Skip to content

i18n-global/i18nexus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

i18nexus

i18nexus Logo

npm version License: MIT TypeScript

🌍 Type-safe React i18n toolkit with intelligent automation and Server Components support

Features β€’ Quick Start β€’ Documentation β€’ API Reference

English | ν•œκ΅­μ–΄


πŸš€ What is i18nexus?

i18nexus is a comprehensive React internationalization toolkit that automates the entire i18n workflow with full type safety. With TypeScript config support, automatic string wrapping, and seamless Google Sheets integration, i18nexus eliminates tedious manual work while providing IDE autocomplete for language codes.

✨ Key Features

  • 🌐 Accept-Language Auto-Detection - Automatically detects user's browser language
  • 🎨 Variable Interpolation - {{variable}} syntax with styled variables
  • 🎯 Type-Safe Languages - TypeScript config with IDE autocomplete
  • πŸ–₯️ Server Components - Full Next.js App Router support with zero hydration
  • πŸ› οΈ Developer Tools - React Query-style devtools for visual debugging
  • πŸ€– Zero Manual Work - Automatically detect and wrap hardcoded strings
  • πŸͺ Smart Persistence - Cookie-based language management with SSR support

πŸš€ Quick Start

Installation

npm install i18nexus
npm install -D i18nexus-tools  # Recommended for CLI tools

1. Initialize Config (Recommended)

npx i18n-sheets init

Creates i18nexus.config.json:

{
  "languages": ["en", "ko", "ja"],
  "defaultLanguage": "en",
  "localesDir": "./locales",
  "sourcePattern": "app/**/*.{ts,tsx}",
  "translationImportSource": "i18nexus"
}

Note: i18nexus.config.json is the recommended configuration format. TypeScript config (.ts) is legacy and not recommended for new projects.

2. Setup Provider (Next.js App Router)

// app/layout.tsx
import { createServerI18n } from "i18nexus/server";
import { I18nProvider } from "i18nexus";

export default async function RootLayout({ children }) {
  const { language } = await createServerI18n({
    availableLanguages: ["en", "ko", "ja"],
    defaultLanguage: "en",
  });

  return (
    <html lang={language}>
      <body>
        <I18nProvider initialLanguage={language}>{children}</I18nProvider>
      </body>
    </html>
  );
}

3. Use Translations

Server Component:

import { createServerI18n } from "i18nexus/server";

export default async function Page() {
  const { t, language } = await createServerI18n({
    availableLanguages: ["en", "ko", "ja"],
    defaultLanguage: "en",
  });

  return (
    <div>
      <h1>{t("Welcome {{name}}", { name: "User" })}</h1>
      <p>Current: {language}</p>
    </div>
  );
}

Client Component:

"use client";
import { useTranslation } from "i18nexus";

export default function ClientComponent() {
  const { t } = useTranslation();

  return (
    <div>
      <h1>{t("Welcome")}</h1>
      <p>{t("You have {{count}} messages", { count: 5 })}</p>
    </div>
  );
}

πŸ“š Documentation

πŸ“– Complete Documentation

🎯 Feature Guides

πŸ“š API Reference

πŸ“‹ Release Notes


🎯 Core Features

🌐 Accept-Language Auto-Detection

Automatically detects user's browser language from Accept-Language header:

const { t, language } = await createServerI18n({
  availableLanguages: ["en", "ko", "ja", "zh"],
  defaultLanguage: "en",
});

// Detects from:
// 1. Cookie (user preference)
// 2. Accept-Language header (browser setting)
// 3. Default language (fallback)

🎨 Variable Interpolation

Insert dynamic values with {{variable}} syntax:

// Basic
t("Hello {{name}}", { name: "World" });

// Multiple variables
t("{{count}} of {{total}} done", { count: 7, total: 10 });

// With styles (Client Component)
t(
  "Price: {{amount}}",
  { amount: 100 },
  { amount: { color: "red", fontWeight: "bold" } }
);

🎯 Type-Safe Languages

// Define your language type
type AppLanguages = "en" | "ko" | "ja";

const { changeLanguage } = useLanguageSwitcher<AppLanguages>();

changeLanguage("en"); // βœ… Autocomplete!
changeLanguage("fr"); // ❌ Compile error!

πŸ› οΈ Developer Tools

import { I18NexusDevtools } from "i18nexus";

<I18nProvider>
  <App />
  <I18NexusDevtools /> {/* Dev mode only */}
</I18nProvider>;

οΏ½ Type-Safe Setup (v2.11.0+)

Get compile-time key validation with TypeScript:

βœ… Setup (5 minutes)

1. Define your translation keys:

// locales/types.ts
import type { translations } from "./index";
export type AppTranslationKey = keyof typeof translations.ko & string;

2. Create a custom hook:

// hooks/useAppTranslation.ts
import { useTranslation } from "i18nexus";
import type { AppTranslationKey } from "../locales/types";

export function useAppTranslation() {
  return useTranslation<AppTranslationKey>();
}

3. Use everywhere:

import { useAppTranslation } from "./hooks/useAppTranslation";

export function MyComponent() {
  const { t } = useAppTranslation();

  t("greeting"); // βœ… Type-checked
  t("invalid.key"); // ❌ TypeScript Error!

  return <div>{t("greeting")}</div>;
}

πŸ“š Full Setup Guide

For complete setup instructions and patterns, see TYPE_SAFE_SETUP.md


οΏ½πŸ“¦ Package Info

  • Name: i18nexus
  • Version: 2.11.0
  • License: MIT
  • TypeScript: βœ… Full support with type-safe keys
  • Bundle Size: ~15KB (gzipped)

🀝 Contributing

We welcome contributions! Please see our contribution guidelines:

Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated!


πŸ“„ License

MIT License - see LICENSE for details.


πŸ”— Links


Made with ❀️ for the React community

⭐ Star us on GitHub β€’ πŸ“¦ View on npm

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •