-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1463 from jsit/feat/default-to-user-primary-lang
feat: Default language dropdowns to user's interface language
- Loading branch information
Showing
6 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Language } from "lemmy-js-client"; | ||
import { I18NextService } from "../../services/I18NextService"; | ||
|
||
export default function getUserInterfaceLangId( | ||
allLanguages: Language[] | ||
): number { | ||
// Get the string of the browser- or user-defined language, like en-US | ||
const i18nLang = I18NextService.i18n.language; | ||
|
||
// Find the Language object with a code that matches the initial characters of | ||
// this string | ||
const userLang = allLanguages.find(lang => { | ||
return i18nLang.indexOf(lang.code) === 0; | ||
}); | ||
|
||
// Return the ID of that language object, or "0" for Undetermined | ||
return userLang?.id || 0; | ||
} |