Bug solved: Modules are not loaded when language is not recognized
This commit is contained in:
parent
b45ab59076
commit
8852bfd4bb
|
@ -5,17 +5,29 @@ export function config($translateProvider, $translatePartialLoaderProvider) {
|
|||
$translatePartialLoaderProvider.addPart('core');
|
||||
|
||||
let conf = {urlTemplate: '/static/locale/{part}/{lang}.json'};
|
||||
|
||||
let fallbackLang = 'es';
|
||||
let langs = ['en', 'es'];
|
||||
let localLangs = {
|
||||
let langAliases = {
|
||||
en_US: 'en',
|
||||
en_UK: 'en',
|
||||
es_ES: 'es',
|
||||
es_AR: 'es'
|
||||
};
|
||||
|
||||
$translateProvider
|
||||
.useSanitizeValueStrategy('escape')
|
||||
.useLoader('$translatePartialLoader', conf)
|
||||
.registerAvailableLanguageKeys(langs, localLangs)
|
||||
.determinePreferredLanguage();
|
||||
.registerAvailableLanguageKeys(langs, langAliases)
|
||||
// FIXME: Circular dependency due to vnInterceptor
|
||||
// .fallbackLanguage(fallbackLang)
|
||||
.determinePreferredLanguage(() => {
|
||||
let locale = $translateProvider.resolveClientLocale();
|
||||
if (langs.indexOf(locale) !== -1)
|
||||
return locale;
|
||||
if (langAliases[locale])
|
||||
return langAliases[locale];
|
||||
return fallbackLang;
|
||||
});
|
||||
}
|
||||
module.config(config);
|
||||
|
|
|
@ -10,10 +10,15 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t
|
|||
load(moduleName, validations) {
|
||||
let loaded = this._loaded;
|
||||
|
||||
if (loaded[moduleName])
|
||||
if (loaded[moduleName] === true)
|
||||
return Promise.resolve(true);
|
||||
if (loaded[moduleName] instanceof Promise)
|
||||
return loaded[moduleName];
|
||||
if (loaded[moduleName] === false)
|
||||
return Promise.reject(
|
||||
new Error(`Module dependency loop detected: ${moduleName}`));
|
||||
|
||||
loaded[moduleName] = Promise.resolve(true);
|
||||
loaded[moduleName] = false;
|
||||
|
||||
let deps = splitingRegister.getDependencies(moduleName);
|
||||
let depPromises = [];
|
||||
|
@ -29,13 +34,18 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t
|
|||
|
||||
// FIXME: https://github.com/angular-translate/angular-translate/pull/1674
|
||||
$translatePartialLoader.addPart(moduleName);
|
||||
promises.push($translate.refresh());
|
||||
promises.push(new Promise(resolve => {
|
||||
$translate.refresh().then(
|
||||
() => resolve(),
|
||||
() => resolve()
|
||||
);
|
||||
}));
|
||||
|
||||
if (validations)
|
||||
promises.push(new Promise(resolve => {
|
||||
$http.get(`/${moduleName}/validations`).then(
|
||||
json => this.onValidationsReady(json, resolve),
|
||||
json => resolve()
|
||||
() => resolve()
|
||||
);
|
||||
}));
|
||||
|
||||
|
@ -45,7 +55,7 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t
|
|||
|
||||
Promise.all(promises)
|
||||
.then(() => {
|
||||
this._loaded[moduleName] = true;
|
||||
loaded[moduleName] = true;
|
||||
resolve($ocLazyLoad.load({name: moduleName}));
|
||||
})
|
||||
.catch(reject);
|
||||
|
|
Loading…
Reference in New Issue