Can I fallback translations if message is missing for a language? #1061
Replies: 3 comments 1 reply
-
Sure, please see here: https://next-intl-docs.vercel.app/docs/usage/configuration#messages-fallback |
Beta Was this translation helpful? Give feedback.
-
I implemented that feature by using the custom hook, maybe it will be useful for someone too import { useTranslations as useIntlTranslations } from "next-intl";
import defaultMessages from "@/i18n/locales/en.json";
function getNestedValue(obj, path) {
return path.split(".").reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : undefined), obj);
}
export function useTranslations() {
const t = useIntlTranslations();
return (namespace) => {
const translated = t(namespace);
return translated !== namespace ? translated : getNestedValue(defaultMessages, namespace) || namespace;
};
} Hoever, it doesn't solve the |
Beta Was this translation helpful? Give feedback.
-
Same issue here — using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a
en.json
with:and a
de.json
with this:Age is missing in
de.json
so I get:How can I make that it fallbacks to en (my default language). Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions