2017-05-25 00:06:30 +00:00
|
|
|
// @flow
|
2017-08-28 18:05:38 +00:00
|
|
|
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 = [
|
2017-08-28 18:05:38 +00:00
|
|
|
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
|
|
|
}
|
2017-08-28 18:05:38 +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
|
|
|
|
);
|
|
|
|
}
|