]> Untitled Git - lemmy-ui.git/commitdiff
Fix native language issue. (zh_Hant) (#513)
authorDessalines <dessalines@users.noreply.github.com>
Wed, 1 Dec 2021 20:50:56 +0000 (15:50 -0500)
committerGitHub <noreply@github.com>
Wed, 1 Dec 2021 20:50:56 +0000 (15:50 -0500)
src/shared/components/person/settings.tsx
src/shared/utils.ts

index fd9e6560e4d390ddf13d10d2089483712dcae25d..2678f9c827e9254adba69ade93a67c3a49bb5629 100644 (file)
@@ -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<any, SettingsState> {
                 <option disabled aria-hidden="true">
                   ──
                 </option>
-                {languages.sort().map(lang => (
-                  <option value={lang.code}>
-                    {ISO6391.getNativeName(lang.code) || lang.code}
-                  </option>
-                ))}
+                {languages
+                  .sort((a, b) => a.code.localeCompare(b.code))
+                  .map(lang => (
+                    <option value={lang.code}>
+                      {getNativeLanguageName(lang.code)}
+                    </option>
+                  ))}
               </select>
             </div>
           </div>
index 3fdafb39933df4cf4b6f5868fa8730de00636408..f273ab2859fbc5578972f00260f460954809ab6d 100644 (file)
@@ -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;