From: Dessalines Date: Wed, 1 Dec 2021 20:50:56 +0000 (-0500) Subject: Fix native language issue. (zh_Hant) (#513) X-Git-Url: http://these/git/%7B%60/feeds/front/static/%7BpictrsAvatarThumbnail%28this.state.siteRes.site.icon%29%7D?a=commitdiff_plain;h=a11cbb29c73107fcc7a629e7b0babdf939520675;p=lemmy-ui.git Fix native language issue. (zh_Hant) (#513) --- diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index fd9e656..2678f9c 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -1,5 +1,4 @@ import { Component, linkEvent } from "inferno"; -import ISO6391 from "iso-639-1"; import { BlockCommunity, BlockCommunityResponse, @@ -32,6 +31,7 @@ import { fetchCommunities, fetchUsers, getLanguage, + getNativeLanguageName, isBrowser, languages, personSelectName, @@ -523,11 +523,13 @@ export class Settings extends Component { - {languages.sort().map(lang => ( - - ))} + {languages + .sort((a, b) => a.code.localeCompare(b.code)) + .map(lang => ( + + ))} diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 3fdafb3..f273ab2 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -1,4 +1,5 @@ import emojiShortName from "emoji-short-name"; +import ISO6391 from "iso-639-1"; import { BlockCommunityResponse, BlockPersonResponse, @@ -414,6 +415,18 @@ export function debounce(func: any, wait = 1000, immediate = false) { }; } +export function getNativeLanguageName(code: string): string { + let [isoCode, qualifier] = code.split("_"); + + let native = ISO6391.getNativeName(isoCode) || code; + + if (qualifier) { + return `${native}_${qualifier}`; + } else { + return native; + } +} + // TODO export function getLanguage(override?: string): string { let myUserInfo = UserService.Instance.myUserInfo;