Closed pschulten closed 11 years ago
Hello,
loading the translation files is done by i18next
. ng-i18next
is only the wrapper to use i18next
with AngularJS
.
I don't know if this works, but you could try something like this:
$i18nextProvider.options = {...}
)$i18next.resStore
Please look at this: https://github.com/archer96/ng-i18next/blob/master/test/unit/i18nextDirectiveSpec.js#L16-L49
I hope that solves your problem :)
Regards, Andre
Thank you. Here's what I'm doing: Tell i18next to not hit the server:
angular.module('jm.i18next').config(function ($i18nextProvider) {
$i18nextProvider.options = {
resStore: {} //defining a resStore prevents i18next to fetch stuff from the server
};
});
and then later use my service:
Translation.load(lang).then(function(transl){
$i18next.options = {resStore: transl, lng:lang};
$rootScope.$broadcast('i18nextLanguageChange');
});
I turned out, that defining an empty resStore was a bad idea.
When I reload the page or directly browse a certain route angular somehow stops and the page content isn't shown.
Workaround one was to remove the call to $digest in the init function of ng_i18next.js
function init(options) {
window.i18n.init(options, function (localize) {
if (!$rootScope.$$phase) {
//wtf? $rootScope.$digest();
}
t = localize;
$rootScope.$broadcast('i18nextLanguageChange');
});
}
which I don't like. Workaround two was trigger the normal i18next life-cycle with:
angular.module('jm.i18next').config(function ($i18nextProvider) {
$i18nextProvider.options = {
resGetPath: 'empty.json' //load translation manually
};
});
I'd like to use a customLoad function. But one can not inject a services or $http in the config phase.