Replies: 7 comments 12 replies
-
Hey @ivandotv, you haven't activated your default locale. You need to call That's why the error says |
Beta Was this translation helpful? Give feedback.
-
I still can't get this to work. How are those values read from the config?
|
Beta Was this translation helpful? Give feedback.
-
Any news on this one? I do geht the same error unfortunately. Also with next.js. |
Beta Was this translation helpful? Give feedback.
-
I do have still the same issue. I always get the same error message on the first reload of the page. I can't find any difference to the official https://github.com/vercel/next.js/tree/canary/examples/with-lingui |
Beta Was this translation helpful? Give feedback.
-
I am using Next.js and I have the same problem. import * as React from "react";
import { I18nProvider } from "@lingui/react";
import { i18n } from "@lingui/core";
import { useRouter } from "next/router";
import { en, ru, zh } from "make-plural/plurals";
import { t } from "@lingui/macro";
import { AllLocaleData, AllMessages } from "@lingui/core";
import messagesRu from "locales/ru/messages";
import messagesEn from "locales/en/messages";
import messagesZh from "locales/zh-CN/messages";
export const messages: AllMessages = {
en: messagesEn.messages,
ru: messagesRu.messages,
"zh-CN": messagesZh.messages,
};
export const plurals: AllLocaleData = {
en: { plurals: en },
ru: { plurals: ru },
"zh-CN": { plurals: zh },
};
export const defaultLocale = "en";
const LanguageProvider: React.FC = ({ children }) => {
const { locale } = useRouter();
// once before render load all i18n catalogs and plurals, this is run on the client only
React.useState(() => {
i18n.loadLocaleData(plurals);
i18n.load(messages);
i18n.activate(typeof locale === "undefined" ? defaultLocale : locale);
});
React.useEffect(() => {
if (i18n.locale === locale) return;
i18n.activate(typeof locale === "undefined" ? defaultLocale : locale);
}, [locale]);
return React.createElement(I18nProvider, { i18n }, children);
};
export default LanguageProvider; |
Beta Was this translation helpful? Give feedback.
-
This is caused by Since the only sane approach is loading the messages asynchronously to prevent loading all locales upfront, there is a high chance the app is already rendering before lingui is properly set up. I managed to solve this issue for my project by not loading the initial locale from within the react code in a side effect, since this causes aforementioned race condition. Load your default (or previously set locale, wherever you happen to store that state) before you even first render the app. Here is an example: activateLocale(defaultLocale).then(() => {
ReactDOM.render(
<App />,
rootEl
);
}); I'm not yet into SSR, maybe someone can find a similar fix for those cases? For improved perceived loading times, it would be great if Maybe a better approach can be achieved by wrapping |
Beta Was this translation helpful? Give feedback.
-
In my particular situation it was because I had multiple versions of @lingui/core installed and making sure all version match solved the issue. |
Beta Was this translation helpful? Give feedback.
-
Currently, I'm trying to make Lingui work with Next.js server-side rendering, I'm concerned with the
i18n
singleton, so I've tried to usesetupI18n()
, which compiles but I get a runtime error:This is my file structure:
I have tried using
But it has no effect?
How is
runtimeConfigModule
supposed to work? How it resolves theimport
from 'initTranslations` in different nested files?my directory structure is this:
This is the component where the error occurs:
Beta Was this translation helpful? Give feedback.
All reactions