Merged in feat/LOY-155-localize-language-options-in-edit-profile-form (pull request #1490)
feat(LOY-155): Localize language options in edit profile form * feat(LOY-155): Localize language options in edit profile form * feat(LOY-155): Capitalize first letter of localized language options Approved-by: Christian Andolf
This commit is contained in:
@@ -85,3 +85,24 @@ export const languageSelect = [
|
||||
{ label: "Norwegian", value: ApiLang.No },
|
||||
{ label: "Swedish", value: ApiLang.Sv },
|
||||
]
|
||||
|
||||
/**
|
||||
* Get localized language options based on the current lang.
|
||||
*/
|
||||
export function getLocalizedLanguageOptions(currentLang: Lang) {
|
||||
const displayNames = new Intl.DisplayNames([currentLang], {
|
||||
type: "language",
|
||||
})
|
||||
|
||||
return languageSelect.map((option) => {
|
||||
const localizedName = displayNames.of(option.value)
|
||||
const capitalizedName = localizedName
|
||||
? localizedName.charAt(0).toUpperCase() + localizedName.slice(1)
|
||||
: option.label
|
||||
|
||||
return {
|
||||
value: option.value,
|
||||
label: capitalizedName,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user