mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-10 11:05:47 +00:00
816ce3180f
* Update account view routing * Temporarily add unicode character to translated strings for testing * Temporarily select add unicode to all untranslated strings * Format changes * Add all english translations for /account & /generate * Add the rest of the english translations * Add a few more missing translations * Update en translations * Get selectedLanguage from localstorage instead of redux sttate * Update snapshots * Add missing translation keys & Update translate functs & change variable prefix * translate all markdown strings & remove old translation strings * Update snapshot * Add a few more translation strs * Move raw strings being translated into json * All translation keys are now Uppercase * Fix up the last few translations * Update snapshot * Uppercase de translation strings * Bring back shapeshift logo on swap * Fix contracts tab translations * Fix a few more translations * Fix translations * remove debugging stuff * Update snapshots * Use react.fragment as markdown root renderer * Seperate markdown translations into their own function * Clean up translation functions * Clean up translation functions * Update snapshot * Fix some broken translation strings * Add prettier ignore file
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import TranslateMarkdown from 'components/Translate';
|
|
import React from 'react';
|
|
import { State as ConfigState } from 'reducers/config';
|
|
import { loadStatePropertyOrEmptyObject } from 'utils/localStorage';
|
|
const fallbackLanguage = 'en';
|
|
const repository: {
|
|
[language: string]: {
|
|
[translationName: string]: string;
|
|
};
|
|
} = {};
|
|
|
|
interface ILanguage {
|
|
code: string;
|
|
data: {
|
|
[translationName: string]: string;
|
|
};
|
|
}
|
|
|
|
const languages: ILanguage[] = [
|
|
require('./lang/en.json'),
|
|
require('./lang/de.json'),
|
|
require('./lang/el.json'),
|
|
require('./lang/es.json'),
|
|
require('./lang/fi.json'),
|
|
require('./lang/fr.json'),
|
|
require('./lang/ht.json'),
|
|
require('./lang/hu.json'),
|
|
require('./lang/id.json'),
|
|
require('./lang/it.json'),
|
|
require('./lang/ja.json'),
|
|
require('./lang/nl.json'),
|
|
require('./lang/no.json'),
|
|
require('./lang/pl.json'),
|
|
require('./lang/pt.json'),
|
|
require('./lang/ru.json') /*sk, sl, sv */,
|
|
require('./lang/ko.json'),
|
|
require('./lang/tr.json'),
|
|
require('./lang/vi.json'),
|
|
require('./lang/zhcn.json'),
|
|
require('./lang/zhtw.json')
|
|
];
|
|
|
|
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 = translateRaw(x);
|
|
return !!translated;
|
|
});
|
|
}
|
|
|
|
export type TranslatedText = React.ReactElement<any> | string;
|
|
|
|
export function translateRaw(key: string, variables?: { [name: string]: string }): string {
|
|
// redux store isn't initialized in time which throws errors, instead we get the language selection from localstorage
|
|
const lsConfig = loadStatePropertyOrEmptyObject('config');
|
|
const language = !!lsConfig ? (lsConfig as ConfigState).meta.languageSelection : fallbackLanguage;
|
|
const translatedString =
|
|
(repository[language] && repository[language][key]) || repository[fallbackLanguage][key] || key;
|
|
|
|
if (!!variables) {
|
|
// Find each variable and replace it in the translated string
|
|
let str = translatedString;
|
|
Object.keys(variables).forEach(v => {
|
|
str = str.replace(v, variables[v]);
|
|
});
|
|
return str;
|
|
}
|
|
|
|
return translatedString;
|
|
}
|
|
|
|
export function translate(
|
|
key: string,
|
|
variables?: { [name: string]: string }
|
|
): React.ReactElement<any> {
|
|
return <TranslateMarkdown source={translateRaw(key, variables)} />;
|
|
}
|
|
|
|
export default translate;
|