javascript - PascalPrecht angular-translate useUrlLoader -


i'm new both programming , angular. need use angular-translate its' useurlloader, since translations stored in database. $translateprovider.useurlloader('foo/bar.json'); $translateprovider.preferredlanguage('en');

while using staticfilesloader seems enough simple me, since need 2 separate json files translation data, can't useurlloader expects. far understand, expects json includes multiply language translations (both english , german example). can't find example of such file anywhere.

the staticfilesloader expects store translations different languages in separate files on server. makes requests this:

/your/server/i18n/locale-en.json /your/server/i18n/locale-de.json /your/server/i18n/locale-fr.json 

where /your/server/i18n/locale- , .json prefix , suffix (respectively) you've passed during configuration.

the urlloader expects have 1 "clever" endpoint instead of bunch of files. makes requests this:

/your/server/i18n/locale-endpoint?lang=en /your/server/i18n/locale-endpoint?lang=de /your/server/i18n/locale-endpoint?lang=fr 

where /your/server/i18n/locale-endpoint , lang url , queryparameter (respectively) you've passed during configuration. url required, queryparameter may omitted (defaults "lang").

you can setup urlloader either this:

$translateprovider.useurlloader('/path/to/your/endpoint', {   queryparameter : 'localekey' }); 

or this:

$translateprovider.useloader('$translateurlloader', {   url : '/path/to/your/endpoint',   queryparameter : 'localekey' }); 

both loaders expect load translation json object. this:

{   "translationid" : "translation id",   "anothertranslationid": "another translation id" } 

you can find more information different loaders in the official guide.

a source code of urlloader can found in the angular-translate repository.

hope, helps.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -