Can I fallback translations if message is missing for a language? #1061
LarsFlieger
started this conversation in
General
Replies: 2 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.
1 reply
-
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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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