mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -05:00
Display the system language first. Fixes #4
This commit is contained in:
parent
cae3b68c7f
commit
735e9b7f5e
1 changed files with 18 additions and 0 deletions
|
@ -53,6 +53,24 @@ export function Component(props: Props) {
|
|||
Langs[x as keyof typeof Langs],
|
||||
]) as Key[];
|
||||
|
||||
// Get the user's system language
|
||||
const preferredLanguage =
|
||||
navigator.languages
|
||||
?.filter((lang) =>
|
||||
languages.find((l) => l[0] == lang.split("-")[0]),
|
||||
)?.[0]
|
||||
?.split("-")[0] ?? "en";
|
||||
|
||||
// This moves the user's system language to the top of the language list
|
||||
const prefLangKey = languages.find((lang) => lang[0] == preferredLanguage);
|
||||
if (prefLangKey) {
|
||||
languages.splice(
|
||||
0,
|
||||
0,
|
||||
languages.splice(languages.indexOf(prefLangKey), 1)[0],
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.languages}>
|
||||
<h3>
|
||||
|
|
Loading…
Reference in a new issue