-
Notifications
You must be signed in to change notification settings - Fork 3
add multilanguage pattern #3
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?
Conversation
… translations - Added i18next and related packages for localization. - Created English translation files for common phrases and specific content. - Created Turkish translation files for common phrases and specific content. - Added a translations.json file to manage language keys and translations.
|
""" WalkthroughInternationalization (i18n) support is introduced throughout the application. This includes adding translation resource files for English and Turkish, configuring i18n libraries, updating components to use translation hooks, and integrating a language switcher UI. Next.js and package configuration files are updated to support multilingual routing and translation management. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant LanguageSwitcher
participant i18n
participant UIComponent
User->>LanguageSwitcher: Clicks language button
LanguageSwitcher->>i18n: i18n.changeLanguage(lang)
i18n-->>UIComponent: Triggers re-render with new language
UIComponent->>i18n: useTranslation() retrieves strings
UIComponent-->>User: Displays UI in selected language
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 4
🔭 Outside diff range comments (5)
pages/index.js (5)
654-669: Complete internationalization for this section.This section contains hardcoded English text that should be internationalized to match the rest of the page. The text "Connect with builders from the community" and related content should use translation keys.
Consider adding translation keys for this section:
- <Text variant="title" sx={{ fontSize: ['36px', 4, 5] }}> - Connect with{' '} - <Text - as="span" - sx={{ - borderRadius: 'default', - px: 2, - mx: 0, - whiteSpace: 'nowrap', - color: 'white', - bg: 'red' - }} - > - builders - </Text>{' '} - from the community - </Text> - <Text - variant="subtitle" - as="p" - sx={{ fontSize: ['18px', '20px', '22px'], pb: [3, 0, 0] }} - > - We gather both online and in-person to share our love of code - and make things together! - </Text> + <Text variant="title" sx={{ fontSize: ['36px', 4, 5] }}> + {t('connect.title')} + </Text> + <Text + variant="subtitle" + as="p" + sx={{ fontSize: ['18px', '20px', '22px'], pb: [3, 0, 0] }} + > + {t('connect.subtitle')} + </Text>
719-746: Complete internationalization for the open source section.This section contains hardcoded English text including "We build open source games and tools together" and related content that should be internationalized.
Add translation keys for this section to ensure consistent multilingual support across the entire page.
857-882: Complete internationalization for the IRL community section.The "Find your IRL community" section and its subtitle contain hardcoded English text that should use translation keys for consistency with the rest of the internationalized content.
910-935: Complete internationalization for the recap section.The recap section includes hardcoded text like "We've got a lot going on - Let's recap" and "Find your second home at HHS" that should be internationalized.
998-1117: Complete internationalization for the action cards.The three action cards contain hardcoded English text for titles and descriptions ("Join Our Community", "Explore Our Open Source Tools", "Start A Club") that should use translation keys.
🧹 Nitpick comments (9)
translations.json (1)
1-10: Prefer per-locale resource files over a singletranslations.jsoni18next (and
next-i18next) look for translation namespaces insidepublic/locales/<lng>/<ns>.json.
Keeping an additional root-leveltranslations.jsonwith duplicate keys:
- introduces another source of truth that can easily diverge from the canonical
public/locales/*files,- is not loaded automatically by the library, so the data is effectively unused unless extra plumbing is added.
Consider deleting this file and consolidating the strings under the existing
public/locales/{en,tr}/common.json(or another namespace) to avoid drift.public/locales/en/common.json (1)
1-4: Minor: drop punctuation to keep keys identical across localesKey
"welcome"carries"Welcome!"here but"Welcome"in other files.
Uniform values (and punctuation) simplify copy-editing and avoid accidental fallback mismatches.No functional impact; treat as style guidance.
public/locales/tr/common.json (1)
1-4: Align punctuation with English counterpartSame note as above – consider removing the exclamation mark or adding it to both locales for consistency.
public/locales/en/index.json (1)
1-9: Consider consolidating translation files for better maintainability.The JSON structure and content are well-organized. However, having separate files like
index.json,translation.json, andcommon.jsonmight lead to confusion about where to place new translations. Consider consolidating into a single main translation file or establish clear guidelines for file organization.components/languageSwitcher/LanguageSwitcher.js (2)
20-41: Enhance accessibility and add responsive considerations.Consider adding accessibility attributes and responsive behavior for mobile devices.
<Button key={lang.code} onClick={() => changeLanguage(lang.code)} variant={i18n.language === lang.code ? 'primary' : 'outline'} + aria-label={`Switch to ${lang.name}`} + aria-pressed={i18n.language === lang.code} sx={{ fontSize: 1, py: 1, px: 2, display: 'flex', alignItems: 'center', gap: 1, cursor: 'pointer', opacity: i18n.language === lang.code ? 1 : 0.7, + '@media (max-width: 48em)': { + fontSize: 0, + px: 1 + }, '&:hover': { opacity: 1 } }} >
11-14: Consider making language configuration external.Hardcoding the language list limits flexibility. Consider moving this to a configuration file or making it configurable via props.
- const languages = [ - { code: 'en', name: 'English', flag: '🇺🇸' }, - { code: 'tr', name: 'Türkçe', flag: '🇹🇷' } - ] + const languages = [ + { code: 'en', name: t('english'), flag: '🇺🇸' }, + { code: 'tr', name: t('turkish'), flag: '🇹🇷' } + ]public/locales/tr/translation.json (1)
89-93: Consider consistency in terminology translation.Ensure consistent translation of technical terms throughout the application. For example, "Hack Kulüpleri" for "Hack Clubs" should be used consistently across all translation files.
pages/index.js (1)
47-48: Verify if the i18n import is necessary.The
i18nimport on line 47 doesn't appear to be used directly in the component. Only theuseTranslationhook is utilized. Consider removing the unused import unless it's required for initialization.-import i18n from '../lib/i18n' import { useTranslation } from 'react-i18next'lib/i18n.js (1)
1-56: Well-configured i18n setup with a potential optimization opportunity.The i18n configuration is comprehensive and follows best practices:
- Proper plugin integration for language detection and React
- Appropriate fallback language and debug settings
- Comprehensive language detection strategy
- Correct React integration options
However, consider lazy-loading translation files for better performance:
For better bundle optimization, consider using dynamic imports for translation files:
-// Import translation files -import enTranslations from '../public/locales/en/translation.json' -import trTranslations from '../public/locales/tr/translation.json' i18n .use(LanguageDetector) .use(initReactI18next) .init({ debug: process.env.NODE_ENV === 'development', fallbackLng: 'en', interpolation: { escapeValue: false, }, - resources: { - en: { - translation: enTranslations - }, - tr: { - translation: trTranslations - } - }, + // Load resources dynamically + resources: {}, + + // Backend configuration for loading translations + backend: { + loadPath: '/locales/{{lng}}/{{ns}}.json', + },This approach would require adding
i18next-http-backendplugin but would improve initial bundle size.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
package-lock.jsonis excluded by!**/package-lock.jsonyarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (13)
components/languageSwitcher/LanguageSwitcher.js(1 hunks)components/nav.js(3 hunks)lib/i18n.js(1 hunks)next-i18next.config.js(1 hunks)next.config.mjs(2 hunks)package.json(2 hunks)pages/index.js(13 hunks)public/locales/en/common.json(1 hunks)public/locales/en/index.json(1 hunks)public/locales/en/translation.json(1 hunks)public/locales/tr/common.json(1 hunks)public/locales/tr/translation.json(1 hunks)translations.json(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
components/nav.js (1)
components/languageSwitcher/LanguageSwitcher.js (1)
LanguageSwitcher(4-44)
components/languageSwitcher/LanguageSwitcher.js (1)
pages/index.js (1)
useTranslation(76-76)
pages/index.js (2)
components/languageSwitcher/LanguageSwitcher.js (1)
useTranslation(5-5)pages/fiscal-sponsorship/open-source.js (1)
Link(25-32)
🔇 Additional comments (9)
package.json (1)
54-56: i18n package compatibility verified – no peer-dependency warnings
Rannpm ls i18next react-i18next next-i18nextand confirmed all versions (i18next@25.3.2, react-i18next@15.6.1, next-i18next@15.4.2) resolve without unmet peer dependencies.next.config.mjs (2)
29-29: LGTM: Proper i18n integration.The i18n configuration is correctly integrated into the Next.js config following the standard pattern for next-i18next.
1-1: ✅ i18n Configuration VerifiedThe referenced
next-i18next.config.jsfile exists and exports a valid i18n config:
- locales: ['en', 'tr']
- defaultLocale: 'en'
- localeDetection: true
No further changes needed—your import and
i18nproperty innext.config.mjsare correctly configured.components/nav.js (1)
10-10: LGTM: Clean component import.The import follows the project's convention for component imports.
public/locales/tr/translation.json (1)
1-95: Comprehensive Turkish translations with well-organized structure.The translation file is comprehensive and well-structured with logical key organization. The nested structure makes it easy to understand the context of each translation.
pages/index.js (1)
238-607: Well-implemented translation key usage.The translation keys are well-structured, semantic, and follow a logical hierarchy. The implementation correctly uses the
useTranslationhook and applies translations consistently throughout the internationalized sections.lib/i18n.js (1)
33-48: Excellent language detection configuration.The language detection setup is comprehensive and well-ordered:
- Prioritizes explicit user choices (query string, cookie, localStorage)
- Falls back to browser defaults appropriately
- Implements proper caching strategy
- Sets reasonable cookie expiration (7 days)
public/locales/en/translation.json (2)
1-104: Well-structured translation file with comprehensive coverage.The translation file demonstrates excellent organization:
- Clear hierarchical structure with logical groupings
- Semantic key names that are easy to understand and maintain
- Comprehensive coverage of UI elements and content
- Proper JSON formatting and structure
The nested structure (e.g.,
joyOfCode.steps.connect.title) makes it easy to organize related translations and maintain consistency.
22-41: Excellent content structure for the joyOfCode section.The step-by-step content is well-structured with clear titles and engaging descriptions. The nested organization makes it easy to maintain and translate this content consistently across languages.
|
|
||
| return ( | ||
| <Flex sx={{ gap: 2, alignItems: 'center' }}> | ||
| <Text sx={{ fontSize: 1, fontWeight: 'bold' }}>Language:</Text> |
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
Make the "Language:" label translatable.
The label is hardcoded in English, which defeats the purpose of internationalization. It should use a translation key.
- <Text sx={{ fontSize: 1, fontWeight: 'bold' }}>Language:</Text>
+ <Text sx={{ fontSize: 1, fontWeight: 'bold' }}>{t('language')}:</Text>And add the translation key to your locale files:
{
"language": "Language"
}🤖 Prompt for AI Agents
In components/languageSwitcher/LanguageSwitcher.js at line 18, the "Language:"
label is hardcoded in English, which breaks internationalization. Replace the
hardcoded text with a translation function call using a key like "language".
Then, add the "language" key with the value "Language" to your locale JSON files
to support translations.
| color={baseColor} | ||
| dark={dark} | ||
| /> | ||
| <LanguageSwitcher /> |
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.
💡 Verification agent
🧩 Analysis chain
Verify responsive behavior of the language switcher.
The LanguageSwitcher is well-positioned in the navigation. However, ensure it behaves appropriately on mobile devices where navigation collapses.
🏁 Script executed:
#!/bin/bash
# Description: Check if LanguageSwitcher has responsive considerations
# Expected: Component should handle mobile layouts appropriately
# Look for responsive styles in the LanguageSwitcher component
rg -A 10 -B 5 "@media|sx.*display|mobile" components/languageSwitcher/LanguageSwitcher.jsLength of output: 91
We didn’t locate any responsive rules with the previous grep. Let’s first find the exact LanguageSwitcher file and then inspect it for breakpoints or media queries:
🏁 Script executed:
#!/bin/bash
# 1. Locate the LanguageSwitcher component file
rg -l "export.*LanguageSwitcher" -g "*.js" -g "*.jsx" -g "*.ts" -g "*.tsx"
# 2. If found, inspect for responsive patterns
FILE=$(rg -l "export.*LanguageSwitcher" -g "*.js" -g "*.jsx" -g "*.ts" -g "*.tsx" | head -n1)
if [ -n "$FILE" ]; then
echo "🔍 Inspecting $FILE for responsive styling…"
echo "--- @media queries ---"
rg -n -C 3 "@media" "$FILE"
echo "--- sx props ---"
rg -n -C 3 "sx=" "$FILE"
echo "--- useMediaQuery hook ---"
rg -n -C 3 "useMediaQuery" "$FILE"
else
echo "❌ LanguageSwitcher component file not found"
fiLength of output: 1335
Ensure LanguageSwitcher adapts to mobile layouts
The LanguageSwitcher currently uses a static <Flex> layout without any breakpoints, media queries, or conditional rendering. On narrow viewports it may overflow or clash with the collapsed nav. Please add responsive handling so it either hides or reflows appropriately.
• File: components/languageSwitcher/LanguageSwitcher.js
Lines: ~16–27
- No
@mediaqueries detected - No
useMediaQueryusage - All
sxprops use fixed values
Suggestions:
- Wrap in a conditional display component (e.g.
<Hide below="md">/<Show above="sm">) - Or update
sxto use responsive arrays, for example:<Flex
- sx={{ gap: 2, alignItems: 'center' }}
- sx={{
-
display: ['none', 'flex'], // hidden on xs, shown on sm+ -
gap: 2, -
alignItems: 'center' - }}
- Alternatively, use `useMediaQuery` to switch between desktop and mobile UI
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **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.
```suggestion
// components/languageSwitcher/LanguageSwitcher.js
// … somewhere around lines 16–27 …
return (
<Flex
sx={{
display: ['none', 'flex'], // hidden on xs, shown on sm+
gap: 2,
alignItems: 'center'
}}
>
{/* …existing children (e.g. language buttons) */}
</Flex>
);
// …
🤖 Prompt for AI Agents
In components/nav.js at line 231, the LanguageSwitcher component lacks
responsive design and may overflow on narrow viewports. To fix this, update the
LanguageSwitcher usage by wrapping it in a conditional display component like
<Hide below="md"> or <Show above="sm"> to hide it on small screens, or modify
its sx props in components/languageSwitcher/LanguageSwitcher.js (lines ~16–27)
to use responsive arrays for layout values. Alternatively, implement
useMediaQuery inside LanguageSwitcher to render different layouts based on
screen size.
Summary by CodeRabbit
New Features
Enhancements
Chores