Skip to content

Commit

Permalink
feat(numfmt): currency shortcuts support internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Gggpound committed Aug 14, 2024
1 parent 2559483 commit 0b58ec0
Show file tree
Hide file tree
Showing 35 changed files with 990 additions and 109 deletions.
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@univerjs/engine-render": "workspace:*",
"@univerjs/facade": "workspace:*",
"@univerjs/find-replace": "workspace:*",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-docs-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-formula-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/rpc": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-formula/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@univerjs/core": "workspace:*"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-sheets-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-slides-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"react": "^16.9.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uniui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"dependencies": {
"@floating-ui/react-dom": "^2.1.1",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@xyflow/react": "^12.0.4",
"rc-util": "^5.43.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@rc-component/color-picker": "^2.0.1",
"@rc-component/trigger": "^2.2.1",
"@types/react-mentions": "^4.1.13",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"rc-dialog": "^9.5.2",
"rc-dropdown": "^4.2.0",
"rc-input": "^1.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-drawing-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-hyper-link-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-thread-comment-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/drawing-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/drawing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"ot-json1": "^1.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/find-replace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/sheets-conditional-formatting-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/protocol": "0.1.39-alpha.3",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
Expand All @@ -94,7 +94,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons-svg": "^0.1.72",
"@univerjs/icons-svg": "^0.1.74",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-conditional-formatting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons-svg": "^0.1.72",
"@univerjs/icons-svg": "^0.1.74",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
"dayjs": "^1.11.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/protocol": "0.1.39-alpha.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-drawing-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-filter-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"rc-virtual-list": "^3.14.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-formula/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-hyper-link-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/sheets-hyper-link": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-numfmt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
20 changes: 20 additions & 0 deletions packages/sheets-numfmt/src/base/const/CURRENCY-SYMBOLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import { LocaleType } from '@univerjs/core';

export const currencySymbols = [
'$',
'£',
Expand Down Expand Up @@ -43,3 +45,21 @@ export const currencySymbols = [
'₾',
'₿',
];

export const currencyMap: Record<string, string> = {
[LocaleType.EN_US]: '$', // United States Dollar
CA: 'C$', // Canadian Dollar
GB: '£', // British Pound Sterling
JP: '¥', // Japanese Yen
IN: '₹', // Indian Rupee
AU: 'A$', // Australian Dollar
[LocaleType.ZH_CN]: '¥', // Chinese Yuan
[LocaleType.ZH_TW]: '¥', // Chinese Yuan
KR: '₩', // South Korean Won
[LocaleType.RU_RU]: '₽', // Russian Ruble
// Euro countries
AT: '€', BE: '€', CY: '€', EE: '€', FI: '€', FR: '€',
DE: '€', GR: '€', IE: '€', IT: '€', LV: '€', LT: '€',
LU: '€', MT: '€', NL: '€', PT: '€', SK: '€', SI: '€', ES: '€',
// Add more mappings as needed
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/

import type { IAccessor, ICommand } from '@univerjs/core';
import { CommandType, ICommandService, Range } from '@univerjs/core';
import { CommandType, ICommandService, LocaleService, Range } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';

import { CURRENCYFORMAT } from '../../base/const/FORMATDETAIL';
import { currencyMap } from '../../base/const/CURRENCY-SYMBOLS';
import type { ISetNumfmtCommandParams } from './set-numfmt.command';
import { SetNumfmtCommand } from './set-numfmt.command';

Expand All @@ -28,14 +29,17 @@ export const SetCurrencyCommand: ICommand = {
handler: async (accessor: IAccessor) => {
const commandService = accessor.get(ICommandService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const localeService = accessor.get(LocaleService);
const locale = localeService.getCurrentLocale();

const symbol = currencyMap[locale] || '$';
const selections = selectionManagerService.getCurrentSelections();
if (!selections || !selections.length) {
return false;
}
const values: ISetNumfmtCommandParams['values'] = [];

const suffix = CURRENCYFORMAT[0].suffix('¥');
const suffix = CURRENCYFORMAT[0].suffix(symbol);

selections.forEach((selection) => {
Range.foreach(selection.range, (row, col) => {
Expand Down
20 changes: 18 additions & 2 deletions packages/sheets-numfmt/src/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { ICommandService, IUniverInstanceService, LocaleService, LocaleType, UniverInstanceType } from '@univerjs/core';
import {
INumfmtService,
RangeProtectionPermissionEditPoint,
Expand Down Expand Up @@ -42,7 +42,23 @@ import { SetPercentCommand } from '../commands/commands/set-percent.command';

export const CurrencyMenuItem = (accessor: IAccessor) => {
return {
icon: 'RmbSingle',
icon: new Observable<string>((subscribe) => {
const localeService = accessor.get(LocaleService);
function getIconKey() {
const local = localeService.getCurrentLocale();
const iconMap: Record<string, string> = {
[LocaleType.EN_US]: 'DollarSingle',
[LocaleType.RU_RU]: 'RoubleSingle',
[LocaleType.ZH_CN]: 'RmbSingle',
[LocaleType.ZH_TW]: 'RmbSingle',
};
return iconMap[local] || 'DollarSingle';
}
subscribe.next(getIconKey());
return localeService.localeChanged$.subscribe(() => {
subscribe.next(getIconKey());
});
}),
id: SetCurrencyCommand.id,
title: 'sheet.numfmt.currency',
tooltip: 'sheet.numfmt.currency',
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-sort-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"rc-virtual-list": "^3.14.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-thread-comment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/protocol": "0.1.39-alpha.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-zen-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/sheets": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/slides-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/thread-comment-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/protocol": "0.1.39-alpha.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"localforage": "^1.10.0",
"rc-notification": "^5.6.0",
"rc-util": "^5.43.0"
Expand Down
Loading

0 comments on commit 0b58ec0

Please sign in to comment.