1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Use js-utility-belt's language utils

This commit is contained in:
Brett Sun 2016-06-13 15:05:53 +02:00
parent 63310c5717
commit 5a270442cb

View File

@ -1,17 +1,11 @@
'use strict'; 'use strict';
import { getBrowserLang } from 'js-utility-belt/es6/lang';
import languages from '../constants/languages'; import languages from '../constants/languages';
import { formatText } from './general'; import { formatText } from './general';
export function getLang() {
// this is just for testing, as changing the navigator.language wasn't possible
// return 'fr';
return navigator.languages ? navigator.languages[0] :
(navigator.language || navigator.userLanguage);
}
/** /**
* 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
@ -19,7 +13,7 @@ export function getLang() {
* @return {string} The formated string * @return {string} The formated string
*/ */
export function getLangText(s, ...args) { export function getLangText(s, ...args) {
let lang = getLang(); const lang = getBrowserLang();
try { try {
if(lang in languages) { if(lang in languages) {
return formatText(languages[lang][s], ...args); return formatText(languages[lang][s], ...args);