hi! it's me again 😅 i set up language translatio...
# support-questions-legacy
y
hi! it's me again 😅 i set up language translations with
next-i18next
library via
translationFunc
like in your guides can i make arbitrary strings from custom additional fields in register page (like labels/placeholders - firstname, lastname) go through this
translateFunc
also?
r
@porcellus can help with this
p
hi
let me check 🙂
They should go through it
they don't in your experience?
y
no, they don't
p
hmm, it works for me. can you paste the config here?
Copy code
// Initialize i18next as you normally would
i18next.init({
    lng: "en", // if you're using a language detector, do not define the lng option

    fallbackLng: "en",
    debug: true,

    resources: {
        en: {
            translation: {
                // Other stuff....
                asdf: "!!!!!!!!!!!!!!!!!!",
                placeholder: "test",
            },
        },
    },
});
// These are used to trigger a re-rendering since the SDK can't detect the change otherwise.
i18next
    .on("languageChanged", (lng) => SuperTokens.changeLanguage(lng))
    .on("loaded", () => SuperTokens.loadTranslation({}));

export function getApiDomain() {
    const apiPort = process.env.REACT_APP_API_PORT || 3001;
    const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`;
    return apiUrl;
}

export function getWebsiteDomain() {
    const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000;
    const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`;
    return websiteUrl;
}

SuperTokens.init({
    languageTranslations: {
        translationFunc: i18next.t.bind(i18next),
    },
    appInfo: {
        appName: "SuperTokens Demo App", // TODO: Your app name
        apiDomain: getApiDomain(), // TODO: Change to your app's API domain
        websiteDomain: getWebsiteDomain(), // TODO: Change to your app's website domain
    },
    recipeList: [
        ThirdPartyEmailPassword.init({
            signInAndUpFeature: {
                signUpForm: {
                    formFields: [
                        { id: "asfd", label: "asdf", placeholder: "placeholder"}
                    ]
                },
                providers: [Github.init(), Google.init(), Apple.init()],
            },
            emailVerificationFeature: {
                mode: "REQUIRED",
            },
        }),
        Session.init(),
    ],
});
this works for me
y
i think it's actually `next-i18next`'s problem
for some reason it's inconsistent when i use multiple namespaces
my config is like this
Copy code
js
languageTranslations: {
      translationFunc: (key: string) => {
        // The string returned by this function will be displayed
        const { t } = useTranslation(['auth', 'common'])
        return t(key)
      },
    },
is this okay?
at the moment it only translates from
'auth'
namespace, but if i change the array to
['common', 'auth']
it only translates from
'common'
namespace
p
hmm, is
useTranslation
like a normal react hook? because I don't think that'd work inside the translationFunc
https://react.i18next.com/latest/usetranslation-hook#loading-namespaces as far as I can see that's the expected behaviour
y
Copy code
js
// the t function will be set to first namespace as default
const { t, i18n } = useTranslation(['ns1', 'ns2', 'ns3']);
do you mean this?
p
yeah
y
i thought that this means if not in ns1 then look in ns2
i don't have the key in ns1, but do have it in ns2
p
well the next 2 lines seem to say it won't fall through
you could try to add the second namespace to the translation key itself like "common:firstname"
y
thank you! it works 🙂
i forgot that i can use namespaces like that 😅 sorry
p
happy to help 🙂
9 Views