Use correct locale, fall back to en if we don't have translations

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-05-15 14:48:19 -07:00
parent 18b8907c96
commit 4402a91976
No known key found for this signature in database
GPG key ID: A4931C09644C654B
5 changed files with 69 additions and 9 deletions

View file

@ -3,12 +3,16 @@
*/
;(function() {
'use strict';
var json = window.config.locale_json;
// preload.js loads this, pulling it from main.js (where it was loaded from disk)
var messages = window.config.localeMessages;
var locale = window.config.locale;
window.i18n = function (message, substitutions) {
if (!json[message]) {
if (!messages[message]) {
return;
}
var s = json[message].message;
var s = messages[message].message;
if (substitutions instanceof Array) {
substitutions.forEach(function(sub) {
s = s.replace(/\$.+?\$/, sub);
@ -20,6 +24,6 @@
};
i18n.getLocale = function() {
return window.config.locale;
return locale;
};
})();