Merge pull request #2018 from Yidadaa/bugfix-0617

feat: add nynorsk option
This commit is contained in:
Yifei Zhang 2023-06-17 01:20:06 +08:00 committed by GitHub
commit 0a2cccfd6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 76 additions and 84 deletions

View File

@ -284,7 +284,8 @@ type DeepPartial<T> = T extends object
[P in keyof T]?: DeepPartial<T[P]>; [P in keyof T]?: DeepPartial<T[P]>;
} }
: T; : T;
export type LocaleType = DeepPartial<typeof cn>;
export type RequiredLocaleType = typeof cn; export type LocaleType = typeof cn;
export type PartialLocaleType = DeepPartial<typeof cn>;
export default cn; export default cn;

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const cs: LocaleType = { const cs: PartialLocaleType = {
WIP: "V přípravě...", WIP: "V přípravě...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const de: LocaleType = { const de: PartialLocaleType = {
WIP: "In Bearbeitung...", WIP: "In Bearbeitung...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import { RequiredLocaleType } from "./index"; import { LocaleType } from "./index";
const en: RequiredLocaleType = { const en: LocaleType = {
WIP: "Coming Soon...", WIP: "Coming Soon...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const es: LocaleType = { const es: PartialLocaleType = {
WIP: "En construcción...", WIP: "En construcción...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const fr: LocaleType = { const fr: PartialLocaleType = {
WIP: "Prochainement...", WIP: "Prochainement...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,57 +1,71 @@
import CN from "./cn"; import cn from "./cn";
import EN from "./en"; import en from "./en";
import TW from "./tw"; import tw from "./tw";
import FR from "./fr"; import fr from "./fr";
import ES from "./es"; import es from "./es";
import IT from "./it"; import it from "./it";
import TR from "./tr"; import tr from "./tr";
import JP from "./jp"; import jp from "./jp";
import DE from "./de"; import de from "./de";
import VI from "./vi"; import vi from "./vi";
import RU from "./ru"; import ru from "./ru";
import NO from "./no"; import no from "./no";
import CS from "./cs"; import cs from "./cs";
import KO from "./ko"; import ko from "./ko";
import { merge } from "../utils/merge"; import { merge } from "../utils/merge";
export type { LocaleType, RequiredLocaleType } from "./cn"; import type { LocaleType } from "./cn";
export type { LocaleType, PartialLocaleType } from "./cn";
export const AllLangs = [ const ALL_LANGS = {
"en", cn,
"cn", en,
"tw", tw,
"fr", jp,
"es", ko,
"it", fr,
"tr", es,
"jp", it,
"de", tr,
"vi", de,
"ru", vi,
"cs", ru,
"ko", cs,
] as const; no,
export type Lang = (typeof AllLangs)[number]; };
export type Lang = keyof typeof ALL_LANGS;
export const AllLangs = Object.keys(ALL_LANGS) as Lang[];
export const ALL_LANG_OPTIONS: Record<Lang, string> = { export const ALL_LANG_OPTIONS: Record<Lang, string> = {
cn: "简体中文", cn: "简体中文",
en: "English", en: "English",
tw: "繁體中文", tw: "繁體中文",
jp: "日本語",
ko: "한국어",
fr: "Français", fr: "Français",
es: "Español", es: "Español",
it: "Italiano", it: "Italiano",
tr: "Türkçe", tr: "Türkçe",
jp: "日本語",
de: "Deutsch", de: "Deutsch",
vi: "Tiếng Việt", vi: "Tiếng Việt",
ru: "Русский", ru: "Русский",
cs: "Čeština", cs: "Čeština",
ko: "한국어", no: "Nynorsk",
}; };
const LANG_KEY = "lang"; const LANG_KEY = "lang";
const DEFAULT_LANG = "en"; const DEFAULT_LANG = "en";
const fallbackLang = en;
const targetLang = ALL_LANGS[getLang()] as LocaleType;
// if target lang missing some fields, it will use fallback lang string
merge(fallbackLang, targetLang);
export default fallbackLang as LocaleType;
function getItem(key: string) { function getItem(key: string) {
try { try {
return localStorage.getItem(key); return localStorage.getItem(key);
@ -96,26 +110,3 @@ export function changeLang(lang: Lang) {
setItem(LANG_KEY, lang); setItem(LANG_KEY, lang);
location.reload(); location.reload();
} }
const fallbackLang = EN;
const targetLang = {
en: EN,
cn: CN,
tw: TW,
fr: FR,
es: ES,
it: IT,
tr: TR,
jp: JP,
de: DE,
vi: VI,
ru: RU,
no: NO,
cs: CS,
ko: KO,
}[getLang()] as typeof CN;
// if target lang missing some fields, it will use fallback lang string
merge(fallbackLang, targetLang);
export default fallbackLang as typeof CN;

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const it: LocaleType = { const it: PartialLocaleType = {
WIP: "Work in progress...", WIP: "Work in progress...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const jp: LocaleType = { const jp: PartialLocaleType = {
WIP: "この機能は開発中です", WIP: "この機能は開発中です",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,8 +1,8 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const ko: LocaleType = { const ko: PartialLocaleType = {
WIP: "곧 출시 예정...", WIP: "곧 출시 예정...",
Error: { Error: {
Unauthorized: "권한이 없습니다. 설정 페이지에서 액세스 코드를 입력하세요.", Unauthorized: "권한이 없습니다. 설정 페이지에서 액세스 코드를 입력하세요.",

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const no: LocaleType = { const no: PartialLocaleType = {
WIP: "Arbeid pågår ...", WIP: "Arbeid pågår ...",
Error: { Error: {
Unauthorized: "Du har ikke tilgang. Vennlig oppgi tildelt adgangskode.", Unauthorized: "Du har ikke tilgang. Vennlig oppgi tildelt adgangskode.",

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const ru: LocaleType = { const ru: PartialLocaleType = {
WIP: "Скоро...", WIP: "Скоро...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const tr: LocaleType = { const tr: PartialLocaleType = {
WIP: "Çalışma devam ediyor...", WIP: "Çalışma devam ediyor...",
Error: { Error: {
Unauthorized: Unauthorized:

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const tw: LocaleType = { const tw: PartialLocaleType = {
WIP: "該功能仍在開發中……", WIP: "該功能仍在開發中……",
Error: { Error: {
Unauthorized: "目前您的狀態是未授權,請前往設定頁面輸入授權碼。", Unauthorized: "目前您的狀態是未授權,請前往設定頁面輸入授權碼。",

View File

@ -1,7 +1,7 @@
import { SubmitKey } from "../store/config"; import { SubmitKey } from "../store/config";
import type { LocaleType } from "./index"; import type { PartialLocaleType } from "./index";
const vi: LocaleType = { const vi: PartialLocaleType = {
WIP: "Sắp ra mắt...", WIP: "Sắp ra mắt...",
Error: { Error: {
Unauthorized: Unauthorized: