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

extend locale lazy-loading #1797

Closed
2 of 4 tasks
kazupon opened this issue Jan 16, 2023 · 8 comments · Fixed by #1801
Closed
2 of 4 tasks

extend locale lazy-loading #1797

kazupon opened this issue Jan 16, 2023 · 8 comments · Fixed by #1801
Labels

Comments

@kazupon
Copy link
Collaborator

kazupon commented Jan 16, 2023

Describe the feature

describe

Currently, lazy-loading loads the locale messages specified in the i18n.locales file.

BCP47 supports language tags such as language - script - region - variant - extension - privateuse.
https://en.wikipedia.org/wiki/IETF_language_tag

If you define locale messages as resources in a file according to that specification, there is a possibility of duplication.
For example, en-US and en-GB have the same language, just different regions.
In that case, most resources would be the same.

For convenience in managing resources for locale messages, it would be useful to have a mechanism to define resources only for the difference of region and variant and to be able to load them lazily.

usecase projects

elk-zone/elk#1172

more details for this feature request

https://discord.com/channels/1044887051155292200/1045783579520684062/1063952424764719154

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

@kazupon kazupon added the v8 label Jan 16, 2023 — with Volta.net
@kazupon kazupon changed the title extending locale lazy-loading extend locale lazy-loading Jan 16, 2023
kazupon added a commit that referenced this issue Jan 19, 2023
@kazupon kazupon mentioned this issue Jan 19, 2023
7 tasks
kazupon added a commit that referenced this issue Jan 19, 2023
@userquin
Copy link
Collaborator

userquin commented Jan 19, 2023

The main problem is the locale (we need it, we cannot use a generic locale), I mean, the html lang tag and Intl usage, just a few examples:

  • in Colombia datetime format is AM/PM, in Spain we use HH24
  • First day of week in Argentina is Sunday while in Spain it is Monday
  • arabic languages: we cannot use ar, we lost numbers

About messages duplication: favorite and favourites for en-US and en-GB respectivelly.

Copy link
Collaborator Author

kazupon commented Jan 20, 2023

in Colombia datetime format is AM/PM, in Spain we use HH24
First day of week in Argentina is Sunday while in Spain it is Monday

I think we can configure those to vueI18n.datetimeFormats. does this mean we want to lazily load datetimeForamts as well as locale messages?

arabic languages: we cannot use ar, we lost numbers

for arabic, sorry, I’m not familiar with that language. sorry, could you please give me some more detail explanation? 🙏

@userquin
Copy link
Collaborator

userquin commented Jan 20, 2023

My previous comment was just to justify the PR.

Just check i18n module https://github.com/elk-zone/elk/blob/main/config/i18n.ts: rn we're using only es-ES for all spanish variants, and that's wrong, for example we're using datetimes and ppl using Elk from countries using AM/PM will end up with HH24.

About arabic, check the script we've in Elk contributing.md file, if we use ar for generic arabic (that's why we're using ar-EG), Intl will use latin numbers, and so arabic numbers will never be used.

@userquin
Copy link
Collaborator

[1, 12, 123, 1234, 12345, 123456, 1234567].forEach((n) => {
  const acc = {}

  Array.from(['ar-EG', 'ar']).forEach((l) => {
    const nf = new Intl.NumberFormat(l, {
      style: 'decimal',
      maximumFractionDigits: 0,
    })
    const nf2 = new Intl.NumberFormat(l, {
      notation: 'compact',
      compactDisplay: 'short',
      maximumFractionDigits: 1,
    })
    acc[l] = {
      number: n,
      format: nf.format(n),
      compact: nf2.format(n),
    }
  })
  console.table(acc)
})

Copy link
Collaborator Author

kazupon commented Jan 21, 2023

Thanks! I appreciate your kindful explanation.

I’m working at #1801.
Could that PR meet your expectations?

@userquin
Copy link
Collaborator

Could that PR meet your expectations?

The only thing I need confirmation is that a module is generated per language with the overwritten messages: for Spanish surely there will not be too many messages to overwrite, but for other languages (Arabic) surely yes

Copy link
Collaborator Author

kazupon commented Jan 21, 2023

I need confirmation is that a module is generated per language with the overwritten messages

In That PR, it's generated by the bundler (vite) for per language.
I will merge the PR and release beta.8
when you would try that version, if you need any more support, you would give me feedback!

kazupon added a commit that referenced this issue Jan 21, 2023
* feat: extend lazy loading

resolve #1797

* feat: extend lazy loading

resolve #1797

* update nuxt module

* update playground

* remove settings

* add docs

* update docs

* update docs

* update testing

* docs: tweak
@userquin
Copy link
Collaborator

I will merge the PR and release beta.8

Thx man: we've also some problems with i18n module and ts types overriden #1711 (should also be included in the new beta 8?)

DarthGigi pushed a commit to DarthGigi/i18n that referenced this issue Apr 16, 2024
* feat: extend lazy loading

resolve nuxt-modules#1797

* feat: extend lazy loading

resolve nuxt-modules#1797

* update nuxt module

* update playground

* remove settings

* add docs

* update docs

* update docs

* update testing

* docs: tweak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants