A comprehensive demonstration of different internationalization (i18n) implementation approaches in React, featuring Context API, Zustand, and react-i18next.
- Three different i18n implementation approaches:
- Context API implementation
- Zustand state management implementation
- Default react-i18next implementation
- TypeScript for type safety
- Modern UI with Tailwind CSS
- Responsive design
- Easy language switching
- Centralized translation management
- React 18
- TypeScript
- Vite
- TailwindCSS
- i18next
- Zustand
- React Router DOM
- Yarn Package Manager
- Clone the repository:
git clone https://github.com/yourusername/i18n-demo.git
cd i18n-demo
- Install dependencies:
yarn install
- Start the development server:
yarn dev
src/
βββ components/ # Shared components
βββ config/ # i18n configuration
βββ contexts/ # Context API implementation
βββ locales/ # Translation files
β βββ en/ # English translations
β βββ vi/ # Vietnamese translations
βββ pages/ # Demo pages
βββ stores/ # Zustand store
- Uses React's Context API for state management
- Provides a custom hook
useLanguage
for easy access - Ideal for smaller applications
- Utilizes Zustand for state management
- Offers a more flexible and scalable solution
- Great for medium to large applications
- Uses the standard react-i18next approach
- Provides access to all i18next features
- Recommended for projects requiring advanced i18n features
/
- Home page/context
- Context API implementation demo/zustand
- Zustand implementation demo/i18next
- React-i18next implementation demo
The i18n configuration can be found in src/config/i18n.ts
. You can modify:
- Supported languages
- Default language
- Translation namespaces
- Detection options
yarn dev
- Start development serveryarn build
- Build for productionyarn preview
- Preview production buildyarn lint
- Run ESLintyarn type-check
- Run TypeScript type checking
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Your Name - Initial work - YourGithub
- React Team
- i18next Team
- Zustand Team
- TailwindCSS Team
Your Name - @yourtwitter - [email protected]
Project Link: https://github.com/yourusername/i18n-demo