UNPKG

create-onetech-app

Version:

CLI to quickly set up React projects with popular templates and tools.

317 lines (244 loc) β€’ 10.2 kB
# OneTech Next.js + next-intl Template A production-ready [Next.js](https://nextjs.org) template with internationalization, TypeScript, and Tailwind CSS from the OneTech open-source collection. ## πŸš€ Quick Start Create a new project using this template: ```bash npx create-onetech-app my-app --base=nextjs --lang=ts --template=app-i18n ``` ## ✨ What's Included This template provides everything you need to build modern multilingual web applications: - ⚑ **Next.js 15** with App Router and Server Components - 🌐 **next-intl Integration** - Complete internationalization with 5 languages - 🎨 **Tailwind CSS** with dark mode support - πŸ“± **Responsive Design** optimized for all devices - πŸŒ™ **Theme System** - Light, Dark, and System preference - πŸ”’ **TypeScript** for enhanced developer experience - πŸ“¦ **Production Ready** with optimized build configuration - 🧩 **Component Architecture** for scalable development ## πŸ›  Tech Stack - **Framework**: Next.js 15 (App Router) - **Language**: TypeScript - **Styling**: Tailwind CSS - **Internationalization**: next-intl - **State Management**: React Context API - **Icons**: Optimized SVG components ## πŸ“‹ Prerequisites - Node.js 18 or later ## πŸ”§ Setup & Configuration After creating your project with `create-onetech-app`, follow these steps: ### 1. Install Dependencies ```bash cd my-app npm install ``` ### 2. Start Development Server ```bash npm run dev ``` Open [http://localhost:3000](http://localhost:3000) to see your application running. The app will automatically redirect to your browser's preferred language or default to English. ## 🌐 Internationalization Integration This template comes pre-configured with complete internationalization support: ### Supported Languages | Language | Code | Native Name | File | |----------|------|-------------|------| | English | `en` | English | `public/locales/en.json` | | Hindi | `hi` | ΰ€Ήΰ€Ώΰ€¨ΰ₯ΰ€¦ΰ₯€ | `public/locales/hi.json` | | Telugu | `te` | ఀెలుగు | `public/locales/te.json` | | Spanish | `es` | EspaΓ±ol | `public/locales/es.json` | | German | `de` | Deutsch | `public/locales/de.json` | ### URL Structure The application uses locale-based routing with automatic detection: - `/en` - English version - `/hi` - Hindi version - `/te` - Telugu version - `/es` - Spanish version - `/de` - German version ### Locale Detection - **URL Parameter**: Direct locale from URL path - **Browser Language**: Automatic detection from Accept-Language header - **Fallback**: Default to English if no match found - **Persistence**: User preference saved in browser ### Configuration All internationalization is configured in `src/i18n/routing.ts` and uses environment variables for flexible deployment. ## 🎨 Theme System Built-in theme support with three modes: - **🌞 Light Mode**: Clean, bright interface - **πŸŒ™ Dark Mode**: Easy on the eyes for night coding - **βš™οΈ System Mode**: Automatically follows OS preference - **πŸ’Ύ Persistent**: Saves user preference in localStorage ### Usage Example ```tsx import { useTranslations } from 'next-intl'; import { useTheme } from '@/context/ThemeContext'; export default function MyComponent() { const t = useTranslations(); const { theme, toggleTheme } = useTheme(); return ( <div className="p-4"> <h1>{t('onetech')}</h1> <p>{t('description')}</p> <button onClick={() => toggleTheme(theme === 'dark' ? 'light' : 'dark')} className="p-2 rounded-lg bg-gray-200 dark:bg-gray-800" > {theme === 'dark' ? '🌞' : 'πŸŒ™'} </button> </div> ); } ``` ## πŸ“ Project Structure ``` β”œβ”€β”€ public/ # Static assets β”‚ β”œβ”€β”€ next-intl.svg # next-intl logo β”‚ β”œβ”€β”€ next.svg # Next.js logo β”‚ β”œβ”€β”€ onetech.svg # OneTech logo β”‚ └── locales/ # Translation files β”‚ β”œβ”€β”€ en.json # English translations β”‚ β”œβ”€β”€ hi.json # Hindi translations β”‚ β”œβ”€β”€ te.json # Telugu translations β”‚ β”œβ”€β”€ es.json # Spanish translations β”‚ └── de.json # German translations β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ app/ # Next.js App Router β”‚ β”‚ β”œβ”€β”€ [locale]/ # Locale-based routing β”‚ β”‚ β”‚ β”œβ”€β”€ layout.tsx # Root layout with i18n β”‚ β”‚ β”‚ └── page.tsx # Home page β”‚ β”‚ └── favicon.ico # App favicon β”‚ β”œβ”€β”€ components/ # Reusable UI components β”‚ β”‚ β”œβ”€β”€ LanguageSwitcher.tsx # Language selector β”‚ β”‚ β”œβ”€β”€ Navbar.tsx # Navigation component β”‚ β”‚ └── ThemeToggler.tsx # Dark/light mode toggle β”‚ β”œβ”€β”€ config/ # Configuration files β”‚ β”‚ └── Languages.ts # Supported languages config β”‚ β”œβ”€β”€ context/ # React Context providers β”‚ β”‚ └── theme/ # Theme context modules β”‚ β”œβ”€β”€ hooks/ # Custom React hooks β”‚ β”‚ └── theme/ # Theme-related hooks β”‚ β”œβ”€β”€ i18n/ # Internationalization setup β”‚ β”‚ β”œβ”€β”€ navigation.ts # Internationalized navigation β”‚ β”‚ β”œβ”€β”€ request.ts # Server-side i18n config β”‚ β”‚ └── routing.ts # Routing configuration β”‚ β”œβ”€β”€ styles/ # Global styles β”‚ β”‚ └── globals.css # Global CSS with theme variables β”‚ β”œβ”€β”€ types/ # TypeScript type definitions β”‚ β”‚ └── ThemeMode.ts # Theme type definitions β”‚ β”œβ”€β”€ utils/ # Utility functions β”‚ β”‚ └── location.ts # Location utilities β”‚ └── middleware.ts # Next.js middleware for locale detection β”œβ”€β”€ eslint.config.mjs # ESLint configuration β”œβ”€β”€ next.config.ts # Next.js configuration β”œβ”€β”€ package.json # Dependencies and scripts β”œβ”€β”€ postcss.config.mjs # PostCSS configuration β”œβ”€β”€ README.md # Project documentation └── tsconfig.json # TypeScript configuration ``` ## πŸ› οΈ Key Components ### Language Switcher Seamlessly switch between supported languages: ```tsx import { LanguageSwitcher } from '@/components/LanguageSwitcher'; export default function Header() { return ( <header className="flex justify-between items-center p-4"> <h1>My App</h1> <LanguageSwitcher /> </header> ); } ``` ### Internationalized Navigation Type-safe navigation with locale awareness: ```tsx import { Link, useRouter } from '@/i18n/navigation'; export default function Navigation() { const router = useRouter(); return ( <nav> <Link href="/about">{t('navigation.about')}</Link> <button onClick={() => router.push('/contact')}> {t('navigation.contact')} </button> </nav> ); } ``` ### Adding New Languages 1. **Add the language code to the configuration:** ```typescript // src/config/Languages.ts const localeLanguages = ["en", "hi", "te", "es", "de", "fr"]; // Add French ``` 2. **Create the translation file:** ```bash # Create new locale file touch public/locales/fr.json ``` 3. **Add translations:** ```json { "onetech": "OneTech", "intro": "DΓ©veloppement ultra-rapide avec des outils modernes", "description": "Ce projet utilise Next.js, next-intl et TypeScript..." } ``` ## πŸš€ Available Scripts - `npm run dev` - Start development server with Turbopack - `npm run build` - Build for production - `npm run start` - Start production server - `npm run lint` - Run ESLint ## πŸ“¦ Dependencies ### Core Dependencies - `next` - Next.js framework - `next-intl` - Internationalization for Next.js - `react` & `react-dom` - React library - `@fontsource-variable/outfit` - Typography ### Development Dependencies - `typescript` - Type checking - `tailwindcss` - CSS framework - `eslint` - Code linting - `@types/*` - TypeScript definitions ## πŸš€ Deployment ### Vercel (Recommended) 1. Push your code to GitHub 2. Connect your repository to [Vercel](https://vercel.com) 3. Deploy automatically on every push ### Other Platforms This template works with any hosting platform that supports Next.js: - **Netlify**: Full support with automatic builds - **Railway**: Container-based deployment - **DigitalOcean**: App Platform deployment ## 🀝 Contributing 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add some amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request ## πŸ“š Learn More ### Next.js Resources - [Next.js Documentation](https://nextjs.org/docs) - Learn about Next.js features and API - [Learn Next.js](https://nextjs.org/learn) - Interactive Next.js tutorial - [Next.js GitHub repository](https://github.com/vercel/next.js) ### Internationalization Resources - [next-intl Documentation](https://next-intl-docs.vercel.app/) - Complete i18n guide - [React Intl](https://formatjs.io/docs/react-intl/) - Advanced internationalization patterns - [ICU Message Format](https://unicode-org.github.io/icu/userguide/format_parse/messages/) - Message formatting ### Additional Resources - [Tailwind CSS Documentation](https://tailwindcss.com/docs) - [TypeScript Documentation](https://www.typescriptlang.org/docs/) - [React Documentation](https://react.dev/) ## πŸ™ Acknowledgments This template is part of the OneTech open-source initiative, built with ❀️ for the developer community. ### Core Technologies - [Next.js](https://nextjs.org) - The React Framework for Production - [next-intl](https://next-intl-docs.vercel.app/) - Internationalization for Next.js - [Tailwind CSS](https://tailwindcss.com) - Utility-first CSS framework - [TypeScript](https://typescriptlang.org) - JavaScript with type safety ## πŸ“„ License This project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details. --- <div align="center"> <strong>Built with ❀️ by the OneTech Team</strong><br> <sub>Star ⭐ this repo if you find it helpful!</sub> </div>