react-localization icon indicating copy to clipboard operation
react-localization copied to clipboard

getLanguage() always return 'en'

Open mehranabi opened this issue 7 years ago • 4 comments

Hello, I have two files in this format "filename_locale.js", like:

  • Projects_en.js
  • Projects_fa.js I check language at begining and import right file like this:
alert(strings.getLanguage());
const language = strings.getLanguage();
const Projects = require("../assets/projects/Projects_" + language).default;

BUT strings.getLanguage() always return 'en' !

mehranabi avatar Sep 20 '18 10:09 mehranabi

This is the code that check the browser interface language:

function getInterfaceLanguage() {
  const defaultLang = 'en-US';
  if (typeof navigator === 'undefined') {
    return defaultLang;
  }
  const nav = navigator; // eslint-disable-line no-undef
  if (nav) {
    if (nav.language) {
      return nav.language;
    }
    if (!!nav.languages && !!nav.languages[0]) {
      return nav.languages[0];
    }
    if (nav.userLanguage) {
      return nav.userLanguage;
    }
    if (nav.browserLanguage) {
      return nav.browserLanguage;
    }
  }
  return defaultLang;
}

that's what you should get...

stefalda avatar Sep 27 '18 20:09 stefalda

There's no way using React-Localization for RN. image

wellmonge avatar Apr 07 '23 13:04 wellmonge

Have you tried with ReactNativeLocalization ?

stefalda avatar Apr 07 '23 13:04 stefalda

Yes, it works for me

wellmonge avatar Apr 20 '23 10:04 wellmonge