Amend to have multiple sections

Changed to allow multiple sections  within the json language files.
This commit is contained in:
Steven Marks
2020-06-10 21:17:29 +01:00
committed by GitHub
parent 7f44c5cc9a
commit fc78f3013c
+3 -5
View File
@@ -7,20 +7,18 @@ var languages = {
}; };
export function localize(string: string, search: string = '', replace: string = '') { export function localize(string: string, search: string = '', replace: string = '') {
const section = string.split('.')[0];
const key = string.split('.')[1];
const lang = (localStorage.getItem('selectedLanguage') || 'en').replace(/['"]+/g, '').replace('-', '_'); const lang = (localStorage.getItem('selectedLanguage') || 'en').replace(/['"]+/g, '').replace('-', '_');
var tranlated: string; var tranlated: string;
try { try {
tranlated = languages[lang][section][key]; tranlated = string.split('.').reduce((o, i) => o[i], languages[lang]);
} catch (e) { } catch (e) {
tranlated = languages['en'][section][key]; tranlated = string.split('.').reduce((o, i) => o[i], languages['en']);
} }
if (tranlated === undefined) tranlated = languages['en'][section][key]; if (tranlated === undefined) tranlated = string.split('.').reduce((o, i) => o[i], languages['en']);
if (search !== '' && replace !== '') { if (search !== '' && replace !== '') {
tranlated = tranlated.replace(search, replace); tranlated = tranlated.replace(search, replace);