mirror of
https://github.com/ascribe/onion.git
synced 2025-01-18 08:46:10 +01:00
Fix ESLint errors with language utils
This commit is contained in:
parent
5a270442cb
commit
643b45bdee
@ -1,4 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
import { getBrowserLang } from 'js-utility-belt/es6/lang';
|
import { getBrowserLang } from 'js-utility-belt/es6/lang';
|
||||||
|
|
||||||
import languages from '../constants/languages';
|
import languages from '../constants/languages';
|
||||||
@ -9,24 +8,28 @@ import { formatText } from './general';
|
|||||||
/**
|
/**
|
||||||
* Is used to translate strings to another language. Basically can be used with C's string format method.
|
* 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 {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 {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
|
* @return {string} The formated string
|
||||||
*/
|
*/
|
||||||
export function getLangText(s, ...args) {
|
export function getLangText(s, ...args) {
|
||||||
const lang = getBrowserLang();
|
const lang = getBrowserLang();
|
||||||
|
let str = s;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(lang in languages) {
|
// Default to english if the language isn't found
|
||||||
return formatText(languages[lang][s], ...args);
|
const language = languages[lang in languages ? lang : 'en-US'];
|
||||||
} else {
|
|
||||||
// just use the english language
|
// Default to the original string if no match is found
|
||||||
return formatText(languages['en-US'][s], ...args);
|
str = language[s] || s;
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//if(!(s in languages[lang])) {
|
// TODO: turn the warning back on when our localization is on point
|
||||||
//console.warn('Language-string is not in constants file. Add: "' + s + '" to the "' + lang + '" language file. Defaulting to keyname');
|
if (false && process.env.NODE_ENV !== 'production') {
|
||||||
return formatText(s, ...args);
|
// eslint-disable-next-line no-console
|
||||||
//} else {
|
console.warn(`Language-string is not in constants file. Add: "${s}" to the "${lang}"` +
|
||||||
// console.error(err);
|
'language file. Defaulting to keyname');
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return formatText(str, ...args);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user