1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-25 18:56:28 +02:00

Fix ESLint errors with language utils

This commit is contained in:
Brett Sun 2016-06-13 15:06:06 +02:00
parent 5a270442cb
commit 643b45bdee

View File

@ -1,4 +1,3 @@
'use strict';
import { getBrowserLang } from 'js-utility-belt/es6/lang';
import languages from '../constants/languages';
@ -8,25 +7,29 @@ import { formatText } from './general';
/**
* Is used to translate strings to another language. Basically can be used with C's string format method.
* @param {string} s The string you want to translate
* @param {array} args An array of arguments (essentially JavaScript's this.arguments) that can be used to substitute digits and other strings
* @param {string} s The string you want to translate
* @param {array} args An array of arguments (essentially JavaScript's this.arguments)
* that can be used to substitute digits and other strings
* @return {string} The formated string
*/
export function getLangText(s, ...args) {
const lang = getBrowserLang();
let str = s;
try {
if(lang in languages) {
return formatText(languages[lang][s], ...args);
} else {
// just use the english language
return formatText(languages['en-US'][s], ...args);
// Default to english if the language isn't found
const language = languages[lang in languages ? lang : 'en-US'];
// Default to the original string if no match is found
str = language[s] || s;
} catch (err) {
// TODO: turn the warning back on when our localization is on point
if (false && process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.warn(`Language-string is not in constants file. Add: "${s}" to the "${lang}"` +
'language file. Defaulting to keyname');
}
} catch(err) {
//if(!(s in languages[lang])) {
//console.warn('Language-string is not in constants file. Add: "' + s + '" to the "' + lang + '" language file. Defaulting to keyname');
return formatText(s, ...args);
//} else {
// console.error(err);
//}
}
return formatText(str, ...args);
}