简体   繁体   中英

Handling default language in jquery-localize

I'm trying to use jquery-localize for localization of my small app. My wish is to use Danish language if the user is Danish, and English otherwise.

I tried doing nothing, but if an unknown language uses the app, then all strings are empty.

My current solution is this

chosenLanguage = window.navigator.userLanguage || window.navigator.language;
langSearch = new RegExp('^da', 'i');
if (chosenLanguage.match(langSearch)){
  // Do nothing
}
else {
  $("[data-localize]").localize("local", { language: "en" });
}

But this solution seems too complex to be correct. Any help or suggestions is appreciated!

The jquery-localize library appears to be rather pritimive string customization tool, without even an idea of a fallback to a generic locale. Your current solution, too, is too simple rather than too complex. It relies on “browser language”, which need not have anything to do with the user's language preferences. Instead, design and implement language switching. The usual way is to make the English version primary and provide some links or buttons for changing to other language(s).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM