-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
Plural hydration error #528
Comments
When I used the normal interpolation method So, to solve this issue in this ticket, I found a workaround after digging into the source code that surprisingly worked. Instead of writing it like that: {
"key": "{variable, plural, =1 {# Unit} other {# Units}}"
} Try this: {
"key": "{variable, plural, =1 {{variable} Unit} other {{variable} Units}}"
} By doing that the library won't see any I don't know if this was intended or not, and if it was intended then maybe we can add that to the documentation somewhere because it was not obvious to me at first glance. I also would like to note that it would be perfect if there was a way to prevent the default formatting done by the library to the interpolated numbers by default. I know we have control on how the library formats the numbers, but we don't have control on whether it should be formatted or not. |
This looks like an environment inconsistency to me. It seems like there are more specific locales for I'm personally not that familiar with this topic, but generally the bug seems to occur due to different treatment of the Maybe @A7med3bdulBaset is familiar with this? See also: formatjs/formatjs#4004 |
As it turns out, FormatJS actually does what I did in the previous comment in the docs if formatting was not wanted and the
I had my doubts that it's being formatted differently on different machines because I faced this issue before in a different situation but it was mixed up! Then this issue can be because of one of two reasons: So, when a locale is presented to the Intl API it matches it to the locale list using different algorithms and the locale string itself that was passed only has the language and no script subtag or region (basically it has none of the optional parameters), so the So, if I need proper formatting that matches on different machines I'll need to laser focus my |
Based on the screenshot, it seems like the This works in Chrome too: new Intl.NumberFormat('ar', {numberingSystem: 'arab'}).format(123) // '١٢٣' |
Yeah, I guess we'll have to override the default Intl config then to do this. Does the library have a localization solution?? If there's a solution for that it might be a better approach because the library itself will be passing the correct locale to FormatJS instead of having to override the locale defaults because it's not only about the So, Does this feature exist? Should I close this ticket and open a Feature request regarding the localization? |
I understand!
You can absolutely load the same messages for different locales! (see also the messages config section) |
Yes, I think this should resolve it 👍🏼
I can make here different locales and then |
I encountered this as well. there are several conflicts between different browsers and node.js behavior in setting the fallback of the numbering system in Arabic. This issue is that the server-rendered html follows the server runtime behavior of either As a solution, You can set the global formatting config in both import { type IntlConfig } from "next-intl";
import { getRequestConfig } from "next-intl/server";
export default getRequestConfig(async ({ locale }) => ({
messages: (await import(`./translations/${locale}.json`)).default,
timeZone: "Asia/Riyadh",
formats: getGlobalFormatOptions(locale),
}));
export function getGlobalFormatOptions(
locale: Locale
): IntlConfig["formats"] {
return {
dateTime: {
date: {
// ...
numberingSystem: locale === "ar" ? "arab" : "latn",
}
},
number: {
currency: {
// ...
numberingSystem: locale === "ar" ? "arab" : "latn",
},
},
};
} |
@A7med3bdulBaset Won't passing Because as mentioned above, it's not only about |
I can confirm passing the region along with the language in my locale string like " |
As a side note, custom prefixes are coming to This might be useful in the case discussed in this thread since you can append a numbering system to your locale without having to show it to the user in the URL. Example: import {LocalePrefix} from 'next-intl/routing';
// Explicitly use the arab numbering system
export const locales = ['ar-u-nu-arab', /* ... */] as const;
export const localePrefix = {
mode: 'always',
prefixes: {
'ar-u-nu-arab': '/ar',
// ...
}
} satisfies LocalePrefix<typeof locales>; See also: new Intl.Locale('ar', {numberingSystem: 'arab'}).toString() // "ar-u-nu-arab" |
Description
When using the pluralization feature, all the numbers injected are formatted by default to the current locale.
The problem here is that for some reason this happens on the server only, so when it runs on the client it doesn't format the numbers which results in a hydration error for the mismatch between the Arabic digits rendered on the server, and the English digits rendered on the client.
Mandatory reproduction URL (CodeSandbox or GitHub repository)
https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-hyncfy?file=%2Fsrc%2Fmiddleware.ts%3A4%2C25
Reproduction description
Steps to reproduce:
/ar
in the URL barExpected behaviour
Server and Client match the same number format.
The text was updated successfully, but these errors were encountered: