Reputation: 81
When using angular-translate to localize my Angular app, the fallback language is not attempted if the preferred language (via static file loader) failed to load or doesn't exist for any reason.
$translateProvider.useStaticFilesLoader({
prefix: 'locale-',
suffix: '.json'
});
$translateProvider
.preferredLanguage('ja')
.fallbackLanguage('en');
The plnkr is available: http://plnkr.co/edit/tHrBeY0Ur0rhp0xNuWpA?p=preview
If there is an empty locale-ja.json file, then the fallback is loaded correctly. This as pointed out might be a library bug. Has anyone found a workaround?
Upvotes: 5
Views: 2973
Reputation: 498
Currently stumbled upon the same problem, and the only way I can solve it is by adding $translateProvider.use()
option. so it would look like this:
$translateProvider
.preferredLanguage('ja')
.use('ja')
.fallbackLanguage('en');
Upvotes: 0
Reputation: 164
FallbackLanguge function have another purpose - if a translation-table doesn't have a specific key, the translation from the fallback language will be used. If you want to specify default language, you can use wildcard in registerAvailableLanguageKeys function:
.registerAvailableLanguageKeys(['en, da'], {
'en_US': 'en',
'en_UK': 'en',
'da_DK': 'da',
'*': 'en'
})
In this example 'en' is the default language. It will load if the preferred language doesn't exist.
Upvotes: 4