Skip to content

Commit

Permalink
type: add function signature of use-translate (#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu authored Nov 19, 2023
1 parent a6d0879 commit 1f12605
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/packages/__VUE/animate/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const translate = useTranslate({
once: 'Once',
times: 'Several times',
basic: 'Loop animation',
click: 'Click',
FRTL: 'From right to left',
FLTR: 'From left to right',
FTTB: 'From top to bottom',
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/button/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Icon from './demo/icon.vue';
import Size from './demo/size.vue';
import Block from './demo/block.vue';
import Color from './demo/color.vue';
const translate = useTranslate<['type', 'plain', 'disabled', 'shape', 'loading', 'icon', 'size', 'block', 'color']>({
const translate = useTranslate({
'zh-CN': {
type: '按钮类型',
plain: '朴素按钮',
Expand Down
1 change: 1 addition & 0 deletions src/packages/__VUE/calendar/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ const translate = useTranslate({
range: 'Select Date Range',
multiple: 'Select Multiple Date',
week: 'Select Week',
disabledDate: 'Disabled Date',
conjunction: '-',
custom_btn: 'Custom Button',
Expand Down
1 change: 1 addition & 0 deletions src/packages/__VUE/cell/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const translate = useTranslate({
title7: 'Vertical Center',
title8: 'Use Slots title',
title9: 'Size setting large',
title10: 'Desc Slot',
link: 'Link',
urlJump: 'URL Jump',
routerJump: 'Router Jump ’/‘ ',
Expand Down
1 change: 1 addition & 0 deletions src/packages/__VUE/circleprogress/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const translate = useTranslate({
customWidth: 'Custom Width',
Gradient: 'Gradient',
custom: 'custom',
customSize: 'Custom Size',
customContent: 'Custom Content',
dynamicChange: 'Dynamic Change',
reduce: 'reduce',
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/comment/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const translate = useTranslate({
basic: 'Basic Usage',
single: 'Single Line Image',
multiRow: 'Multi Line Image ',
review: 'Additional Review'
additionalReviewd: 'Additional Review'
}
});
let cmt = ref<any>({});
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/grid/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const translate = useTranslate({
square: 'Square',
gutter: 'Gutter',
reverse: 'Reverse',
horizontal: 'Horizontal',
Horizontal: 'Horizontal',
iconStyle: 'Icon Style',
route: 'Route',
customContent: 'Custom Content',
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/image/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const translate = useTranslate({
circle: '圆形图片',
loading: '加载中提示',
error: '加载失败',
lay: '懒加载'
lazy: '懒加载'
},
'en-US': {
basic: 'Basic Usage',
Expand Down
1 change: 0 additions & 1 deletion src/packages/__VUE/searchbar/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const translate = useTranslate({
basic7: '自定义清除图标 icon',
word1: '标签',
word2: '搜索',
title3: '标题3',
shape: '设置搜索框形状'
},
'en-US': {
Expand Down
16 changes: 14 additions & 2 deletions src/packages/__VUE/uploader/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ const translate = useTranslate({
title11: '手动执行上传',
title12: '禁用状态',
title13: '自定义 xhr 上传方式(before-xhr-upload)',
title14: '手动清空上传'
title14: '手动清空上传',
ready: '准备完成',
readyUpload: '准备上传',
waitingUpload: '等待上传',
uploading: '上传中',
success: '上传成功',
error: '上传失败'
},
'en-US': {
basic: 'Basic Usage',
Expand All @@ -85,7 +91,13 @@ const translate = useTranslate({
title11: 'Manual upload',
title12: 'Disabled state',
title13: 'Customize XHR upload (before-xhr-upload)',
title14: 'Clear upload manually'
title14: 'Clear upload manually',
ready: 'Ready',
readyUpload: 'Ready to upload',
waitingUpload: 'Waiting for upload',
uploading: 'Uploading',
success: 'Upload successful',
error: 'Upload failed'
}
});
const uploadUrl = 'https://my-json-server.typicode.com/linrufeng/demo/posts';
Expand Down
20 changes: 10 additions & 10 deletions src/sites/assets/util/useTranslate.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Locale from '@/packages/locale';
import { useLocale } from '@/packages/utils/useLocale';
export const currentLang = Locale.currentLang;
// @type-challenges
type TupleToUnion<T extends any[]> = T[number];
export const useTranslate = <T extends string[]>(object: {
'zh-CN': {
[key in TupleToUnion<T>]: string | string[] | Function;
};
'en-US': {
[key in TupleToUnion<T>]: string | string[] | Function;
};

export const useTranslate = <
T1 extends {
[key: string]: any;
},
T2 extends T1
>(object: {
'zh-CN': T1;
'en-US': T2;
}) => {
for (const [key, value] of Object.entries(object)) {
Locale.merge(key, value);
}
return useLocale<TupleToUnion<T>>();
return useLocale<Exclude<Extract<keyof T1, keyof T2>, number | symbol>>();
};

export const translateChange = () => {
Expand Down

0 comments on commit 1f12605

Please sign in to comment.