forked from FoundKeyGang/FoundKey
Update i18n.ts
This commit is contained in:
parent
1a474d13d6
commit
41f7e38547
1 changed files with 4 additions and 1 deletions
|
@ -13,6 +13,8 @@ export default (lang, locale) => ({
|
||||||
{
|
{
|
||||||
pattern: /%i18n:(.+?)%/g, replacement: (_, key) => {
|
pattern: /%i18n:(.+?)%/g, replacement: (_, key) => {
|
||||||
let text = locale;
|
let text = locale;
|
||||||
|
|
||||||
|
// Check the key existance
|
||||||
const error = key.split('.').some(k => {
|
const error = key.split('.').some(k => {
|
||||||
if (text.hasOwnProperty(k)) {
|
if (text.hasOwnProperty(k)) {
|
||||||
text = text[k];
|
text = text[k];
|
||||||
|
@ -21,9 +23,10 @@ export default (lang, locale) => ({
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.warn(`key '${key}' not found in '${lang}'`);
|
console.warn(`key '${key}' not found in '${lang}'`);
|
||||||
return key;
|
return key; // Fallback
|
||||||
} else {
|
} else {
|
||||||
return text.replace(/'/g, '\\\'').replace(/"/g, '\\"');
|
return text.replace(/'/g, '\\\'').replace(/"/g, '\\"');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue