-
Notifications
You must be signed in to change notification settings - Fork 0
Add localization for next.js #123
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| i18n: { | ||
| defaultLocale: "ru", | ||
| locales: ["ru", "en"], | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,18 @@ const nextConfig = { | |||||||||||||||||||||||||||||||||||
| compiler: { | ||||||||||||||||||||||||||||||||||||
| styledComponents: true, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| i18n: { | ||||||||||||||||||||||||||||||||||||
| defaultLocale: "ru", | ||||||||||||||||||||||||||||||||||||
| locales: ["ru", "en"], | ||||||||||||||||||||||||||||||||||||
| localeDetection: false, // отключить автоопределение по Accept-Language | ||||||||||||||||||||||||||||||||||||
| localeCookie: { | ||||||||||||||||||||||||||||||||||||
| name: "django_language", | ||||||||||||||||||||||||||||||||||||
| httpOnly: false, | ||||||||||||||||||||||||||||||||||||
| sameSite: false, // Django uses None, Next.js uses false for None | ||||||||||||||||||||||||||||||||||||
| path: "/", | ||||||||||||||||||||||||||||||||||||
| secure: false, // same as Django DEBUG mode | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain
If cookie control is required, handle it at application level (e.g. i18n: {
defaultLocale: "ru",
locales: ["ru", "en"],
localeDetection: false,
- localeCookie: { … }
},🏁 Script executed: #!/bin/bash
# Locate Next.js version in package.json
echo "Searching for Next.js dependency versions in package.json..."
grep -R -C2 '"next"\s*:' -n package.json || echo "No Next.js entry found in package.json."Length of output: 327 Remove unsupported Please remove the following lines in i18n: {
defaultLocale: "ru",
locales: ["ru", "en"],
localeDetection: false,
- localeCookie: {
- name: "django_language",
- httpOnly: false,
- sameSite: false, // Django uses None, Next.js uses false for None
- path: "/",
- secure: false, // same as Django DEBUG mode
- },
},📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| productionBrowserSourceMaps: true, | ||||||||||||||||||||||||||||||||||||
| reactStrictMode: true, | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,19 +32,22 @@ | |
| "@fortawesome/free-brands-svg-icons": "^6.0.0", | ||
| "@fortawesome/free-solid-svg-icons": "^6.0.0", | ||
| "@fortawesome/react-fontawesome": "^0.1.17", | ||
| "@prisma/client": "^3.9.2", | ||
| "@prisma/client": "latest", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid - "@prisma/client": "latest",
+ "@prisma/client": "^5.7.0",
…
- "prisma": "latest",
+ "prisma": "^5.7.0",Also applies to: 84-84 🤖 Prompt for AI Agents |
||
| "@sentry/nextjs": "^6.17.9", | ||
| "date-fns": "^2.28.0", | ||
| "dayjs": "^1.10.7", | ||
| "gravatar-url": "^4.0.1", | ||
| "i18next": "^25.3.2", | ||
| "lru-cache": "^7.4.0", | ||
| "mobx": "^6.4.0", | ||
| "mobx-devtools-mst": "^0.9.30", | ||
| "mobx-react": "^7.3.0", | ||
| "mobx-state-tree": "^5.1.3", | ||
| "next": "^12.1.0", | ||
| "next-i18next": "^15.4.2", | ||
| "react": "^17.0.2", | ||
| "react-dom": "^17.0.2", | ||
| "react-i18next": "^15.6.1", | ||
| "react-linkify": "^1.0.0-alpha", | ||
| "react-redux": "^7.2.6", | ||
| "react-tooltip": "^4.2.21", | ||
|
|
@@ -78,7 +81,7 @@ | |
| "prettier-plugin-packagejson": "^2.2.15", | ||
| "prettier-plugin-prisma": "^3.9.0", | ||
| "prettier-plugin-sh": "^0.8.1", | ||
| "prisma": "^3.9.2", | ||
| "prisma": "latest", | ||
| "suppress-exit-code": "^1.0.0", | ||
| "typescript": "^4.5.5" | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "welcome": "Welcome", | ||
| "dataPeriod": "Data Period", | ||
| "forPeriod": "For period:", | ||
| "filters": "Filters", | ||
| "hide": "Hide" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "welcome": "Добро пожаловать", | ||
| "dataPeriod": "Период данных", | ||
| "forPeriod": "За период:", | ||
| "filters": "Фильтры", | ||
| "hide": "Скрыть" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import { NextPage } from "next"; | ||
| import dynamic from "next/dynamic"; | ||
| import Script from "next/script"; | ||
| import { useTranslation } from "next-i18next"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused -import { useTranslation } from "next-i18next";
-...
- const { t } = useTranslation("common");
+// Translation resources are still loaded through getServerSideProps;
+// the hook call isn't required here.Also applies to: 18-18 🤖 Prompt for AI Agents |
||
| import { serverSideTranslations } from "next-i18next/serverSideTranslations"; | ||
| import * as React from "react"; | ||
|
|
||
| import { usePostLocationSearchChangesToIframeParent } from "../../shared/django-helpers"; | ||
|
|
@@ -13,6 +15,7 @@ const InheritedMap = dynamic( | |
|
|
||
| const MapIframePage: NextPage = () => { | ||
| usePostLocationSearchChangesToIframeParent(); | ||
| const { t } = useTranslation("common"); | ||
|
|
||
| return ( | ||
| <> | ||
|
|
@@ -29,4 +32,12 @@ const MapIframePage: NextPage = () => { | |
| ); | ||
| }; | ||
|
|
||
| export async function getServerSideProps({ locale }: { locale: string }) { | ||
| return { | ||
| props: { | ||
| ...(await serverSideTranslations(locale ?? "ru", ["common"])), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export default MapIframePage; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Include
fallbackLng(and optionally disable locale detection) for safer runtime behaviourIf a user requests an unsupported locale the app will currently throw. Add an explicit fallback to avoid 500s and keep SSR predictable:
module.exports = { i18n: { defaultLocale: "ru", locales: ["ru", "en"], + fallbackLng: "ru", + // localeDetection: false, // uncomment if you rely on Django cookie instead }, };📝 Committable suggestion
🤖 Prompt for AI Agents