Using $ translateProvider.useUrlLoader

I am using the latest version of angularjs and angular translators.

For some reason, I don't want to store my translations in static .json files (en_US.json or ru_RU.json)

Is there any API in angular-translate that calls the REST API, which in turn returns json data for translation. The REST API will pull out the translation store in the database.

+6
source share
1 answer

Look at:

http://angular-translate.imtqy.com/docs/#/api/pascalprecht.translate . $ translateUrlLoader

By default, it will use the querystring ?lang= parameter to switch to the desired language.

you would use it like:

 $translateProvider.useUrlLoader("/path/to/my/endpoint"); $translationProvider.defaultLanguage("en"); 

Angular -translate will call /path/to/my/endpoint?lang=en

If you do not need a query string parameter, but rather a path parameter, you can create your own loader based on $ translateUrlLoader. Looking at the source, it looks very trivial:

https://github.com/angular-translate/angular-translate/blob/master/src/service/loader-url.js

+7
source

Source: https://habr.com/ru/post/981878/


All Articles