Open kb-0912 opened 8 months ago
I encountered the same thing. For some reason, that translations
object in loadTranslation
util doesn't load in order, returning undefined
instead of the corresponding loader function.
To solve this you need to check if the loader is undefined
, if so, return the default loader function:
// /path/to/loadTranslation.ts
export default async function loadTranslation(
locale: Locale
): Promise<Translation> {
// Invoke a call to translations corresponding to a given locale key.
if (translations[locale]) {
return translations[locale]();
}
return import("@/translations/ar.json").then((module) => module.default);
}
Instead of:
export default async function loadTranslation(
locale: Locale
): Promise<Translation> {
// Invoke a call to translations corresponding to a given locale key.
return translations[locale]();
}
Let me know if this helps.
@kb-0912 Hi, did that work for you? if yes, you may mark this issue as closed.
@kb-0912 Hi, did that work for you? if yes, you may mark this issue as closed.
Hi, with your suggestion it always return default locale
@kb-0912 Hi, did that work for you? if yes, you may mark this issue as closed.
Hi, with your suggestion it always return default locale
I've raised a pr on this repo, could u try pulling it and let me know afterwards? I wrote the exact code to be added/modified there.
Hi, @kb-0912 and @ObaidQatan! Sorry it has taken me so long to respond to your messages! I wanted to let you know that I am going to update this project up to date with Next.js 14 very soon. This should fix most of the bugs and simplify the code.
Cheers!
I came across the issue in Next.js 14, in case the issue persisted in your case even after the update, you may consider this pr.
@kb-0912 Hi, did that work for you? if yes, you may mark this issue as closed.
Hi, with your suggestion it always return default locale
I've raised a pr on this repo, could u try pulling it and let me know afterwards? I wrote the exact code to be added/modified there.
Thank you let me check
Hi, @kb-0912 and @ObaidQatan! Sorry it has taken me so long to respond to your messages! I wanted to let you know that I am going to update this project up to date with Next.js 14 very soon. This should fix most of the bugs and simplify the code.
Cheers!
Thanks for your reply. May I know the expected date?
Can you help me explain why?