William O'Beirne f5b6a49463 Translation updates (#120)
* Updated all translations, moved into their own folders.

* Switch translations to use Markdown component.

* Remove markup tests, since were using a module now.

* Fix flow errors, render react elements instead of dangerouslysetinnerhtml.

* Make translate a connected component, so it updates with Redux.

* Fix flow errors

* First pass at returning raw when needed for placeholder.

* Added aria test.

* Fixed flow errors and linter warnings.

* Move settimeout to saga.

* Change reload to 250 ms from 1500 ms
2017-08-28 13:05:38 -05:00

72 lines
1.6 KiB
JavaScript

// @flow
import React from 'react';
import type { Element } from 'react';
import Translate from 'components/Translate';
import { store } from 'store';
import { getLanguageSelection } from 'selectors/config';
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')
];
languages.forEach(l => {
repository[l.code] = l.data;
});
export function getTranslators() {
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;
});
}
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
);
}