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
Post a Comment