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

Unify defining number formats for different locales #2054

Open
3 tasks done
MickL opened this issue Dec 21, 2024 · 2 comments
Open
3 tasks done

Unify defining number formats for different locales #2054

MickL opened this issue Dec 21, 2024 · 2 comments
Labels
Status: Proposal Request for comments

Comments

@MickL
Copy link

MickL commented Dec 21, 2024

Clear and concise description of the problem

At the moment number formats need to be defined for every locale, but this results in duplicate code:

numberFormats: {
    de: {
      currency: {
        style: 'currency',
        currency: 'EUR',
      },
    },
    fr: {
      currency: {
        style: 'currency',
        currency: 'EUR',
      },
    },
    es: {
      currency: {
        style: 'currency',
        currency: 'EUR',
      },
    },
  },
  datetimeFormats: {
    de: {
      date: {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
      },
    },
    fr: {
      date: {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
      },
    },
    es: {
      date: {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
      },
    },
  },

This is a simple example but imagine having 27 EU countries and defining multiple date formats and all of them are the same.

Suggested solution

Maybe something like this:

numberFormats: {
    currency: {
      style: 'currency',
      currency: 'EUR',
      locales: ['de', 'fr', 'es'],
    },
  },
  datetimeFormats: {
    date: {
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      locales: ['de', 'fr', 'es'],
    },
  },

Additionally locales could be optional: If not defined it applies to all locales.

Alternative

No response

Additional context

No response

Validations

@razorness
Copy link

A workaround is this:

const datetimeFormats: {
    de: {
      date: {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
      },
    }
};

datetimeFormats['fr'] = datetimeFormats.de;
datetimeFormats['es'] = datetimeFormats.de;

@MickL
Copy link
Author

MickL commented Mar 4, 2025

True! Only downside is it creates duplicate code in the final bundle. Not much but depends on how many formats and languages. Also the compiler complains, in your example that fr and es is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

2 participants