i working on ionic application. want add multi-language support same using language .json files. googled , found few examples loading files using "angular static file loader plugin", loads language files @ once.
my question is, can load user selected language file avoid time loading other language files. can please let me know how can achieve ?? or loading files @ time better approach ?? or there better implementation can ??
thank you.
my question is, can load user selected language file avoid time loading other language files.
yes.
can please let me know how can achieve ?? or loading files @ time better approach ?? or there better implementation can ??
use angular-translate
, angular-translate-loader-url
in app.config()
$translateprovider.useurlloader('/translate'); $translateprovider.preferredlanguage('en_us');
this equivalent of request /translate?lang=en_us
specific language (default) when app initial.
later when want change language:
// example in 1 of controller $translate.use('fr_fr');
this trigger request /translate?lang=fr_fr
fetch translation file
i have created json files of language "en.json" in project.. , want use file.. possible using above code?
for json files, mentioned in question angular-translate-loader-static-files
trick (i not sure why have file loaded in once, because supposed lazy loading)
$translateprovider.usestaticfilesloader({ prefix: '', suffix: '.json' }); $translateprovider.preferredlanguage('en');
this load en.json
.
to lazy load translation file.
$translate.uses('fr');
this load fr.json
Comments
Post a Comment