angularjs - angular-translate. What is the best way to implement i18n using json files that are stored on the server, not the client -


implementing i18n isn't difficult when have list of json documents stored on client. if can't have json files stored locally? have retrieved @ runtime. best way achieve this.

i thought storing them in sessionstorage required how angular-translate work or similar?

when work local files point location:

urltemplate: 'assets/translation/{lang}/{part}.json' 

i don't know if best way, have been using static files loader angular-translate this.

let's have folder full of translation files:

locales/locale-de_de.json  locales/locale-en_gb.json  locales/locale-nl_be.json  ... 

then in app, this:

var app = angular.module('myapp', [ ]);  app.config([ '$translateprovider',   function($translateprovider) {     $translateprovider.usestaticfilesloader({       prefix: 'locales/',       suffix: '.json'     });   } ]);  app.run([ '$translate',   function($translate) {     // set default language german     $translate.use('locale-de_de');   } ]); 

whenever want switch language later on in code, need call $translate-service language want switch to, e.g.

[...] $translate.use('locale-en_gb'); // switch british english [...] 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -