From a11cbb29c73107fcc7a629e7b0babdf939520675 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 1 Dec 2021 15:50:56 -0500 Subject: [PATCH] Fix native language issue. (zh_Hant) (#513) --- src/shared/components/person/settings.tsx | 14 ++++++++------ src/shared/utils.ts | 13 +++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) 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; -- 2.44.1