fix(mobile): sort language keys
This commit is contained in:
parent
9e4b7a50cf
commit
d27e5aba03
|
|
@ -1,7 +1,7 @@
|
|||
import { parseHtml } from "@follow/components/ui/markdown/parse-html.js"
|
||||
import { views } from "@follow/constants"
|
||||
import type { SupportedLanguages } from "@follow/models/types"
|
||||
import { LANGUAGE_MAP } from "@follow/shared"
|
||||
import { ACTION_LANGUAGE_MAP } from "@follow/shared"
|
||||
import { franc } from "franc-min"
|
||||
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
|
|
@ -23,7 +23,7 @@ export const checkLanguage = ({
|
|||
const pureContent = parseHtml(content)
|
||||
.toText()
|
||||
.replaceAll(/https?:\/\/\S+|www\.\S+/g, " ")
|
||||
const { code } = LANGUAGE_MAP[language]
|
||||
const { code } = ACTION_LANGUAGE_MAP[language]
|
||||
if (!code) {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { useMobile } from "@follow/components/hooks/useMobile.js"
|
|||
import { ResponsiveSelect } from "@follow/components/ui/select/responsive.js"
|
||||
import { UserRole } from "@follow/constants"
|
||||
import { useTypeScriptHappyCallback } from "@follow/hooks"
|
||||
import { LANGUAGE_MAP } from "@follow/shared"
|
||||
import { ACTION_LANGUAGE_MAP } from "@follow/shared"
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
|
|
@ -302,7 +302,7 @@ const ActionLanguageSelector = () => {
|
|||
}}
|
||||
items={[
|
||||
{ label: t("general.action_language.default"), value: DEFAULT_ACTION_LANGUAGE },
|
||||
...Object.values(LANGUAGE_MAP),
|
||||
...Object.values(ACTION_LANGUAGE_MAP),
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import type { SupportedLanguage } from "@follow/shared"
|
||||
import { LANGUAGE_MAP } from "@follow/shared"
|
||||
import { ACTION_LANGUAGE_KEYS } from "@follow/shared"
|
||||
import i18next from "i18next"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { Text, View } from "react-native"
|
||||
|
||||
import type { MobileSupportedLanguages } from "@/src/@types/constants"
|
||||
import { currentSupportedLanguages } from "@/src/@types/constants"
|
||||
import { setGeneralSetting, useGeneralSettingKey } from "@/src/atoms/settings/general"
|
||||
import {
|
||||
|
|
@ -25,17 +25,18 @@ import type { NavigationControllerView } from "@/src/lib/navigation/types"
|
|||
function LanguageSelect({ settingKey }: { settingKey: "language" | "actionLanguage" }) {
|
||||
const { t } = useTranslation("lang")
|
||||
const languageMapWithTranslation = useMemo(() => {
|
||||
const data = (Object.keys(LANGUAGE_MAP) as SupportedLanguage[]).map((key) => ({
|
||||
subLabel: t(`langs.${key}`, { lng: key }),
|
||||
const languageKeys =
|
||||
settingKey === "language"
|
||||
? (currentSupportedLanguages as MobileSupportedLanguages[])
|
||||
: ACTION_LANGUAGE_KEYS.sort(
|
||||
(a, b) => currentSupportedLanguages.indexOf(a) - currentSupportedLanguages.indexOf(b),
|
||||
)
|
||||
|
||||
return languageKeys.map((key) => ({
|
||||
subLabel: settingKey === "language" ? t(`langs.${key}`, { lng: key }) : undefined,
|
||||
label: t(`langs.${key}`),
|
||||
value: key,
|
||||
}))
|
||||
|
||||
return settingKey === "language"
|
||||
? data.filter((item) => {
|
||||
return currentSupportedLanguages.includes(item.value)
|
||||
})
|
||||
: data
|
||||
}, [settingKey, t])
|
||||
const language = useGeneralSettingKey(settingKey)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import type { z } from "zod"
|
|||
|
||||
import type { languageSchema } from "./hono"
|
||||
|
||||
export type SupportedLanguage = z.infer<typeof languageSchema>
|
||||
export const LANGUAGE_MAP: Record<
|
||||
SupportedLanguage,
|
||||
export type SupportedActionLanguage = z.infer<typeof languageSchema>
|
||||
export const ACTION_LANGUAGE_MAP: Record<
|
||||
SupportedActionLanguage,
|
||||
{
|
||||
label: string
|
||||
value: string
|
||||
|
|
@ -106,3 +106,4 @@ export const LANGUAGE_MAP: Record<
|
|||
code: "tur",
|
||||
},
|
||||
}
|
||||
export const ACTION_LANGUAGE_KEYS = Object.keys(ACTION_LANGUAGE_MAP) as SupportedActionLanguage[]
|
||||
|
|
|
|||
Loading…
Reference in New Issue