Add option to also output original string
This is useful for debugging and testing Signed-off-by: Stefan Parviainen <pafcu@iki.fi>
This commit is contained in:
parent
7118f7a38f
commit
713230e082
1 changed files with 19 additions and 1 deletions
|
@ -23,6 +23,10 @@ import SettingsStore, {SettingLevel} from "./settings/SettingsStore";
|
||||||
|
|
||||||
const i18nFolder = 'i18n/';
|
const i18nFolder = 'i18n/';
|
||||||
|
|
||||||
|
// Control whether to also return original, untranslated strings
|
||||||
|
// Useful for debugging and testing
|
||||||
|
const ANNOTATE_STRINGS = false;
|
||||||
|
|
||||||
// We use english strings as keys, some of which contain full stops
|
// We use english strings as keys, some of which contain full stops
|
||||||
counterpart.setSeparator('|');
|
counterpart.setSeparator('|');
|
||||||
// Fall back to English
|
// Fall back to English
|
||||||
|
@ -84,7 +88,21 @@ export function _t(text, variables, tags) {
|
||||||
// The translation returns text so there's no XSS vector here (no unsafe HTML, no code execution)
|
// The translation returns text so there's no XSS vector here (no unsafe HTML, no code execution)
|
||||||
const translated = safeCounterpartTranslate(text, args);
|
const translated = safeCounterpartTranslate(text, args);
|
||||||
|
|
||||||
return substitute(translated, variables, tags);
|
let substituted = substitute(translated, variables, tags);
|
||||||
|
|
||||||
|
// For development/testing purposes it is useful to also output the original string
|
||||||
|
// Don't do that for release versions
|
||||||
|
if (ANNOTATE_STRINGS) {
|
||||||
|
if (typeof substituted === 'string') {
|
||||||
|
return `@@${text}##${substituted}@@`
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return <span className='translated-string' data-orig-string={text}>{substituted}</span>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return substituted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue