angularinternationalizationtransloco

Transloco - how to add scope to Translation API?


How to set the scope when using : this.translocoService.translate('object.test'); ?

My translation files are located in a folder like "MyFolder", so the scope will be MyFolder.

This is the structure of my *.json files:

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

This is what I like to do:

export class AppComponent {

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

    ngOnInit() {

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

    }    
}

Solution

  • Solution:

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