dayjs 与 i18next 设置区域设置不起作用
我使用 dayjs,我想用 i18next.language 的当前语言更改语言环境
,但它不起作用,我只得到英语格式。
...
import dayjs from 'dayjs';
const { t, i18n } = useTranslation();
dayjs.locale(i18n.language);
...
I use dayjs, and I want to change the locale with the current languages of i18next.language
but its not working, I get only the english format.
...
import dayjs from 'dayjs';
const { t, i18n } = useTranslation();
dayjs.locale(i18n.language);
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还应该导入所需的区域设置。它不会起作用,除非:
You should also import the required locale. It won't work unless:
尝试使用 i18next.resolvedLanguage
像这样:
顺便说一句:这可能是你太早访问 i18n,或者尝试检查 就绪标志:
或者订阅 语言更改事件(在您启动 i18next 的地方):
Try to use i18next.resolvedLanguage
Something like this:
btw: it might be you're accessing i18n too early, alternatively try to check the ready flag:
or alternatively subscribe to the language changed event (somewhere where you init i18next):
从“ dayjs/locale/it it”中导入它
,然后像这样使用
import it from 'dayjs/locale/it' like so
And use it like so
Next-Intl当前具有用于客户端渲染的Hook Uselocale()。
请确保从Dayjs拳头以及组件的顶部进口各个地方。
Next-Intl currently has the hook useLocale() for client-side rendering.
Be sure to import the locales from dayjs fist as well at the top of the component.