Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(i18n): add formatter support of the russian language #2862

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/s2-core/__tests__/unit/common/i18n/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('(СУММА)');
Expand Down
26 changes: 13 additions & 13 deletions packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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);
Expand All @@ -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 = '组内降序';
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 = '降序';
Expand Down
8 changes: 4 additions & 4 deletions packages/s2-core/src/common/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>;
Expand All @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions packages/s2-core/src/utils/formatter.ts
Original file line number Diff line number Diff line change
@@ -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],
],
};

Expand Down
11 changes: 7 additions & 4 deletions packages/s2-react/src/components/sheets/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
<React.StrictMode>
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-shared/src/constant/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -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,
};
4 changes: 2 additions & 2 deletions s2-site/docs/manual/basic/i18n.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -39,7 +39,7 @@ const locale = {
en_US: {
test: 'test',
},
ru: {
ru_RU: {
test: 'тест',
},
};
Expand Down
4 changes: 4 additions & 0 deletions s2-site/docs/manual/basic/i18n.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -33,6 +34,9 @@ const locale = {
en_US: {
test: 'test',
},
ru_RU: {
test: 'тест',
},
};

extendLocale(locale)
Expand Down
Loading