mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Move i18n to javascript
This commit is contained in:
@@ -2,8 +2,7 @@ import {each, defaults, assign} from 'lodash';
|
||||
import capitalize from 'lodash.capitalize';
|
||||
import camelCase from 'lodash.camelcase';
|
||||
|
||||
require('coffee-script');
|
||||
import i18n from '../../../script/i18n.coffee';
|
||||
import i18n from '../i18n';
|
||||
|
||||
//----------------------------------------
|
||||
// Translator Helpers
|
||||
|
||||
49
common/script/src/i18n.js
Normal file
49
common/script/src/i18n.js
Normal file
@@ -0,0 +1,49 @@
|
||||
let _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
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];
|
||||
}
|
||||
if ((locale == null) || (!module.exports.strings && !module.exports.translations[locale])) {
|
||||
locale = 'en';
|
||||
}
|
||||
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.';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user