diff --git a/packages/s2-core/__tests__/unit/common/i18n/index-spec.ts b/packages/s2-core/__tests__/unit/common/i18n/index-spec.ts index 84f4e7e476..d2d858e063 100644 --- a/packages/s2-core/__tests__/unit/common/i18n/index-spec.ts +++ b/packages/s2-core/__tests__/unit/common/i18n/index-spec.ts @@ -35,8 +35,8 @@ describe('I18n Test', () => { expect(i18n(',')).toEqual(', '); }); - test('should show russian text when set lang to ru', () => { - setLang('ru'); + test('should show russian text when set lang to ru_RU', () => { + setLang('ru_RU'); expect(i18n('小计')).toEqual('Промежуточный итог'); expect(i18n('总计')).toEqual('Общий итог'); expect(i18n('总和')).toEqual('(СУММА)'); diff --git a/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts b/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts index 1bcfafb1cd..d8c4615870 100644 --- a/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts +++ b/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts @@ -1,28 +1,28 @@ // eslint-disable-next-line max-classes-per-file -import { getContainer } from 'tests/util/helpers'; -import dataCfg from 'tests/data/simple-data.json'; import { Canvas, Event as GEvent } from '@antv/g-canvas'; import { cloneDeep, get, last } from 'lodash'; -import { PivotSheet, SpreadSheet } from '@/sheet-type'; +import dataCfg from 'tests/data/simple-data.json'; +import { getContainer } from 'tests/util/helpers'; +import type { CornerCell } from '@/cell/corner-cell'; import { CellTypes, - type CustomSVGIcon, - getIcon, InterceptType, KEY_GROUP_PANEL_SCROLL, - type RowCellCollapseTreeRowsType, - type S2DataConfig, S2Event, - type S2Options, - type TooltipShowOptions, TOOLTIP_CONTAINER_CLS, + getIcon, setLang, + type CustomSVGIcon, type LangType, + type RowCellCollapseTreeRowsType, + type S2DataConfig, + type S2Options, + type TooltipShowOptions, } from '@/common'; import { Node } from '@/facet/layout/node'; -import { customMerge, getSafetyDataConfig } from '@/utils'; +import { PivotSheet, SpreadSheet } from '@/sheet-type'; import { BaseTooltip } from '@/ui/tooltip'; -import type { CornerCell } from '@/cell/corner-cell'; +import { customMerge, getSafetyDataConfig } from '@/utils'; jest.mock('@/utils/hide-columns'); @@ -888,7 +888,7 @@ describe('PivotSheet Tests', () => { }); // https://github.com/antvis/S2/issues/1421 - test.each(['zh_CN', 'en_US', 'ru'])( + test.each(['zh_CN', 'en_US', 'ru_RU'])( 'should render group sort menu', (lang: LangType) => { setLang(lang); @@ -906,7 +906,7 @@ describe('PivotSheet Tests', () => { sheet.handleGroupSort(event, null); const isEnUS = lang === 'en_US'; - const isRu = lang === 'ru'; + const isRu = lang === 'ru_RU'; let groupAscText = '组内升序'; let groupDescText = '组内降序'; diff --git a/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts b/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts index b35cec75aa..baf3c7e1fd 100644 --- a/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts +++ b/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts @@ -1,9 +1,9 @@ -import { getContainer } from 'tests/util/helpers'; import type { Event as GEvent } from '@antv/g-canvas'; import * as dataCfg from 'tests/data/simple-table-data.json'; -import { TableSheet } from '@/sheet-type'; +import { getContainer } from 'tests/util/helpers'; import { S2Event, setLang, type LangType, type S2Options } from '@/common'; import { Node } from '@/facet/layout/node'; +import { TableSheet } from '@/sheet-type'; describe('TableSheet Tests', () => { let s2: TableSheet; @@ -161,7 +161,7 @@ describe('TableSheet Tests', () => { }); // https://github.com/antvis/S2/issues/1421 - test.each(['zh_CN', 'en_US', 'ru'])( + test.each(['zh_CN', 'en_US', 'ru_RU'])( 'should render group sort menu', (lang: LangType) => { setLang(lang); @@ -180,7 +180,7 @@ describe('TableSheet Tests', () => { sheet.handleGroupSort(event, null); const isEnUS = lang === 'en_US'; - const isRu = lang === 'ru'; + const isRu = lang === 'ru_RU'; let groupAscText = '升序'; let groupDescText = '降序'; diff --git a/packages/s2-core/src/common/i18n/index.ts b/packages/s2-core/src/common/i18n/index.ts index 43fba501f2..096c2b26f1 100644 --- a/packages/s2-core/src/common/i18n/index.ts +++ b/packages/s2-core/src/common/i18n/index.ts @@ -1,11 +1,11 @@ import { get, merge } from 'lodash'; -import { ZH_CN as BASE_ZH_CN } from './zh_CN'; import { EN_US as BASE_EN_US } from './en_US'; -import { RU as BASE_RU } from './ru'; +import { RU as BASE_RU } from './ru_RU'; +import { ZH_CN as BASE_ZH_CN } from './zh_CN'; const DEFAULT_LANG: LangType = 'zh_CN'; -export type LangType = 'zh_CN' | 'en_US' | 'ru'; +export type LangType = 'zh_CN' | 'en_US' | 'ru_RU'; export type LocaleType = { [K in LangType]: Record; @@ -16,7 +16,7 @@ let lang: LangType = DEFAULT_LANG; let locale: LocaleType = { zh_CN: BASE_ZH_CN, en_US: BASE_EN_US, - ru: BASE_RU, + ru_RU: BASE_RU, }; export const getLang = () => lang; diff --git a/packages/s2-core/src/common/i18n/ru.ts b/packages/s2-core/src/common/i18n/ru_RU.ts similarity index 100% rename from packages/s2-core/src/common/i18n/ru.ts rename to packages/s2-core/src/common/i18n/ru_RU.ts diff --git a/packages/s2-core/src/utils/formatter.ts b/packages/s2-core/src/utils/formatter.ts index 83d44ac414..f882c302cb 100644 --- a/packages/s2-core/src/utils/formatter.ts +++ b/packages/s2-core/src/utils/formatter.ts @@ -1,12 +1,16 @@ import { isNaN, toNumber } from 'lodash'; import { PRECISION } from '../common/constant'; -import { getLang } from '../common/i18n'; +import { getLang, type LangType } from '../common/i18n'; -const FORMATTERS = { +const FORMATTERS: { [K in LangType]: [string[], number[]] } = { en_US: ['KMBTP'.split(''), [1e3, 1e3, 1e3, 1e3, 1e3]], + ru_RU: [ + ['тысяча', 'миллион', 'миллиард', 'триллион', 'квадриллион'], + [1e3, 1e3, 1e3, 1e3, 1e3], + ], zh_CN: [ ['万', '亿'], - [10000, 1e4], + [1e4, 1e4], ], }; diff --git a/packages/s2-react/src/components/sheets/index.tsx b/packages/s2-react/src/components/sheets/index.tsx index 289a7789f8..826eebbff8 100644 --- a/packages/s2-react/src/components/sheets/index.tsx +++ b/packages/s2-react/src/components/sheets/index.tsx @@ -1,9 +1,10 @@ import type { SpreadSheet } from '@antv/s2'; -import React from 'react'; -import zhCN from 'antd/es/locale/zh_CN'; -import enUS from 'antd/es/locale/en_US'; import { getLang } from '@antv/s2'; import { ConfigProvider } from 'antd'; +import enUS from 'antd/es/locale/en_US'; +import ruRU from 'antd/es/locale/ru_RU'; +import zhCN from 'antd/es/locale/zh_CN'; +import React from 'react'; import { EditableSheet } from './editable-sheet'; import { GridAnalysisSheet } from './grid-analysis-sheet'; import type { SheetComponentsProps } from './interface'; @@ -42,7 +43,9 @@ const Sheet = React.forwardRef( } }, [sheetType, sheetProps]); - const locale = getLang() === 'zh_CN' ? zhCN : enUS; + const lang = getLang(); + // eslint-disable-next-line no-nested-ternary + const locale = lang === 'zh_CN' ? zhCN : lang === 'ru_RU' ? ruRU : enUS; return ( diff --git a/packages/s2-shared/src/constant/i18n/index.ts b/packages/s2-shared/src/constant/i18n/index.ts index b9961439f5..5ad2364fba 100644 --- a/packages/s2-shared/src/constant/i18n/index.ts +++ b/packages/s2-shared/src/constant/i18n/index.ts @@ -1,10 +1,10 @@ import type { LocaleType } from '@antv/s2'; import { EN_US } from './en_US'; +import { RU } from './ru_RU'; import { ZH_CN } from './zh_CN'; -import { RU } from './ru'; export const Locale: LocaleType = { zh_CN: ZH_CN, en_US: EN_US, - ru: RU, + ru_RU: RU, }; diff --git a/packages/s2-shared/src/constant/i18n/ru.ts b/packages/s2-shared/src/constant/i18n/ru_RU.ts similarity index 100% rename from packages/s2-shared/src/constant/i18n/ru.ts rename to packages/s2-shared/src/constant/i18n/ru_RU.ts diff --git a/s2-site/docs/manual/basic/i18n.en.md b/s2-site/docs/manual/basic/i18n.en.md index 2e51e363c5..0c1e3e6809 100644 --- a/s2-site/docs/manual/basic/i18n.en.md +++ b/s2-site/docs/manual/basic/i18n.en.md @@ -19,7 +19,7 @@ import { setLang, PivotSheet } from '@antv/s2' setLang('en_US') // setLang('zh_CN') -// setLang('ru'); +// setLang('ru_RU'); const s2 = new PivotSheet() s2.render() @@ -39,7 +39,7 @@ const locale = { en_US: { test: 'test', }, - ru: { + ru_RU: { test: 'тест', }, }; diff --git a/s2-site/docs/manual/basic/i18n.zh.md b/s2-site/docs/manual/basic/i18n.zh.md index 23ead6051b..f6f3694d89 100644 --- a/s2-site/docs/manual/basic/i18n.zh.md +++ b/s2-site/docs/manual/basic/i18n.zh.md @@ -14,6 +14,7 @@ import { setLang, PivotSheet } from '@antv/s2' setLang('en_US') // setLang('zh_CN') +// setLang('ru_RU'); const s2 = new PivotSheet() s2.render() @@ -33,6 +34,9 @@ const locale = { en_US: { test: 'test', }, + ru_RU: { + test: 'тест', + }, }; extendLocale(locale)