Skip to content

Commit

Permalink
refactor i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
mebtte committed Oct 23, 2024
1 parent 0652971 commit ff63825
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 45 deletions.
4 changes: 2 additions & 2 deletions apps/cli/src/i18n/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import enUS from './en_us';
import en from './en';

export type Key = keyof typeof enUS;
export type Key = keyof typeof en;
File renamed without changes.
10 changes: 4 additions & 6 deletions apps/cli/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Language } from '#/constants';
import { Key } from './constants';
import enUS from './en_us';
import en from './en';
import zhHans from './zh_hans';
import ja from './ja';

const LANGUAGE_MAP: Record<Language, typeof enUS> = {
[Language.EN_US]: enUS,
const LANGUAGE_MAP: Record<Language, typeof en> = {
[Language.EN]: en,
[Language.ZH_HANS]: zhHans,
[Language.JA]: ja,
};

export function t(key: Key, language: Language, ...args: string[]) {
Expand All @@ -22,4 +20,4 @@ export function t(key: Key, language: Language, ...args: string[]) {
return value;
}

export { Key };
export type { Key };
10 changes: 0 additions & 10 deletions apps/cli/src/i18n/ja.ts

This file was deleted.

5 changes: 0 additions & 5 deletions apps/pwa/src/global_states/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ function getInitialLanguage() {
case 'zh-cn': {
return Language.ZH_HANS;
}

case 'ja': {
return Language.JA;
}

default: {
return DEFAULT_LANGUAGE;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/pwa/src/i18n/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import enUS from './en_us';
import en from './en';

export type Key = keyof typeof enUS;
export type Key = keyof typeof en;
File renamed without changes.
9 changes: 2 additions & 7 deletions apps/pwa/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ switch (useSetting.getState().language) {
({ default: translation } = await import('./zh_hans'));
break;
}
case Language.JA: {
({ default: translation } = await import('./ja'));
break;
}
default: {
({ default: translation } = await import('./en_us'));
({ default: translation } = await import('./en'));
}
}

Expand All @@ -35,9 +31,8 @@ export const LANGUAGE_MAP: Record<
label: string;
}
> = {
[Language.EN_US]: { label: 'English(US)' },
[Language.EN]: { label: 'English' },
[Language.ZH_HANS]: { label: '简体中文' },
[Language.JA]: { label: '日本語' },
};

export type { Key };
10 changes: 0 additions & 10 deletions apps/pwa/src/i18n/ja.ts

This file was deleted.

5 changes: 2 additions & 3 deletions shared/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ export const SINGER_MODIFY_RECORD_TTL = 1000 * 60 * 60 * 24 * 180;

export enum Language {
ZH_HANS = 'zh-hans',
EN_US = 'en-us',
JA = 'ja',
EN = 'en',
}
export const LANGUAGES = Object.values(Language);
export const DEFAULT_LANGUAGE = Language.EN_US;
export const DEFAULT_LANGUAGE = Language.EN;

export enum CommonQuery {
VERSION = '__v',
Expand Down

0 comments on commit ff63825

Please sign in to comment.