Skip to content

Commit

Permalink
improve i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
mebtte committed Aug 1, 2023
1 parent 03ee853 commit 601c8ef
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 30 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 en from './en';
import enUS from './en_us';

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

const LANGUAGE_MAP: Record<Language, typeof en> = {
[Language.EN]: en,
const LANGUAGE_MAP: Record<Language, typeof enUS> = {
[Language.EN_US]: enUS,
[Language.ZH_HANS]: zhHans,
[Language.JA]: ja,
};
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/i18n/ja.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Key } from './constants';
import en from './en';
import enUS from './en_us';

const ja: {
[key in Key]: string;
} = {
...en,
...enUS,
};

export default ja;
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 en from './en';
import enUS from './en_us';

export type Key = keyof typeof en;
export type Key = keyof typeof enUS;
7 changes: 7 additions & 0 deletions apps/pwa/src/i18n/en.ts → apps/pwa/src/i18n/en_us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ export default {
nickname: 'nickname',
join_time: 'join time',
zero_means_unlimited: '0 means unlimited',
delete_music: 'delete music',
delete: 'delete',
music_forked_by_other_can_not_be_deleted:
'music forked by other can not be deleted',
year_of_issue: 'year of issue',
edit_year_of_issue: 'edit year of issue',
year_of_issue_limit: 'year of issue should be between %s1 and %s2',
};
4 changes: 2 additions & 2 deletions apps/pwa/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ switch (setting.get().language) {
break;
}
default: {
({ default: translation } = await import('./en'));
({ default: translation } = await import('./en_us'));
}
}

Expand All @@ -35,7 +35,7 @@ export const LANGUAGE_MAP: Record<
label: string;
}
> = {
[Language.EN]: { label: 'english' },
[Language.EN_US]: { label: 'English(US)' },
[Language.ZH_HANS]: { label: '简体中文' },
[Language.JA]: { label: '日本語' },
};
Expand Down
4 changes: 2 additions & 2 deletions apps/pwa/src/i18n/ja.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Key } from './constants';
import en from './en';
import enUS from './en_us';

const ja: {
[key in Key]: string;
} = {
...en,
...enUS,
};

export default ja;
16 changes: 11 additions & 5 deletions apps/pwa/src/i18n/zh_hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ const zhCN: {
maximum_amount_of_musicbill: '乐单最大数量',
maximum_amount_of_creating_music_per_day: '每天创建音乐最大数量',
music_play_record_indate: '音乐播放记录保留天数',
should_be_greater_than: '%s1应该大于%s2',
should_be_greater_than_or_equal_to: '%s1应该大于等于%s2',
should_be_less_than_or_equal_to: '%s1应该小于等于%s2',
length_of: '%s1长度',
should_be_greater_than: '%s1 应该大于 %s2',
should_be_greater_than_or_equal_to: '%s1 应该大于等于 %s2',
should_be_less_than_or_equal_to: '%s1 应该小于等于 %s2',
length_of: '%s1 长度',
nickname: '昵称',
join_time: '加入时间',
zero_means_unlimited: '0表示无限制',
zero_means_unlimited: '0 表示无限制',
delete_music: '删除音乐',
delete: '删除',
music_forked_by_other_can_not_be_deleted: '被二次创作的音乐无法被删除',
year_of_issue: '发行年份',
edit_year_of_issue: '编辑发行年份',
year_of_issue_limit: '发行年份应在 %s1 - %s2 之间',
};

export default zhCN;
32 changes: 22 additions & 10 deletions apps/pwa/src/pages/player/music_drawer/edit_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import absoluteFullSize from '@/style/absolute_full_size';
import useTitlebarArea from '@/utils/use_titlebar_area_rect';
import { Variant } from '@/components/button';
import getResizedImage from '@/server/asset/get_resized_image';
import { t } from '@/i18n';
import { Music, ZIndex } from '../constants';
import { MusicDetail } from './constants';
import e, { EventType } from './eventemitter';
Expand Down Expand Up @@ -428,7 +429,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, '更新二次创作来源失败');
logger.error(error, "Failed to update music's fork-from");
notice.error(error.message);
return false;
}
Expand All @@ -440,11 +441,11 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdOutlineCalendarToday />}
label="编辑发行年份"
label={t('edit_year_of_issue')}
onClick={() =>
dialog.input({
title: '编辑发行年份',
label: '发行年份',
title: t('edit_year_of_issue'),
label: t('year_of_issue'),
initialValue: music.year ? music.year.toString() : '',
inputType: 'number',
onConfirm: async (year: string) => {
Expand All @@ -455,7 +456,13 @@ function EditMenu({ music }: { music: MusicDetail }) {
yearNumber < YEAR_MIN ||
yearNumber > YEAR_MAX
) {
notice.error(`发行年份应在 ${YEAR_MIN}-${YEAR_MAX} 范围内`);
notice.error(
t(
'year_of_issue_limit',
YEAR_MIN.toString(),
YEAR_MAX.toString(),
),
);
return false;
}

Expand All @@ -468,7 +475,10 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, '更新音乐发行年份失败');
logger.error(
error,
"Failed to update music's year of issue",
);
notice.error(error.message);
return false;
}
Expand All @@ -480,13 +490,15 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdDelete style={dangerousIconStyle} />}
label="删除"
label={t('delete')}
onClick={() => {
if (music.forkList.length) {
return notice.error('被二次创作的音乐无法被删除');
return notice.error(
t('music_forked_by_other_can_not_be_deleted'),
);
}
return dialog.captcha({
confirmText: '删除音乐',
confirmText: t('delete_music'),
confirmVariant: Variant.DANGER,
onConfirm: async ({ captchaId, captchaValue }) => {
try {
Expand All @@ -495,7 +507,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
id: music.id,
});
} catch (error) {
logger.error(error, '删除音乐失败');
logger.error(error, 'Failed to delete music');
notice.error(error.message);

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

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

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

0 comments on commit 601c8ef

Please sign in to comment.