Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using $translateProvider.useUrlLoader

I am using latest version of angularjs and angular-translate.

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 which calls a REST API which in turn returns json data for translation. REST API will pull the translations store in database.

like image 797
NoobDeveloper Avatar asked Feb 02 '15 15:02

NoobDeveloper


1 Answers

Tale a look at:

http://angular-translate.github.io/docs/#/api/pascalprecht.translate.$translateUrlLoader

By default it will use the querystring param ?lang= to pass in the desired language.

you would use it like:

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

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

If you do not want a query string parameter, but would 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

like image 172
Martin Avatar answered Oct 01 '22 23:10

Martin