getFixedT does not use fallbackLng from i18nextOptions
jacknevitt opened this issue · 0 comments
jacknevitt commented
Describe the bug
When using i18n.getFixedT
inside a loader function, I have to redeclare the fallbackLng
option.
import i18n from "~/i18next.server";
import i18nextOptions from "~/i18nextOptions";
export async function loader({ request }: DataFunctionArgs) {
const t = await i18n.getFixedT(request, "welcome", {
fallbackLng: i18nextOptions.fallbackLng, // required
});
return json({
meta: {
title: t("META_TITLE"),
},
});
}
Without declaring it again, t("META_TITLE")
returns the translation key for languages without this key. I'm expecting to see the fallback language used in i18next.server.js
to translate the string.
Your Example Website or App
Private repo
Steps to Reproduce the Bug or Issue
- Create an i18next instance as shown in
i18next.server.js
in https://github.com/sergiodxa/remix-i18next#configuration - Import the i18next instance in a route file.
- Declare a variable
t
by callingi18next.getFixedT
with the request and namespace arguments - Call
t
function with a translation key that exists in the fallback language but not in another language - Make a request with the browser language for the other language without the key
Expected behavior
I expect to see the translation for the given key in the fallback language used when none exist in the target language
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: 109.0
Additional context
Not a major issue as there is a workaround but it would save us repeating code in each route's loader. Thanks