2

Currently I have a site that supports English and German where I have English (en) as the fallback language. I'm using the determinePreferredLanguage() method to automatically translate the site and I'm also using the useStaticFilesLoader so each language corresponds to a json file. Additionally I'm using the registerAvailableLanguageKeys method specifying en and de. I understand the nature of this method is to map all variants of a language key to a unified format (ie. en_UK and en_US to en) but is there a way to tell it to map all "non-registered" languages to say, en?

Here's my issue. If a French user hits my site it tries to use 'fr' (in fact calling $translate.use() returns 'fr'). The site appears in English because there is no fr language file but I still get a 404 when the site tries to request fr.json in my static files directory. I was hoping that the registerAvailableLanguageKeys would tell the client "I can ONLY use these languages." and it would never check for any language that wasn't registered. Obviously that's not how it works. Anyone have a good solution for avoiding this issue? Thanks.

budkin
  • 347
  • 3
  • 11

1 Answers1

2

It looks like you can have wildcards: https://stackoverflow.com/a/30492315/481812 (Credit Drix)

    $translateProvider.useStaticFilesLoader({
       prefix: 'locales/locale-',
       suffix: '.json'
    })   

    .registerAvailableLanguageKeys(['en','pt'], {
       'en_*': 'en',
       'fr_*': 'fr',
       'pt_*': 'pt'
    })

    .determinePreferredLanguage()

    .fallbackLanguage('en');
Community
  • 1
  • 1
Robert Cutajar
  • 3,181
  • 1
  • 30
  • 42