yzs
08/02/2022, 10:17 AMnext-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?rp_st
08/02/2022, 10:23 AMporcellus
08/02/2022, 10:26 AMporcellus
08/02/2022, 10:26 AMporcellus
08/02/2022, 10:29 AMporcellus
08/02/2022, 10:29 AMyzs
08/02/2022, 10:41 AMyzs
08/02/2022, 10:41 AMporcellus
08/02/2022, 10:47 AMporcellus
08/02/2022, 10:50 AM// 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(),
],
});
porcellus
08/02/2022, 10:50 AMyzs
08/02/2022, 10:51 AMyzs
08/02/2022, 10:52 AMyzs
08/02/2022, 10:54 AMjs
languageTranslations: {
translationFunc: (key: string) => {
// The string returned by this function will be displayed
const { t } = useTranslation(['auth', 'common'])
return t(key)
},
},
yzs
08/02/2022, 10:55 AMyzs
08/02/2022, 10:56 AM'auth'
namespace, but if i change the array to ['common', 'auth']
it only translates from 'common'
namespaceporcellus
08/02/2022, 10:58 AMuseTranslation
like a normal react hook? because I don't think that'd work inside the translationFuncporcellus
08/02/2022, 11:00 AMyzs
08/02/2022, 11:02 AMjs
// the t function will be set to first namespace as default
const { t, i18n } = useTranslation(['ns1', 'ns2', 'ns3']);
yzs
08/02/2022, 11:02 AMporcellus
08/02/2022, 11:02 AMyzs
08/02/2022, 11:02 AMyzs
08/02/2022, 11:03 AMporcellus
08/02/2022, 11:04 AMporcellus
08/02/2022, 11:05 AMyzs
08/02/2022, 11:06 AMyzs
08/02/2022, 11:06 AMporcellus
08/02/2022, 11:07 AM