Add Next.js project with internationalization support
- Set up Next.js 15 with TypeScript, ESLint, and Tailwind CSS - Add i18n support for Korean, English, and Japanese - Implement language switcher and navigation components - Update .gitignore to exclude node_modules, IDE files, and build artifacts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
45
src/components/LanguageSwitcher.tsx
Normal file
45
src/components/LanguageSwitcher.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
import { useLocale } from 'next-intl';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { locales, localeNames, localeFlags, type Locale } from '@/i18n/config';
|
||||
|
||||
/**
|
||||
* Language Switcher Component
|
||||
*
|
||||
* Allows users to switch between available locales
|
||||
* Usage: Place in header or navigation bar
|
||||
*/
|
||||
export default function LanguageSwitcher() {
|
||||
const locale = useLocale();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const handleLocaleChange = (newLocale: Locale) => {
|
||||
// Get the pathname without the current locale
|
||||
const pathnameWithoutLocale = pathname.replace(`/${locale}`, '');
|
||||
|
||||
// Navigate to the new locale
|
||||
router.push(`/${newLocale}${pathnameWithoutLocale}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
{locales.map((loc) => (
|
||||
<button
|
||||
key={loc}
|
||||
onClick={() => handleLocaleChange(loc)}
|
||||
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||
locale === loc
|
||||
? 'bg-blue-600 text-white'
|
||||
: 'bg-gray-200 text-gray-700 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'
|
||||
}`}
|
||||
aria-label={`Switch to ${localeNames[loc]}`}
|
||||
>
|
||||
<span className="mr-1">{localeFlags[loc]}</span>
|
||||
{localeNames[loc]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
43
src/components/NavigationMenu.tsx
Normal file
43
src/components/NavigationMenu.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
import Link from 'next/link';
|
||||
import { useLocale } from 'next-intl';
|
||||
|
||||
/**
|
||||
* Navigation Menu Component
|
||||
*
|
||||
* Demonstrates translation in navigation elements
|
||||
* Shows how to use translations with dynamic content
|
||||
*/
|
||||
export default function NavigationMenu() {
|
||||
const t = useTranslations('navigation');
|
||||
const locale = useLocale();
|
||||
|
||||
const menuItems = [
|
||||
{ key: 'dashboard', href: '/dashboard' },
|
||||
{ key: 'inventory', href: '/inventory' },
|
||||
{ key: 'finance', href: '/finance' },
|
||||
{ key: 'hr', href: '/hr' },
|
||||
{ key: 'crm', href: '/crm' },
|
||||
{ key: 'reports', href: '/reports' },
|
||||
{ key: 'settings', href: '/settings' },
|
||||
];
|
||||
|
||||
return (
|
||||
<nav className="bg-gray-100 dark:bg-gray-900 p-4 rounded-lg">
|
||||
<ul className="flex flex-wrap gap-4">
|
||||
{menuItems.map((item) => (
|
||||
<li key={item.key}>
|
||||
<Link
|
||||
href={`/${locale}${item.href}`}
|
||||
className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300 font-medium"
|
||||
>
|
||||
{t(item.key as any)}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
20
src/components/WelcomeMessage.tsx
Normal file
20
src/components/WelcomeMessage.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
/**
|
||||
* Welcome Message Component
|
||||
*
|
||||
* Demonstrates basic translation usage
|
||||
* Shows how to use useTranslations hook in client components
|
||||
*/
|
||||
export default function WelcomeMessage() {
|
||||
const t = useTranslations('common');
|
||||
|
||||
return (
|
||||
<div className="p-6 bg-white dark:bg-gray-800 rounded-lg shadow-md">
|
||||
<h2 className="text-2xl font-bold mb-2">{t('welcome')}</h2>
|
||||
<p className="text-gray-600 dark:text-gray-300">{t('appName')}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user