MyCrypto/common/translations/index.js

72 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-05-25 00:06:30 +00:00
// @flow
import React from 'react';
import type { Element } from 'react';
import Translate from 'components/Translate';
import { store } from 'store';
import { getLanguageSelection } from 'selectors/config';
2017-05-25 00:06:30 +00:00
let fallbackLanguage = 'en';
let repository = {};
const languages = [
require('./lang/de'),
require('./lang/el'),
require('./lang/en'),
require('./lang/es'),
require('./lang/fi'),
require('./lang/fr'),
require('./lang/ht'),
require('./lang/hu'),
require('./lang/id'),
require('./lang/it'),
require('./lang/ja'),
require('./lang/nl'),
require('./lang/no'),
require('./lang/pl'),
require('./lang/pt'),
require('./lang/ru') /*sk, sl, sv */,
require('./lang/ko'),
require('./lang/tr'),
require('./lang/vi'),
require('./lang/zhcn'),
require('./lang/zhtw')
2017-05-25 00:06:30 +00:00
];
languages.forEach(l => {
2017-07-04 03:21:19 +00:00
repository[l.code] = l.data;
2017-05-25 00:06:30 +00:00
});
2017-06-01 20:45:00 +00:00
export function getTranslators() {
2017-07-04 03:21:19 +00:00
return [
'TranslatorName_1',
'TranslatorName_2',
'TranslatorName_3',
'TranslatorName_4',
'TranslatorName_5'
].filter(x => {
const translated = translate(x);
if (typeof translated === 'string') {
return !!translated.trim();
}
return !!translated;
});
2017-06-01 20:45:00 +00:00
}
type TranslateType = Element<*> | string;
export default function translate(
key: string,
textOnly: boolean = false
): TranslateType {
return textOnly ? translateRaw(key) : <Translate translationKey={key} />;
}
export function translateRaw(key: string) {
const lang = getLanguageSelection(store.getState());
return (
(repository[lang] && repository[lang][key]) ||
repository[fallbackLanguage][key] ||
key
);
}