Skip to content

Conversation

@triklozoid
Copy link
Collaborator

@triklozoid triklozoid commented Aug 5, 2025

Описание общей логики: https://github.com/dtpstat/dtp-project/wiki/%D0%9B%D0%BE%D0%BA%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F

Summary by CodeRabbit

  • New Features

    • Added internationalization (i18n) support with Russian and English language options.
    • Introduced language switching and localization for key UI elements, including filter panel and map iframe pages.
    • Added English and Russian translation files for common interface text.
  • Chores

    • Updated and added dependencies to support i18n functionality.
    • Adjusted configuration files to enable and customize localization behavior.

@coderabbitai
Copy link

coderabbitai bot commented Aug 5, 2025

Walkthrough

Internationalization (i18n) support is introduced to the Next.js application. This includes configuration updates, new locale files for Russian and English, dependency additions for i18n libraries, and code changes to integrate translation hooks and server-side translation loading in relevant components and pages.

Changes

Cohort / File(s) Change Summary
i18n Configuration
next-i18next.config.js, next.config.mjs
Added and configured i18n settings for default and supported locales (Russian and English), locale detection, and locale cookie settings.
i18n Dependencies
package.json
Updated Prisma dependencies to "latest" and added i18next, next-i18next, and react-i18next for localization support.
Localization Files
public/locales/en/common.json, public/locales/ru/common.json
Added English and Russian translation files with five common UI strings each.
Component i18n Integration
src/components/inherited-map/components/filter-panel/filter-panel-normal.js
Integrated translation hook and replaced hardcoded Russian strings with translation keys for filter panel UI.
App-wide i18n Integration
src/pages/_app.tsx
Wrapped the App component with appWithTranslation to enable i18n throughout the app.
Page-level i18n Integration
src/pages/iframes/map.tsx
Added translation hook usage and implemented getServerSideProps to provide server-side translations for the map iframe page.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant NextJS_App
    participant next-i18next
    participant Locale_Files

    User->>Browser: Requests page (with locale)
    Browser->>NextJS_App: Sends request (locale info)
    NextJS_App->>next-i18next: Calls serverSideTranslations(locale)
    next-i18next->>Locale_Files: Loads translation JSON for locale
    Locale_Files-->>next-i18next: Returns translations
    next-i18next-->>NextJS_App: Provides translation props
    NextJS_App-->>Browser: Renders page with translations
    Browser-->>User: Displays localized UI
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature-i18n

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link

netlify bot commented Aug 5, 2025

Deploy Preview for dtp-stat failed. Why did it fail? →

Name Link
🔨 Latest commit d8776bf
🔍 Latest deploy log https://app.netlify.com/projects/dtp-stat/deploys/68951da40156d10008de3bb8

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
public/locales/en/common.json (1)

1-7: Check key parity and punctuation against the Russian source
Before merging, make sure the English file contains exactly the same keys (and any required interpolation placeholders) as public/locales/ru/common.json; otherwise run-time lookups will fall back to Russian or break. Also verify the trailing colon in "forPeriod" matches the Russian variant so UI punctuation stays consistent.

src/pages/iframes/map.tsx (1)

35-41: Type the getServerSideProps signature to avoid drift
Using a hand-rolled { locale: string } parameter ignores the rest of GetServerSidePropsContext, which can lead to unsound code if you ever access other properties. Prefer the official type:

-import { serverSideTranslations } from "next-i18next/serverSideTranslations";
+import { serverSideTranslations } from "next-i18next/serverSideTranslations";
+import type { GetServerSideProps } from "next";

-export async function getServerSideProps({ locale }: { locale: string }) {
+export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
   return {
     props: {
       ...(await serverSideTranslations(locale ?? "ru", ["common"])),
     },
   };
-}
+};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c12f684 and 9223573.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • next-i18next.config.js (1 hunks)
  • next.config.mjs (1 hunks)
  • package.json (2 hunks)
  • public/locales/en/common.json (1 hunks)
  • public/locales/ru/common.json (1 hunks)
  • src/components/inherited-map/components/filter-panel/filter-panel-normal.js (4 hunks)
  • src/pages/_app.tsx (2 hunks)
  • src/pages/iframes/map.tsx (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/pages/iframes/map.tsx (1)
src/components/inherited-map/components/filter-panel/filter-panel-normal.js (1)
  • useTranslation (69-69)
🔇 Additional comments (4)
package.json (1)

40-50: Check peer-compatibility of newly added i18n packages with Next 12 / React 17
next-i18next@15 is published for recent Next versions (≥12 is fine) but its peer map expects React ≥17.0.2 AND requires i18next@>=21. The pinned versions here satisfy that, but please confirm in lockfile/CI that no peer warnings are produced and bundle size impact is acceptable.

public/locales/ru/common.json (1)

1-7: LGTM – keys are present and match the EN file
No issues spotted with the Russian translation stub.

src/pages/_app.tsx (1)

5-6: Type-safety: export of appWithTranslation(App) loses the custom err prop
appWithTranslation returns NextPage<AppProps> and doesn’t include { err: Error }. If you rely on the err prop elsewhere, add an explicit type to preserve it:

-const App: React.VoidFunctionComponent<AppProps & { err: Error }> = ({
+const App: React.FC<AppProps & { err: Error }> = ({
   …
 });
 
-export default appWithTranslation(App);
+export default appWithTranslation(App) as unknown as React.FC<
+  AppProps & { err: Error }
+>;

At a minimum run tsc to ensure no implicit-any errors surface.

Also applies to: 28-28

src/components/inherited-map/components/filter-panel/filter-panel-normal.js (1)

69-70: LGTM – localisation hook correctly replaces hard-coded strings
The component now pulls filters and hide from the “common” namespace; import path and namespace are correct.

Also applies to: 88-89, 105-106

Comment on lines +1 to +6
module.exports = {
i18n: {
defaultLocale: "ru",
locales: ["ru", "en"],
},
};
Copy link

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 behaviour
If 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
module.exports = {
i18n: {
defaultLocale: "ru",
locales: ["ru", "en"],
},
};
module.exports = {
i18n: {
defaultLocale: "ru",
locales: ["ru", "en"],
fallbackLng: "ru",
// localeDetection: false, // uncomment if you rely on Django cookie instead
},
};
🤖 Prompt for AI Agents
In next-i18next.config.js at lines 1 to 6, the configuration lacks a fallbackLng
setting, which can cause runtime errors if an unsupported locale is requested.
Add a fallbackLng property inside the i18n object, setting it to "ru" to ensure
the app falls back to Russian when an unsupported locale is used. Optionally,
add localeDetection: false to disable automatic locale detection for more
predictable SSR behavior.

Comment on lines +24 to +35
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
},
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

localeCookie is not a recognised Next.js i18n option
Next.js (≤ 13.5) supports locales, defaultLocale, domains, and localeDetection; there is no localeCookie field. Unknown keys are silently ignored, so the custom cookie settings here will have no effect and may mislead future maintainers.

If cookie control is required, handle it at application level (e.g. setCookie on locale switch) or confirm that your Next.js version introduces localeCookie.

   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 localeCookie option from i18n
The localeCookie field isn’t recognized by Next.js 12.1.0 (or any Next.js release up through v13); Next.js only supports locales, defaultLocale, domains and localeDetection under i18n. Unknown properties are silently ignored, so this block has no effect and may mislead future maintainers. If you need to control the locale cookie, do so in application code (e.g. call setCookie when handling a locale switch).

Please remove the following lines in next.config.mjs:

   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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
},
},
i18n: {
defaultLocale: "ru",
locales: ["ru", "en"],
localeDetection: false, // отключить автоопределение по Accept-Language
},
🤖 Prompt for AI Agents
In next.config.mjs around lines 24 to 35, the i18n configuration includes an
unsupported localeCookie option that Next.js does not recognize and silently
ignores. Remove the entire localeCookie block from the i18n configuration to
avoid confusion and ensure only supported options remain. Manage locale cookies
separately in application code if needed.

"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/react-fontawesome": "^0.1.17",
"@prisma/client": "^3.9.2",
"@prisma/client": "latest",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid "latest" – pin Prisma packages to a fixed semver range
Using the string "latest" for both @prisma/client and prisma makes every install potentially pull a different version, which breaks reproducibility and can introduce breaking changes without notice (Prisma frequently ships breaking feature flags). Replace it with an explicit semver (e.g. "^5.7.0" or whatever version you have validated in CI).

-    "@prisma/client": "latest",
+    "@prisma/client": "^5.7.0",-    "prisma": "latest",
+    "prisma": "^5.7.0",

Also applies to: 84-84

🤖 Prompt for AI Agents
In package.json at line 35 and also line 84, replace the version string "latest"
for both "@prisma/client" and "prisma" dependencies with a fixed semver range
like "^5.7.0" or the specific version you have tested in CI to ensure consistent
and reproducible installs without unexpected breaking changes.

import { NextPage } from "next";
import dynamic from "next/dynamic";
import Script from "next/script";
import { useTranslation } from "next-i18next";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unused t variable (will trip ESLint)
const { t } = useTranslation("common"); is never referenced, so the build will fail with no-unused-vars.
Either delete the import and the destructuring altogether or keep only the hook call:

-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
In src/pages/iframes/map.tsx at lines 4 and 18, the variable `t` destructured
from `useTranslation("common")` is not used, causing ESLint no-unused-vars
errors. Remove the destructuring of `t` from the hook call or remove the entire
import if not needed. If the hook call is required for side effects, keep only
the hook call without destructuring `t`.

@alexander-mart
Copy link
Member

@triklozoid рекомендации от кролика актуальны?

@alexander-mart alexander-mart self-requested a review August 7, 2025 20:32
@alexander-mart alexander-mart added the enhancement New feature or request label Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants