Home:ALL Converter>NativeScript with Angular - ngx-translate how to add translations after the application has initialized

NativeScript with Angular - ngx-translate how to add translations after the application has initialized

Ask Time:2020-05-23T00:10:30         Author:user1261710

Json Formatter

I'm writing an application with NativeScript 6.4.1 and Angular 8.

I want to use the ngx-translate library in my project: https://github.com/ngx-translate/core

Here is my sample repository: https://github.com/aubrey-fowler/translationsTest1

It's working fine but I need to be able to add translations after the app has initialized. It's because it's how the backend developers have implemented the feature. When the user logs in to the app they get some more translations from their profile. I know it's strange but it's how they want it to work.

**Problem: my sample code is working but how can I use the ngx-translate library to add new languages and their associated son? **

e.g. this.translate.add('fr', { "greeting": "bonjour"});

Is it possible to add a language json at runtime and if so how can I do that?

Code snippet:

export class AppComponent {

    constructor(public translate: TranslateService) {

        translate.addLangs(['en', 'nl']);
        translate.setDefaultLang('en');
        translate.use('en');

    }

}

Author:user1261710,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/61959268/nativescript-with-angular-ngx-translate-how-to-add-translations-after-the-appl
yy