diff --git a/ui/component/channelEdit/view.jsx b/ui/component/channelEdit/view.jsx
index c6cd117d4..ccd452142 100644
--- a/ui/component/channelEdit/view.jsx
+++ b/ui/component/channelEdit/view.jsx
@@ -21,6 +21,7 @@ import LbcSymbol from 'component/common/lbc-symbol';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import WalletSpendableBalanceHelp from 'component/walletSpendableBalanceHelp';
import { SIMPLE_SITE } from 'config';
+import { sortLanguageMap } from 'util/default-languages';
const LANG_NONE = 'none';
@@ -416,9 +417,9 @@ function ChannelForm(props: Props) {
- {Object.keys(SUPPORTED_LANGUAGES).map((language) => (
-
))}
@@ -434,13 +435,11 @@ function ChannelForm(props: Props) {
- {Object.keys(SUPPORTED_LANGUAGES)
- .filter((lang) => lang !== languageParam[0])
- .map((language) => (
-
- ))}
+ {sortLanguageMap(SUPPORTED_LANGUAGES).map(([langKey, langName]) => (
+
+ ))}
>
}
diff --git a/ui/component/publishAdditionalOptions/view.jsx b/ui/component/publishAdditionalOptions/view.jsx
index 8e05b04cc..a2db2f50f 100644
--- a/ui/component/publishAdditionalOptions/view.jsx
+++ b/ui/component/publishAdditionalOptions/view.jsx
@@ -8,6 +8,7 @@ import PublishReleaseDate from 'component/publishReleaseDate';
import LicenseType from './license-type';
import Card from 'component/common/card';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
+import { sortLanguageMap } from 'util/default-languages';
// @if TARGET='app'
// import ErrorText from 'component/common/error-text';
@@ -162,9 +163,8 @@ function PublishAdditionalOptions(props: Props) {
value={language}
onChange={(event) => updatePublishForm({ language: event.target.value })}
>
- {Object.entries(SUPPORTED_LANGUAGES).map(([langkey, langName]) => (
- // $FlowFixMe
-
))}
diff --git a/ui/component/settingLanguage/view.jsx b/ui/component/settingLanguage/view.jsx
index d8d530fa2..ab9ca6982 100644
--- a/ui/component/settingLanguage/view.jsx
+++ b/ui/component/settingLanguage/view.jsx
@@ -4,7 +4,7 @@ import React, { useState } from 'react';
import { FormField } from 'component/common/form';
import Spinner from 'component/spinner';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
-import { getDefaultLanguage } from 'util/default-languages';
+import { getDefaultLanguage, sortLanguageMap } from 'util/default-languages';
type Props = {
language: string,
@@ -15,9 +15,7 @@ type Props = {
function SettingLanguage(props: Props) {
const { language, setLanguage, searchInLanguage, setSearchInLanguage } = props;
-
const [previousLanguage, setPreviousLanguage] = useState(null);
- const languages = SUPPORTED_LANGUAGES;
if (previousLanguage && language !== previousLanguage) {
setPreviousLanguage(null);
@@ -41,23 +39,11 @@ function SettingLanguage(props: Props) {
'Multi-language support is brand new and incomplete. Switching your language may have unintended consequences, like glossolalia.'
)}
>
- {Object.entries(languages)
- .sort((a, b) => {
- const lhs = String(a[1]);
- const rhs = String(b[1]);
- if (lhs < rhs) return -1;
- if (lhs > rhs) return 1;
- return 0;
- })
- .map((language) => {
- const langKey = language[0];
- const langName = String(language[1]);
- return (
-
- );
- })}
+ {sortLanguageMap(SUPPORTED_LANGUAGES).map(([langKey, langName]) => (
+
+ ))}
{previousLanguage && }
setLanguage(event.target.value)}
value={language}
>
- {Object.keys(SUPPORTED_LANGUAGES).map((language) => (
-
))}
diff --git a/ui/util/default-languages.js b/ui/util/default-languages.js
index fd5cd4b6b..2e2577c69 100644
--- a/ui/util/default-languages.js
+++ b/ui/util/default-languages.js
@@ -12,3 +12,19 @@ export const getDefaultHomepageKey = () => {
const language = getDefaultLanguage();
return (homepages[language] && language) || (homepages[language.slice(0, 2)] && language.slice(0, 2)) || DEFAULT_LANG;
};
+
+/**
+ * Sorts the language map by their native representation (not by language code).
+ *
+ * @param languages The language map to sort, e.g. "{ 'ja': '日本語', ... }"
+ * @returns {[string, string][]}
+ */
+export function sortLanguageMap(languages) {
+ return Object.entries(languages).sort((a, b) => {
+ const lhs = String(a[1]);
+ const rhs = String(b[1]);
+ if (lhs < rhs) return -1;
+ if (lhs > rhs) return 1;
+ return 0;
+ });
+}