-
-
Notifications
You must be signed in to change notification settings - Fork 650
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(numfmt): currency shortcuts support internationalization #3062
Conversation
f75d138
to
0b58ec0
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #3062 +/- ##
==========================================
- Coverage 27.44% 27.44% -0.01%
==========================================
Files 1980 1980
Lines 104889 104907 +18
Branches 22643 22647 +4
==========================================
+ Hits 28787 28788 +1
- Misses 76102 76119 +17 ☔ View full report in Codecov by Sentry. |
View Deployment
|
[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: '€', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it normal that two-letters country codes are mixed with full locale strings like en-US
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, currency types are represented using language codes instead of coutry codes (You can find specific language codes in the file located at packages/core/src/types/enum/locale-type.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and that's a problem, because the currency depends on the country, but not on the language
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to work for euros ?
Or will we have to wait until univer is translated into every european language ?
I liked using the browser's current regional settings, because it allowed this to work with languages univer is not (and will never be) translated into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no, no. The European region is also a future direction for our services. It's just that we currently don't have enough manpower to support this work. Most of the internationalization resources in the project are provided by the community, and we are very grateful for their help.
Can we try adding an enumeration of LocaleType euro, but translate the text in English (Wait for the open source community to provide the corresponding language copywriting)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to implement this button in the toolbar by yourself, you can try overriding this menu configuration.
After loading the numfmt-plugin, you can reset the CurrencyMenuItem by calling the setMenuItem method in menu.service.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, there are many many different languages in the "euro region". What would an euro locale contain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you don't want to decouple supported languages from supported currencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
【there are many many different languages in the "euro region"】Could there be multiple languages for the same currency? That means that our localType enumerations may be excessive.
Please give me a little more time to discuss it internally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, I would like the default currency displayed to SQLPage users to be the currency of the place they are in, even if the rest of the UI is in English.
Could there be multiple languages for the same currency?
Yes. There are 20 countries in the euro zone, speaking 19 different languages. Some of these languages have <1M locutors. I can speak only one of these 19 languages (french). I understand you have grand ambitions, but univerjs will probably not be translated in all of these languages anytime soon. It would be great if we could still have the € sign by default...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I think providing an API to set a custom currency symbol is a great solution. It allows you to set the currency symbol independently of the platform language and Univer
own language settings. When integrating with Univer
, you can use the API to set the currency symbol, regardless of how you obtain the system language or coutry code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a misunderstanding. I don't need an api to set the default currency symbol, I would like the default symbol to automatically reflect the users preference, wherever they are. That's what my initial pull request did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
We will provide an API for setting the currency symbol, and you can write some code to call it. For example, you can use the browser's user-agent to recognize the country code and set the corresponding symbol.
-
We will add a country code identifier to the snapshot upon creation. If not set, it will default to the mapped value of that country code and will not follow the language settings.
-
Later, we will provide a StackBlitz code to guide you through the implementation.😊
There are some blocking bugs that need to be resolved, and we expect to provide them to you by next week.
😊
0b58ec0
to
bd100dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me. But there are some code quality issues.
@@ -29,6 +31,8 @@ export const DefaultSheetNumfmtConfig = {}; | |||
|
|||
@OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController) | |||
export class NumfmtMenuController extends Disposable { | |||
private _currencySymbol$ = new BehaviorSubject<keyof typeof currencyMap>('ZH_CN'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to infer the default currency symbol for the browser's navgiator
info whenever possible. Since this property is at UI layer, it is considered as harmless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It it recommended to make property readonly
whenever possible.
@@ -29,6 +31,8 @@ export const DefaultSheetNumfmtConfig = {}; | |||
|
|||
@OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController) | |||
export class NumfmtMenuController extends Disposable { | |||
private _currencySymbol$ = new BehaviorSubject<keyof typeof currencyMap>('ZH_CN'); | |||
public currencySymbol$ = this._currencySymbol$.asObservable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line before constructors to make the code clear to read.
@@ -50,4 +54,12 @@ export class NumfmtMenuController extends Disposable { | |||
this.disposeWithMe((this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType))); | |||
this.disposeWithMe((this._componentManager.register(OPTIONS_KEY, Options))); | |||
} | |||
|
|||
public setCurrencySymbol(symbol: keyof typeof currencyMap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSDoc is expected to be required on this method if it is intended to be used directly by users. And a relate change on the Facade API is required.
bd100dd
to
e156571
Compare
After the Univer instance is created, execute the following code: import { NumfmtMenuController, NumfmtMenuController } from '@univerjs/sheets-numfmt';
import { LifecycleService, LifecycleStages } from '@univerjs/core';
const univer = new Univer();
univer.registerPlugin(UniverSheetsNumfmtPlugin);
setCurrencySymbol()
function setCurrencySymbol() {
const injector = univer.__getInjector();
const lifecycleService = injector.get(LifecycleService);
function calculateYourCurrencySymbol() {
function getRegionCode(): string {
// Get the user's locale
const userLocale: string = navigator.language || (navigator as any).userLanguage;
const regionCode: string = userLocale.split('-')[1] || userLocale.split('-')[0];
// Return the corresponding currency symbol or default to USD
return regionCode;
}
const numfmtMenuController = injector.get(NumfmtMenuController);
// If it is not legal, it will be used ‘$’ by default
numfmtMenuController.setCurrencySymbol(getRegionCode());
}
const dispose = lifecycleService.lifecycle$.subscribe((stage) => {
if (LifecycleStages.Rendered === stage) {
calculateYourCurrencySymbol();
dispose.unsubscribe();
}
});
} |
6977f13
to
590e272
Compare
590e272
to
4d594f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please add an example or some documentation on univer.ai to demonstrate how this works. @Gggpound
close #1803
This time supports quick keys for USD, RMB, and EUR. Other currencies will be added after internationalization.
Pull Request Checklist