Skip to content

Commit

Permalink
fix: 修复中英文标点符号
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Dec 1, 2023
1 parent 1207fa0 commit 7e10791
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
13 changes: 11 additions & 2 deletions packages/s2-core/src/common/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const setLang = (langType: LangType) => {
lang = langType || DEFAULT_LANG;
};

const isChinese = () => getLang() === 'zh_CN';

/**
* 拓展locale配置
*/
Expand All @@ -36,6 +38,13 @@ export const extendLocale = (extraLocale: LocaleType) => {

export const getLocale = () => locale;

export const i18n = (key: string, defaultValue = key) => {
return get(locale, [lang, key], defaultValue);
export const i18n = (key: string, defaultValue = key) =>
get(locale, [lang, key], defaultValue);

export const wrapWithBracket = (text: string) => {
return `${isChinese() ? '(' : '('}${text}${isChinese() ? ')' : ')'}`;
};

export const getComma = () => {
return isChinese() ? ',' : ', ';
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type TooltipDetailListItem,
type TooltipHeadInfo,
TOOLTIP_PREFIX_CLS,
getComma,
} from '@antv/s2';

export const TooltipHead: React.FC<TooltipHeadInfo> = (props) => {
Expand All @@ -11,7 +12,7 @@ export const TooltipHead: React.FC<TooltipHeadInfo> = (props) => {
return (
<div className={`${TOOLTIP_PREFIX_CLS}-head-info-list`}>
{cols.map((item: TooltipDetailListItem) => item.value)?.join('/')}
{cols.length > 0 && rows.length > 0 && ','}
{cols.length > 0 && rows.length > 0 && getComma()}
{rows.map((item: TooltipDetailListItem) => item.value)?.join('/')}
</div>
);
Expand Down
10 changes: 8 additions & 2 deletions packages/s2-react/src/components/tooltip/components/summary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from 'react';
import { size, sumBy } from 'lodash';
import { i18n, TOOLTIP_PREFIX_CLS, type TooltipSummaryProps } from '@antv/s2';
import {
i18n,
TOOLTIP_PREFIX_CLS,
type TooltipSummaryProps,
wrapWithBracket,
} from '@antv/s2';
import cls from 'classnames';

export const TooltipSummary: React.FC<TooltipSummaryProps> = React.memo(
Expand Down Expand Up @@ -33,7 +38,8 @@ export const TooltipSummary: React.FC<TooltipSummaryProps> = React.memo(
>
{name ? (
<span className={`${TOOLTIP_PREFIX_CLS}-summary-key`}>
{name}{i18n('总和')})
{name}
{wrapWithBracket(i18n('总和'))}
</span>
) : (
<span className={`${TOOLTIP_PREFIX_CLS}-summary-key`}>
Expand Down

0 comments on commit 7e10791

Please sign in to comment.