You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is no dateTimeFormats or numberFormats for a given language, the translate methodss use the fallback locale to format the given input.
Expected behavior
The d(new Date(), 'formatName') and n(1234567.89, 'formatName') calls should respect the current locale value and only use of the dateTimeFormat / numberFormat option from the fallback.
I opted to declare en-GB instead of en to avoid ambiguity around the date part order.
Added "Intl test" lines for the playground to show how the date and number are properly formatted with hu-HU locale. These tests use the locale set in vue-i18n but call the Intl methods directly.
Thank you for your feedback!
I've just see the your reproduction.
I have checked at your App.vue, but there are no options specified for useI18n. Therefore, on App.vue, the locale operates in the global scope. In other words, it is hu-HU.
(about locale scope, you can see in there: https://vue-i18n.intlify.dev/guide/essentials/scope.html )
Since hu-HU is empty, en-GB is used for dateTimeFormats and numberFormats.
I have checked at your App.vue, but there are no options specified for useI18n. Therefore, on App.vue, the locale operates in the global scope. In other words, it is hu-HU.
that's exactly what I'd expect: the locale is set to Hungarian and therefore the labels are shown in that language too!
I see now where my expectation and Vue I18n's behaviour differs: while the package handles the situation by using the fallback locale's definition and the locale itself, I expected to only use the format option but keep the current locale 🤔
I could reason why my thinking makes sense, but I also see the implemented approach has benefits, just wasn't necessary obvious when I was reading the documentation!
If I'm mistaken the this forces me to define all datetime and number formats for every language, or to create a mechanism that assigns the missing definitions to every locale when assigning the i18nOptions. I don't think it's a big deal, but certainly creates friction when the format options don't deviate too much.
In any case, it's good to know the behaviour is intended and no further action is needed, thank you for the explanation Kazuya!
Reporting a bug?
When there is no
dateTimeFormats
ornumberFormats
for a given language, the translate methodss use the fallback locale to format the given input.Expected behavior
The
d(new Date(), 'formatName')
andn(1234567.89, 'formatName')
calls should respect the currentlocale
value and only use of the dateTimeFormat / numberFormat option from the fallback.Reproduction
StackBlitz playground: vue-i18n-dn-test
d()
orn()
with the format defined in the fallback locale:<i18n-d>
and<i18n-n>
and do the same:Actual behaviour
30/11/2024
instead of2024. 11. 30.
Ft 1,234,567.89
instead of1 234 567,89 Ft
System Info
Screenshot
Additional context
en-GB
instead ofen
to avoid ambiguity around the date part order.hu-HU
locale. These tests use the locale set invue-i18n
but call the Intl methods directly.Validations
The text was updated successfully, but these errors were encountered: