Skip to content

Commit

Permalink
fix: 修复 Drawer、Tooltip 组件默认按钮的国际化问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean-gao committed Dec 26, 2024
1 parent 5b7aec4 commit 0d3ba62
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
7 changes: 5 additions & 2 deletions components/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useConfig } from '../config-provider';
import { useTheme } from '../_theme/useTheme';
import { pxfy } from '../_util/utils';
import useEsc from '../_util/use/useEsc';
import { useLocale } from '../config-provider/useLocale';
import { useResizable } from './useResizable';
import { COMPONENT_NAME, prefixCls } from './const';
import {
Expand Down Expand Up @@ -63,6 +64,8 @@ const Drawer = defineComponent({
() => props.getContainer || config.getContainer?.value,
);

const { t } = useLocale();

function handleCancel(event: MouseEvent | KeyboardEvent) {
ctx.emit(UPDATE_SHOW_EVENT, false);
ctx.emit(CANCEL_EVENT, event);
Expand Down Expand Up @@ -120,11 +123,11 @@ const Drawer = defineComponent({
onClick={handleOk}
loading={props.okLoading}
>
{props.okText}
{props.okText || t('drawer.okText')}
</FButton>
{props.showCancel && (
<FButton size="middle" onClick={handleCancel}>
{props.cancelText}
{props.cancelText || t('drawer.cancelText')}
</FButton>
)}
</>
Expand Down
10 changes: 2 additions & 8 deletions components/drawer/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@ export const drawerProps = {
default: false,
},
title: String,
okText: {
type: String,
default: '确定',
},
okText: String,
okLoading: Boolean,
cancelText: {
type: String,
default: '取消',
},
cancelText: String,
showCancel: {
type: Boolean,
default: true,
Expand Down
8 changes: 8 additions & 0 deletions components/locales/lang/enUS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ export default {
okText: 'Confirm',
cancelText: 'Cancel',
},
drawer: {
okText: 'Confirm',
cancelText: 'Cancel',
},
tooltip: {
okText: 'Confirm',
cancelText: 'Cancel',
},
};
8 changes: 8 additions & 0 deletions components/locales/lang/zhCN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,12 @@ export default {
okText: '确定',
cancelText: '取消',
},
drawer: {
okText: '确定',
cancelText: '取消',
},
tooltip: {
okText: '确定',
cancelText: '取消',
},
};
8 changes: 8 additions & 0 deletions components/locales/lang/zr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ export default {
okText: 'تأكيد',
cancelText: 'إلغاء',
},
drawer: {
okText: 'تأكيد',
cancelText: 'إلغاء',
},
tooltip: {
okText: 'تأكيد',
cancelText: 'إلغاء',
},
};
11 changes: 7 additions & 4 deletions components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import FButton from '../button/button';
import { popperProps } from '../popper/props';
import { CANCEL_EVENT, OK_EVENT, UPDATE_MODEL_EVENT } from '../_util/constants';
import type { ExtractPublicPropTypes } from '../_util/interface';
import { useLocale } from '../config-provider/useLocale';

const prefixCls = getPrefixCls('tooltip');

const defaultConfirmOption = {
okText: '确定',
cancelText: '取消',
okText: '',
cancelText: '',
showOk: true,
showCancel: true,
icon: <ExclamationCircleFilled />,
Expand Down Expand Up @@ -64,6 +65,8 @@ export default defineComponent({
currentValue.value = val;
};

const { t } = useLocale();

const popperElRef = ref(null);

function getPopperSlots() {
Expand Down Expand Up @@ -134,7 +137,7 @@ export default defineComponent({
size="small"
type="primary"
>
{mergeOpt.okText}
{mergeOpt.okText || t('tooltip.okText')}
</FButton>
)}
{
Expand All @@ -146,7 +149,7 @@ export default defineComponent({
}
size="small"
>
{mergeOpt.cancelText}
{mergeOpt.cancelText || t('tooltip.cancelText')}
</FButton>
)
}
Expand Down

0 comments on commit 0d3ba62

Please sign in to comment.