-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change language without modifying the URL (/[lang]/rest) #1159
Comments
I'm facing a similar problem |
We are on the same boat, trying to switch languages without using [lang]/route. the setLanguage complains about that the next/router is not found.
Ok, after finding this comment #1022 (comment) |
Attempting to implement the solution you refer to @Eusebiotrigo didn't work for me unfortunately. I still get:
😩 |
+1 |
No real official way, for now, to do so. However, you can implement it using Here's what's worked for me, as ugly as it may be.
import commonEn from 'public/locales/en/common.json';
import dashboardEn from 'public/locales/en/dashboard.json';
import commonFr from 'public/locales/fr/common.json';
import dashboardFr from 'public/locales/fr/dashboard.json';
type Locale = 'en' | 'fr';
const localeMapping = {
en: {
common: commonEn,
dashboard: dashboardEn,
},
fr: {
common: commonFr,
dashboard: dashboardFr,
},
};
export const useI18nProviderNamespaces = (locale: string) =>
localeMapping[locale as Locale];
const locale = props.pageProps.locale;
const i18nProviderNamespaces = useI18nProviderNamespaces(locale);
<I18nProvider lang={locale} namespaces={i18nProviderNamespaces}>
<MyApp {...props} />
</I18nProvider>
export const getServerSideProps: GetServerSideProps = async ({ req }) => ({
props: { locale: req.cookies.NEXT_LOCALE ?? 'en' },
}); You can polish it up a bit to suit your use case. The language will be determined by setting the cookie Hope it helps. |
What version of this package are you using?
2.6.0
What problem do you want to solve?
We have a dashboard app that is hidden from search engines, so we do not need SEO, using
Next 13.5
with pages router andnext-translate
latest version and we would like to be able to change language without adding the locale inside the url, I see that setLanguage uses next-router to pass thelocale
but would it be possible to allow to change the locale without changing the URL ?What do you think is the correct solution to this problem?
Maybe there is a way to use the NEXT_LOCALE cookie or something else to accomplish the same behavior, I am not familiar enough with this library
Are you willing to submit a pull request to implement this change?
It depends of the complexity of what would have to be modified
The text was updated successfully, but these errors were encountered: