Skip to content

Commit

Permalink
Fix fallback language selection logic in Si18n class
Browse files Browse the repository at this point in the history
Before, when the `lang` option wasn't provided, and there was no URL parameter, and the user hadn't yet selected (saved) a language, everything crashed.
  • Loading branch information
jdbruxelles committed Jan 11, 2024
1 parent 30c8240 commit 1a21467
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/si18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ export default class Si18n {
} else if (_options.lang) {
this.#options.lang = _options.lang;
} else {
// Use the default language of the navigator.
this.#options.lang = navigator.language.substring(0, 2);
// Use the default language of the navigator, if it's available.
const browserLang = navigator.language.substring(0, 2);
this.#options.lang = this.#options.availableLocales.includes(browserLang) ?
browserLang : this.#options.fallbackLang;
}

if (!Si18n.#isUndefined(_options.reloadPage)) {
Expand Down

0 comments on commit 1a21467

Please sign in to comment.