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 bc5b8bd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
17 changes: 15 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,17 @@ 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() ? ',' : ', ';
};

export const getColon = () => {
return isChinese() ? ':' : ': ';
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { i18n, Node } from '@antv/s2';
import { getColon, i18n, Node } from '@antv/s2';
import cls from 'classnames';
import React from 'react';
import { getStrategySheetTooltipClsName as tooltipCls } from '@antv/s2-shared';
Expand All @@ -22,7 +22,9 @@ export const StrategySheetRowTooltip: React.FC<CustomTooltipProps> = ({
<div className={tooltipCls('value')}>{rowName}</div>
{description && (
<div className={tooltipCls('description')}>
{i18n('说明')}: {description}
{i18n('说明')}
{getColon()}
{description}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { i18n, TOOLTIP_PREFIX_CLS } from '@antv/s2';
import { getColon, i18n, TOOLTIP_PREFIX_CLS } from '@antv/s2';

interface TooltipDescriptionProps {
description: string;
Expand All @@ -12,7 +12,9 @@ export const TooltipDescription: React.FC<TooltipDescriptionProps> = ({
<>
{description && (
<div className={`${TOOLTIP_PREFIX_CLS}-description`}>
{i18n('说明')}{description}
{i18n('说明')}
{getColon()}
{description}
</div>
)}
</>
Expand Down
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 bc5b8bd

Please sign in to comment.