0

I have a method that returns either german or english. Works perfectly on Google Chrome but on IE it always return english.

What is the issue? How can I support IE with my code?

// Method that returns the locale to be used in the translation e.g. en, de
this.getLocale = function() {
    var locale = window.navigator.language;
    console.log(locale);
    // Only get the first two letters of the locale e.g. en-US -> en, pt-PT -> pt
    locale = locale.substr(0, 2);
    // Return en or de. Defaults as en
    return (locale == "en" || locale == "de") ? locale : "en";
};

My browser is in German, my computer is in German. The I18n labels is in German but window.navigator.language returns en-US. How is this possible?

user11341081
  • 199
  • 7
  • @VLAZ there is no good solution there – user11341081 Jul 02 '19 at 10:41
  • @user11341081 Why not? Can you say what is different in your question so that the answer given by bobince can't be applied? – Teemu Jul 02 '19 at 10:44
  • @user11341081 what do you get with `window.navigator.languages`? I'm currently getting a 5 elements array: `(5) ["en-US", "en", "it-IT", "it", "la"]` (browser in english, operating system in english, location = Italy) – GrafiCode Jul 02 '19 at 11:04
  • Mine are: `window.navigator.language` return `"id"` without substr(). `window.navigator.languages` return `["en", "id"]`. – Itang Sanjana Jul 02 '19 at 11:46

0 Answers0