Skip to content

Commit

Permalink
improve i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
mebtte committed Aug 9, 2023
1 parent eacf111 commit 9c3cb72
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 38 deletions.
16 changes: 16 additions & 0 deletions apps/pwa/src/i18n/en_us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,20 @@ export default {
no_music: 'no music',
no_modify_record: 'no modify record',
no_public_musicbill: 'no public musicbill',
edit_cover: 'edit cover',
please_select_a_cover: 'please select a cover',
reset_cover: 'reset cover',
reset_cover_question: 'are you sure to reset cover ?',
edit_lyric: 'edit lyric',
lyric: 'lyric',
text_of_lrc: 'text of lrc',
modify_singer: 'modify singer',
singer: 'singer',
please_select_singers: 'please select singers',
modify_file_of_music: 'modify file of music',
file_of_music: 'file of music',
please_select_a_file: 'please select a file',
one_of_formats: 'one of formats: %s1',
modify_fork_from: 'modify fork-from',
fork_from: 'fork-from',
};
16 changes: 16 additions & 0 deletions apps/pwa/src/i18n/zh_hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ const zhCN: {
no_music: '暂无音乐',
no_modify_record: '暂无修改记录',
no_public_musicbill: '暂无公开乐单',
edit_cover: '编辑封面',
please_select_a_cover: '请选择封面',
reset_cover: '重置封面',
reset_cover_question: '确定重置封面吗?',
edit_lyric: '编辑歌词',
lyric: '歌词',
text_of_lrc: 'LRC 格式文本',
modify_singer: '修改歌手',
singer: '歌手',
please_select_singers: '请选择歌手',
modify_file_of_music: '修改音乐文件',
file_of_music: '音乐文件',
please_select_a_file: '请选择一个文件',
one_of_formats: '以下格式的一种: %s1',
modify_fork_from: '修改二次创作来源',
fork_from: '二次创作来源',
};

export default zhCN;
76 changes: 38 additions & 38 deletions apps/pwa/src/pages/player/music_drawer/edit_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdImage />}
label="编辑封面"
label={t('edit_cover')}
onClick={() =>
dialog.imageCut({
title: '编辑封面',
title: t('edit_cover'),
onConfirm: async (cover) => {
if (!cover) {
notice.error('请选择封面');
notice.error(t('please_select_a_cover'));
return false;
}
try {
Expand All @@ -180,7 +180,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, "Updating music's cover fail");
logger.error(error, 'Failed to update cover of music');
notice.error(error.message);
return false;
}
Expand All @@ -192,11 +192,10 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdImage />}
label="重置封面"
label={t('reset_cover')}
onClick={() =>
dialog.confirm({
title: '确定重置封面吗?',
content: '重置后音乐将使用默认封面',
title: t('reset_cover_question'),
onConfirm: async () => {
try {
await updateMusic({
Expand All @@ -206,7 +205,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, '重置音乐封面失败');
logger.error(error, 'Failed to reset cover of music');
dialog.alert({
content: error.message,
});
Expand All @@ -220,17 +219,17 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdTitle />}
label="编辑名字"
label={t('edit_name')}
onClick={() =>
dialog.input({
title: '编辑名字',
label: '名字',
title: t('edit_name'),
label: t('name'),
initialValue: music.name,
maxLength: NAME_MAX_LENGTH,
onConfirm: async (name: string) => {
const trimmedName = name.replace(/\s+/g, ' ').trim();
if (!trimmedName.length) {
notice.error('请输入名字');
notice.error(t('please_enter_the_name'));
return false;
}

Expand All @@ -243,7 +242,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, '更新音乐名字失败');
logger.error(error, 'Failed to update name of music');
notice.error(error.message);
return false;
}
Expand All @@ -255,11 +254,11 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdTextFields />}
label="编辑别名"
label={t('edit_alias')}
onClick={() =>
dialog.inputList({
title: '编辑别名',
label: '别名',
title: t('edit_alias'),
label: t('alias'),
initialValue: music.aliases,
max: MUSIC_MAX_ALIAS_COUNT,
maxLength: ALIAS_MAX_LENGTH,
Expand All @@ -277,7 +276,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, "Updating music's aliases fail");
logger.error(error, 'Failed to update aliases of music');
notice.error(error.message);
return false;
}
Expand All @@ -290,15 +289,15 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdTextFields />}
label="编辑歌词"
label={t('edit_lyric')}
onClick={() =>
dialog.textareaList({
title: '编辑歌词',
label: '歌词',
title: t('edit_lyric'),
label: t('lyric'),
initialValue: music.lyrics.map((l) => l.lrc),
max: MUSIC_MAX_LRYIC_AMOUNT,
maxLength: LYRIC_MAX_LENGTH,
placeholder: 'LRC 格式的文本',
placeholder: t('text_of_lrc'),
onConfirm: async (lyrics: string[]) => {
const trimmedLyrics = lyrics
.map((l) => l.trim())
Expand All @@ -318,7 +317,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, 'Updating lyrics fail');
logger.error(error, 'Failed to update lyrics of music');
notice.error(error.message);
return false;
}
Expand All @@ -331,19 +330,19 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdGroup />}
label="编辑歌手列表"
label={t('modify_singer')}
onClick={() =>
dialog.multipleSelect<Singer>({
label: '歌手列表',
label: t('singer'),
labelAddon: <MissingSinger />,
title: '编辑歌手列表',
title: t('modify_singer'),
optionsGetter: searchSinger,
initialValue: music.singers.map(
formatSingerToMultipleSelectOption,
),
onConfirm: async (options) => {
if (!options.length) {
notice.error('请选择歌手');
notice.error(t('please_select_singers'));
return false;
}

Expand All @@ -361,7 +360,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, '更新歌手列表失败');
logger.error(error, 'Failed to modify singers of music');
notice.error(error.message);
return false;
}
Expand All @@ -373,18 +372,19 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdOutlineFilePresent />}
label="编辑音乐文件"
label={t('modify_file_of_music')}
onClick={() =>
dialog.fileSelect({
title: '编辑音乐文件',
label: '音乐文件',
title: t('modify_file_of_music'),
label: t('file_of_music'),
acceptTypes: ASSET_TYPE_MAP[AssetType.MUSIC].acceptTypes,
placeholder: `选择文件, 支持以下类型 ${ASSET_TYPE_MAP[
AssetType.MUSIC
].acceptTypes.join(',')}`,
placeholder: t(
'one_of_formats',
ASSET_TYPE_MAP[AssetType.MUSIC].acceptTypes.join(','),
),
onConfirm: async (file) => {
if (!file) {
notice.error('请选择文件');
notice.error(t('please_select_a_file'));
return false;
}
try {
Expand All @@ -396,7 +396,7 @@ function EditMenu({ music }: { music: MusicDetail }) {
});
emitMusicUpdated(music.id);
} catch (error) {
logger.error(error, 'Updating music asset fail');
logger.error(error, 'Failed to modify file of music');
notice.error(error.message);
return false;
}
Expand All @@ -407,11 +407,11 @@ function EditMenu({ music }: { music: MusicDetail }) {
<MenuItem
style={itemStyle}
icon={<MdCallSplit />}
label="编辑二次创作来源"
label={t('modify_fork_from')}
onClick={() =>
dialog.multipleSelect<Music>({
title: '二次创作来源',
label: '创作来源自以下音乐',
title: t('modify_fork_from'),
label: t('fork_from'),
optionsGetter: searchMusic,
initialValue: music.forkFromList.map(
formatMusicTouMultipleSelectOtion,
Expand Down

0 comments on commit 9c3cb72

Please sign in to comment.