question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use fallbackLanguage when using determinePreferredLanguage

See original GitHub issue

When I use determinePreferredLanguage I would like to use fallbackLanguage or any other special defined fallback when determine methods retruns locale code which is not in my available langague keys.

@PascalPrecht is there any way to achive that?

For now I defined smth like this:

$translateProvider.useStaticFilesLoader({
    prefix: 'resources/translations/',
    suffix: '.json'
});
$translateProvider.useLocalStorage();
$translateProvider.useMissingTranslationHandlerLog();
$translateProvider.registerAvailableLanguageKeys(
    ['pl', 'en'],
    {
        'en*': 'en',
        'pl*': 'pl',
        '*': 'en' // must be last!
    }
);
$translateProvider.fallbackLanguage('en');
$translateProvider.determinePreferredLanguage();

and it works well, but it will be better to define it 😃

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:5
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tandibarcommented, Feb 18, 2016

Ok, but if i call determinePreferedLanguage() it will internally set the language to the determined language, or am I wrong? It will at least set what is returned by $translateProvider.preferredLanguage().

I had a problem with this code:

$translateProvider
  // see: http://angular-translate.github.io/docs/#/guide/09_language-negotiation
  .registerAvailableLanguageKeys(['en', 'de'], {
    'en_US': 'en',
    'en_UK': 'en',
    'de_DE': 'de',
    'de_CH': 'de'
    })
  .determinePreferredLanguage();

  // interpolation for pluralization
  $translateProvider.addInterpolation('$translateMessageFormatInterpolation');

In a polish Browser the last line will fail with Plural Function not found for locale: pl_PL which leads me to the assumption that determinePreferredLanguage() is setting something internally. If I change the code to (as suggested by @mrzepinski):

$translateProvider
// see: http://angular-translate.github.io/docs/#/guide/09_language-negotiation
.registerAvailableLanguageKeys(['en', 'de'], {
  'en_US': 'en',
  'en_UK': 'en',
  'de_DE': 'de',
  'de_CH': 'de',
  '*': 'en'
  })
.fallbackLanguage('en')
.determinePreferredLanguage();

// interpolation for pluralization
$translateProvider.addInterpolation('$translateMessageFormatInterpolation');

everything works fine. So in this case determinePreferredLanguage() will not return or set pl.

0reactions
knallicommented, Feb 18, 2016

A preferred language is the requested language one, but not an actual available or selected one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular-translate - Fallback language for ...
How can I register a fallback language if the determinePreferredLanguage() returns a language key my code doesn't know? I want to fall back...
Read more >
5b. How to add a language - Traceur Fabmob
By default, the fallback language is english but it can easily be modified by just changing en in the line below by the...
Read more >
Angularjs – angular-translate – Fallback language for ...
I use angular-translate in my app. How can I register a fallback language if the determinePreferredLanguage() returns a language key my code doesn't...
Read more >
Use Localization in AngularJS Using Internationalization
This article shows how to implement Localization using AngularJS.
Read more >
Introduction of translation in your project - Angular Translate
PS: This post is for Angular1 and using Angular Translate for translation ... determinePreferredLanguage() //load fallback language .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found