【问题标题】:Transloco - how to add scope to Translation API?Transloco - 如何为翻译 API 添加范围?
【发布时间】:2021-07-22 13:21:24
【问题描述】:

使用时如何设置作用域:this.translocoService.translate('object.test');

我的翻译文件位于“MyFolder”之类的文件夹中,因此范围为 MyFolder。

这是我的 *.json 文件的结构:

{
    "demo": "test123",
    
    "object" : {        
        "test" : "My.Test" 
    }
}

这是我喜欢做的事情:

export class AppComponent {

constructor(private translocoService: TranslocoService,@Inject(TRANSLOCO_SCOPE) private scope) {}

    ngOnInit() {

    this.translocoService.translate('object.test'); //How to set the scope here?

    }    
}

【问题讨论】:

    标签: angular internationalization transloco


    【解决方案1】:

    解决方案:

    export class AppComponent {
    
    constructor(private translocoService: TranslocoService,@Inject(TRANSLOCO_SCOPE) private scope) {}
    
        ngOnInit() {
    
        var testLable = this.translocoService.translate(this.scope + '.object.test');
    
        }    
    }
    

    【讨论】:

    猜你喜欢
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    相关资源
    最近更新 更多