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

Default currency symbol as setting or environment variable #1195

Open
alexfacciorusso opened this issue Dec 28, 2024 · 6 comments
Open

Default currency symbol as setting or environment variable #1195

alexfacciorusso opened this issue Dec 28, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@alexfacciorusso
Copy link

Is your feature request related to a problem? Please describe.
It is frustrating to have to change the currency symbol every time I create a field

Describe the solution you'd like
A field in the settings would be amazing, but if that's too complicated, an environment variable would be appreciated.

@alexfacciorusso
Copy link
Author

This seems relatively simple to implement and I could give it a go

@alexfacciorusso alexfacciorusso changed the title Default currency symbol as Environment Variable or settings Default currency symbol as setting or environment variable Dec 28, 2024
@kpodp0ra
Copy link
Collaborator

I propose saving the user's last selection in cookie/local storage. This way, the currency symbol can be automatically restored based on the user's previous choice, making the experience more seamless.

@tea-artist
Copy link
Contributor

LLM's suggestion is good, so that the appropriate default currency symbol can be automatically selected on the front end.
And contributions are welcome.

Here's how you can get the currency symbol based on the user's locale:

// Get user's locale (e.g., 'en-US', 'de-DE', etc.)
const userLocale = navigator.language;

// Create a number formatter for currency using the user's locale
const formatter = new Intl.NumberFormat(userLocale, {
  style: 'currency',
  currency: 'USD' // You need to specify which currency you want to format
});

// Get the currency symbol
const currencySymbol = formatter.formatToParts(0).find(part => part.type === 'currency').value;
console.log(currencySymbol); // '$' for en-US, '€' for de-DE with EUR, etc.

A few important notes:

  1. The currency symbol shown will be based on both the locale AND the currency code you specify
  2. Some locales might show the currency code (like 'USD') instead of a symbol
  3. The position of the symbol (before or after the number) will also be determined by the locale

You can also get the full formatted currency string:

const price = 42.99;
const formatted = formatter.format(price);
console.log(formatted); // '$42.99' for en-US

This is the recommended way to handle currency display as it respects the user's locale preferences and provides proper formatting for different regions.

@alexfacciorusso
Copy link
Author

It's a fair suggestion although saving it as a cookie is almost thinking as a single-user system. If I set a default currency, I want to set it for all the team/at a space or base level! :)

@alexfacciorusso
Copy link
Author

Maybe the priority table should be:

Base setting > Space setting > User locale > App default currency.

It doesn't have to be implemented altogether as a logic but can be split in steps/tasks, but that's what I believe can benefit the most

@kpodp0ra
Copy link
Collaborator

There is no need for base/space setting for default currency as currency is enforced on field-level. You only need to set currency when you are creating new table and in most use cases this isn't common task.

@kpodp0ra kpodp0ra added the enhancement New feature or request label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants