简体   繁体   English

如果 json 文件之一中缺少密钥,则 ngx-translate 替换为其他 json 文件相同的密钥

[英]ngx-translate if a key is missing in one of the json file replace with other json file same key

I have a scenario, I have two languages files en.json & es.json I have a key in en.json file which is missed in es.json file, however, I want to replace this missing key with the en.json key how would I achieve this. I have a scenario, I have two languages files en.json & es.json I have a key in en.json file which is missed in es.json file, however, I want to replace this missing key with the en.json key我将如何实现这一目标。

I know the way we use MissingTranslationHandler for missing keys, but I do not want to show a default text for missing keys, Although I'm doing this for a missed key from both files, in my scenario its different.我知道我们使用 MissingTranslationHandler 处理丢失键的方式,但我不想显示丢失键的默认文本,尽管我正在为两个文件中的丢失键执行此操作,但在我的场景中它是不同的。

Any help would be greatly appreciated, thanks in advance!任何帮助将不胜感激,在此先感谢!

Inside your app module constructor, you can tell what is the default language which you're interested in在您的应用程序模块构造函数中,您可以知道您感兴趣的默认语言是什么

export class AppModule {

    constructor(translate: TranslateService) {
        translate.setDefaultLang('en');
        translate.use('en');
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析json文件Angular 5 ngx-translate期间Http失败 - Http failure during parsing for json file Angular 5 ngx-translate Ngx-translate:如何使用键引用直接在 Angular 中访问 JSON 数组值 - Ngx-translate: How to access JSON array value directly in Angular with key reference 使用 angular ngx-translate 翻译 json 数组 - Translate json arrays with angular ngx-translate 在一个JSON文件中查找键的值,并将其替换为第二个JSON中的键的值,其中第一个JSON中的值与第二个JSON中的键匹配 - Find value of key in one JSON file and replace it with value of key from second JSON where value in first JSON matches key in second JSON 找不到 json 语言文件 ngx-translate angular-cli - json language files are not found ngx-translate angular-cli SwiftUI 更新/替换密钥,JSON 文件中的值 - SwiftUI update/replace key, value in a JSON file 如何替换 JSON 文件中的密钥? - How do I replace the key in a JSON file? 在 JSON 文件中的任意位置找到一个键值,并将键替换为变量 - Find a key-value anywhere in JSON file and replace key with a variable 每次我为新文件执行 JSON.stringify 时替换 JSON 文件(刷新每个键和值) - replace JSON file everytime I do JSON.stringify for a new one (refreshing every key and value) 如何替换json文件中的键名而不使其成为json数组 - How to replace key names in a json file without making it a json array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM