12 changed files with 160 additions and 79 deletions
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
import { Dropdown } from "@/components/Dropdown"; |
||||
import { FlagIcon } from "@/components/FlagIcon"; |
||||
import { Heading1 } from "@/components/utils/Text"; |
||||
import { appLanguageOptions } from "@/setup/i18n"; |
||||
import { useLanguageStore } from "@/stores/language"; |
||||
import { sortLangCodes } from "@/utils/sortLangCodes"; |
||||
|
||||
export function LocalePart() { |
||||
const sorted = sortLangCodes(appLanguageOptions.map((t) => t.id)); |
||||
const { language, setLanguage } = useLanguageStore(); |
||||
|
||||
const options = appLanguageOptions |
||||
.sort((a, b) => sorted.indexOf(a.id) - sorted.indexOf(b.id)) |
||||
.map((opt) => ({ |
||||
id: opt.id, |
||||
name: `${opt.englishName} — ${opt.nativeName}`, |
||||
leftIcon: <FlagIcon countryCode={opt.id} />, |
||||
})); |
||||
|
||||
const selected = options.find((t) => t.id === language); |
||||
|
||||
return ( |
||||
<div> |
||||
<Heading1 border>Locale</Heading1> |
||||
<p className="text-white font-bold mb-3">Application language</p> |
||||
<p className="max-w-[20rem] font-medium"> |
||||
Language applied to the entire application. |
||||
</p> |
||||
<Dropdown |
||||
options={options} |
||||
selectedItem={selected || options[0]} |
||||
setSelectedItem={(opt) => setLanguage(opt.id)} |
||||
/> |
||||
</div> |
||||
); |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
export function sortLangCodes(langCodes: string[]) { |
||||
const languagesOrder = ["en", "hi", "fr", "de", "nl", "pt"].reverse(); // Reverse is neccesary, not sure why
|
||||
|
||||
const results = langCodes.sort((a, b) => { |
||||
if (languagesOrder.indexOf(b) !== -1 || languagesOrder.indexOf(a) !== -1) |
||||
return languagesOrder.indexOf(b) - languagesOrder.indexOf(a); |
||||
|
||||
return a.localeCompare(b); |
||||
}); |
||||
|
||||
return results; |
||||
} |
Loading…
Reference in new issue