mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Convert common files to es2015.
This commit is contained in:
@@ -1,51 +1,63 @@
|
||||
var _;
|
||||
import _ from 'lodash';
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
let i18n = {
|
||||
strings: null,
|
||||
translations: {},
|
||||
t: function(stringName) {
|
||||
var clonedVars, e, locale, string, stringNotFound, vars;
|
||||
vars = arguments[1];
|
||||
if (_.isString(arguments[1])) {
|
||||
vars = null;
|
||||
locale = arguments[1];
|
||||
} else if (arguments[2] != null) {
|
||||
vars = arguments[1];
|
||||
locale = arguments[2];
|
||||
t, // eslint-disable-line no-use-before-define
|
||||
};
|
||||
|
||||
function t (stringName) {
|
||||
let vars = arguments[1];
|
||||
let locale;
|
||||
|
||||
if (_.isString(arguments[1])) {
|
||||
vars = null;
|
||||
locale = arguments[1];
|
||||
} else if (arguments[2]) {
|
||||
locale = arguments[2];
|
||||
}
|
||||
|
||||
let i18nNotSetup = !i18n.strings && !i18n.translations[locale];
|
||||
|
||||
if (!locale || i18nNotSetup) {
|
||||
locale = 'en';
|
||||
}
|
||||
|
||||
let string;
|
||||
|
||||
if (i18n.strings) {
|
||||
string = i18n.strings[stringName];
|
||||
} else {
|
||||
string = i18n.translations[locale] && i18n.translations[locale][stringName];
|
||||
}
|
||||
|
||||
let clonedVars = _.clone(vars) || {};
|
||||
|
||||
clonedVars.locale = locale;
|
||||
|
||||
if (string) {
|
||||
try {
|
||||
return _.template(string, clonedVars);
|
||||
} catch (_error) {
|
||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||
}
|
||||
if ((locale == null) || (!module.exports.strings && !module.exports.translations[locale])) {
|
||||
locale = 'en';
|
||||
} else {
|
||||
let stringNotFound;
|
||||
|
||||
if (i18n.strings) {
|
||||
stringNotFound = i18n.strings.stringNotFound;
|
||||
} else if (i18n.translations[locale]) {
|
||||
stringNotFound = i18n.translations[locale] && i18n.translations[locale].stringNotFound;
|
||||
}
|
||||
if (module.exports.strings) {
|
||||
string = module.exports.strings[stringName];
|
||||
} else {
|
||||
string = module.exports.translations[locale] && module.exports.translations[locale][stringName];
|
||||
}
|
||||
clonedVars = _.clone(vars) || {};
|
||||
clonedVars.locale = locale;
|
||||
if (string) {
|
||||
try {
|
||||
return _.template(string, clonedVars);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||
}
|
||||
} else {
|
||||
if (module.exports.strings) {
|
||||
stringNotFound = module.exports.strings.stringNotFound;
|
||||
} else if (module.exports.translations[locale]) {
|
||||
stringNotFound = module.exports.translations[locale] && module.exports.translations[locale].stringNotFound;
|
||||
}
|
||||
try {
|
||||
return _.template(stringNotFound, {
|
||||
string: stringName
|
||||
});
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||
}
|
||||
|
||||
try {
|
||||
return _.template(stringNotFound, {
|
||||
string: stringName,
|
||||
});
|
||||
} catch (_error) {
|
||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default i18n;
|
||||
|
||||
Reference in New Issue
Block a user