Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,712 changes: 1,374 additions & 338 deletions MMM-MyScoreboard.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions localeHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs')
const path = require('path')
const environment = process.env;
const userLocale = environment.LC_ALL || environment.LC_MESSAGES || environment.LANG || environment.LANGUAGE || environment.LC_NAME

module.exports = {
getMomentLocale: function() {
return userLocale.split('.')[0].replace('_', '-').toLowerCase();
},
loadTranslations: function(language) {
const path = './modules/MMM-MyScoreboard/translations/' + language + '.json'
if (fs.existsSync(path)) {
return require('./translations/' + language + '.json');
} else {
return require('./translations/en.json');
}
}
}
24 changes: 24 additions & 0 deletions localeMoment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const momentTz = require('moment-timezone');
const moment = require("moment/min/moment-with-locales");
const localeHelper = require("./localeHelper");

const chooseMomentLocale = (locale) => {
// make the locale lower case
// will fix crashes caused by "en-GB" (instead of "en-gb") not being found
locale = locale.toLowerCase();
if (moment.locales().includes(locale)) { // check if the locale is included in the array returned by `locales()` which (in this case) tells us which locales moment will support
return locale;
} else if (moment.locales().includes(locale.substring(0, 2))) {
// check if the first two letters of the locale are included in the array returned by `locales()` which (in this case) tells us which locales moment will support
// will fixes crashes caused by "en-US" not being found, as we'll tell moment to load "en" instead
return locale.substring(0, 2);
}
// use "en-gb" (the default language and locale for my app) as a fallback if we can't find any other locale
return 'en-gb';
};

const momentLocale = localeHelper.getMomentLocale()
const localeToImport = chooseMomentLocale(momentLocale)
momentTz.locale(localeToImport)

module.exports = momentTz
34 changes: 17 additions & 17 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
const NodeHelper = require("node_helper");

module.exports = NodeHelper.create({

providers: {},

start: function() {
start: function () {
console.log("Starting node_helper for module [" + this.name + "]");

this.providers.SNET = require("./providers/SNET.js");
this.providers.ESPN = require("./providers/ESPN.js");
},

socketNotificationReceived: function(notification, payload) {

socketNotificationReceived: function (notification, payload) {
if (notification == "MMM-MYSCOREBOARD-GET-SCORES") {

/*
payload contains:
provider to get data from
Expand All @@ -28,16 +25,19 @@ module.exports = NodeHelper.create({
var self = this;
var provider = this.providers[payload.provider];

provider.getScores(payload.league, payload.teams, payload.gameDate, function(scores) {
self.sendSocketNotification("MMM-MYSCOREBOARD-SCORE-UPDATE", {instanceId: payload.instanceId, index: payload.index, scores: scores});
});


provider.getScores(
payload.league,
payload.teams,
payload.gameDate,
payload.language,
function (scores) {
self.sendSocketNotification("MMM-MYSCOREBOARD-SCORE-UPDATE", {
instanceId: payload.instanceId,
index: payload.index,
scores: scores
});
}
);
}

},




});
}
});
128 changes: 64 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading