I can't manage to show nested properties in my application from translation configuration in React application with useTranslation.
This is my i18 configuration:
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
// Config
i18n.use(initReactI18next).init({
resources: {
en: {
translation: {
NESTING_PARENT: {
CHILD: 'Some text'
}
},
},
},
lng: "en",
debug: false,
keySeparator: false,
interpolation: {
escapeValue: false,
formatSeparator: ",",
},
react: {
useSuspense: false,
},
});
// Component
function MyComponent() {
const { t } = useTranslation("translations", { keyPrefix: "NESTING_PARENT" });
return <div>{t("CHILD")}</div>;
}
Output is:
NESTING_PARENT.CHILD
It turns out that config
keySeparator: falseturns off nesting overall. Even if i don't translate withNESTING_PARENT.CHILD.This is misleading as the
keySeparatorproperty is used to define key separator character (default is.).Removing
keySeparatorform the config fixed my issue.Output is now: