Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions components/languageSwitcher/LanguageSwitcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useTranslation } from 'react-i18next'
import { Button, Flex, Text } from 'theme-ui'

const LanguageSwitcher = () => {
const { i18n } = useTranslation()

const changeLanguage = (lng) => {
i18n.changeLanguage(lng)
}

const languages = [
{ code: 'en', name: 'English', flag: '🇺🇸' },
{ code: 'tr', name: 'Türkçe', flag: '🇹🇷' }
]

return (
<Flex sx={{ gap: 2, alignItems: 'center' }}>
<Text sx={{ fontSize: 1, fontWeight: 'bold' }}>Language:</Text>

Copy link
Copy Markdown

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.

{languages.map((lang) => (
<Button
key={lang.code}
onClick={() => changeLanguage(lang.code)}
variant={i18n.language === lang.code ? 'primary' : 'outline'}
sx={{
fontSize: 1,
py: 1,
px: 2,
display: 'flex',
alignItems: 'center',
gap: 1,
cursor: 'pointer',
opacity: i18n.language === lang.code ? 1 : 0.7,
'&:hover': {
opacity: 1
}
}}
>
<span>{lang.flag}</span>
<span>{lang.name}</span>
</Button>
))}
</Flex>
)
}

export default LanguageSwitcher
4 changes: 4 additions & 0 deletions components/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Icon from './icon'
import Flag from './flag'
import ScrollLock from 'react-scrolllock'
import NextLink from 'next/link'
import LanguageSwitcher from '../components/languageSwitcher/LanguageSwitcher'

const rgbaBgColor = (props, opacity) =>
`rgba(
Expand Down Expand Up @@ -147,6 +148,8 @@ const Navigation = props => (
<NextLink href="https://toolbox.hackclub.com/" passHref>
<Link>Toolbox</Link>
</NextLink>


</NavBar>
)

Expand Down Expand Up @@ -225,6 +228,7 @@ function Header({ unfixed, color, bgColor, dark, fixed, ...props }) {
color={baseColor}
dark={dark}
/>
<LanguageSwitcher />

Copy link
Copy Markdown

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.js

Length 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"
fi

Length 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 @media queries detected
  • No useMediaQuery usage
  • All sx props use fixed values

Suggestions:

  • Wrap in a conditional display component (e.g. <Hide below="md"> / <Show above="sm">)
  • Or update sx to 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.

<ToggleContainer color={toggleColor} onClick={handleToggleMenu}>
<Icon glyph={toggled ? 'view-close' : 'menu'} />
</ToggleContainer>
Expand Down
56 changes: 56 additions & 0 deletions lib/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import LanguageDetector from 'i18next-browser-languagedetector'

// Import translation files
import enTranslations from '../public/locales/en/translation.json'
import trTranslations from '../public/locales/tr/translation.json'

i18n
// Detect user language
.use(LanguageDetector)
// Pass the i18n instance to react-i18next
.use(initReactI18next)
// Initialize i18next
.init({
debug: process.env.NODE_ENV === 'development',

fallbackLng: 'en',
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},

// Language resources
resources: {
en: {
translation: enTranslations
},
tr: {
translation: trTranslations
}
},

// Language detection options
detection: {
// Order of language detection
order: ['querystring', 'cookie', 'localStorage', 'navigator', 'htmlTag'],

// Keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',

// Cache user language
caches: ['localStorage', 'cookie'],

// Optional expire and domain for set cookie
cookieMinutes: 10080, // 7 days
},

// React options
react: {
useSuspense: false
}
})

export default i18n
8 changes: 8 additions & 0 deletions next-i18next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Next.js i18n configuration for routing
const i18nConfig = {
locales: ['en', 'tr'],
defaultLocale: 'en',
localeDetection: true
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

export default i18nConfig
2 changes: 2 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import i18n from './next-i18next.config.js';
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
Expand Down Expand Up @@ -25,6 +26,7 @@ const nextConfig = {
}
]
},
i18n,
webpack: (config, { isServer }) => {
return config
},
Expand Down
Loading