@shelchin/svelte-i18n

🌍 The Last i18n Library You'll Ever Need for Svelte

Zero-config β€’ Type-safe β€’ AI-powered β€’ Enterprise Features

Demo β€’ Documentation β€’ Translation Editor β€’ δΈ­ζ–‡ζ–‡ζ‘£

[!WARNING] ⚠️ DEVELOPMENT STATUS: This library is currently in active development and is NOT ready for production use.

While we're excited about the features and actively working on stability, please be aware:

  • APIs may change without notice
  • Some features are experimental
  • Bugs and breaking changes are expected

For production applications, please wait for the stable v1.0.0 release.

Feel free to experiment, provide feedback, and contribute! Follow our progress in Issues.


πŸš€ Why @shelchin/svelte-i18n?

Stop wrestling with i18n libraries. We've built the one that just works.

🎯 8 Reasons This Changes Everything:

  1. πŸ€– AI-Powered Translation Editor - Non-developers can create translations with OpenAI integration. No JSON editing, no technical knowledge required.

  2. ⚑ True Zero-Config - Auto-discovers languages, auto-loads translations from static files, auto-detects user preferences. It literally just works.

  3. πŸ”’ 100% Type-Safe - Every translation key is typed with auto-completion. Get suggestions as you type i18n.t('...'). Typos are compile-time errors.

  4. 🎨 Svelte 5 Native - Built with runes from the ground up. Not a port, not a wrapper - pure Svelte 5.

  5. 🌐 Global Formatting - Format dates, numbers, currencies for 100+ locales using native Intl API. Zero dependencies.

  6. πŸ“¦ Enterprise-Ready - Namespace isolation for micro-frontends, static site generation support, post-build language addition via auto-discovery, comprehensive testing.

  7. πŸ’Ύ Translation Caching - Save and resume translation work anytime. Browser-based IndexedDB storage keeps your progress safe.

  8. πŸ“‚ Flexible Import Options - Import from files, URLs, or resume incomplete translations. Supports multiple source languages for context.


πŸ’« Quick Start

npm install @shelchin/svelte-i18n

30 seconds to i18n:

// Setup
import { setupI18n } from '@shelchin/svelte-i18n';

const i18n = setupI18n({
    defaultLocale: 'en'
});

// Use
i18n.t('welcome', { name: 'World' }); // "Welcome, World!"
i18n.formatCurrency(99.99); // "$99.99" / "99,99 €" / "Β₯100"
i18n.formatRelativeTime(-2, 'day'); // "2 days ago" / "hace 2 dΓ­as"

That's it. Seriously.


πŸ” Auto-Discovery: Add Languages Without Touching Code

Revolutionary for teams: Translators can add new languages by simply dropping JSON files in /static/translations/. No code changes, no rebuilds, no deployments.

Setup Auto-Discovery

  1. Create /static/translations/index.json:
{
    "autoDiscovery": {
        "app": ["es", "hi", "ko", "pt", "ru"],
        "packages": {
            "@shelchin/svelte-i18n": ["fr", "zh"]
        }
    }
}
  1. Add translation files:
/static/translations/
β”œβ”€β”€ index.json           # Auto-discovery configuration
β”œβ”€β”€ app/                 # App translations
β”‚   β”œβ”€β”€ es.json
β”‚   β”œβ”€β”€ hi.json
β”‚   β”œβ”€β”€ ko.json
β”‚   β”œβ”€β”€ pt.json
β”‚   └── ru.json
└── @shelchin/svelte-i18n/  # Package translations
    β”œβ”€β”€ fr.json
    └── zh.json
  1. Enable in your app:
// In +layout.svelte
onMount(async () => {
    await i18n.clientLoad(); // Auto-discovers and loads all translations
});

Result: New languages appear instantly in your app. Perfect for:

  • Post-deployment language additions
  • Community translations
  • A/B testing different translations
  • Regional variations

πŸš€ Deployment Options

Static Site Generation (GitHub Pages, Vercel, Netlify)

This library fully supports static site generation with client-side language switching:

// svelte.config.js
import adapter from '@sveltejs/adapter-static';

export default {
    kit: {
        adapter: adapter({
            pages: 'build',
            assets: 'build',
            fallback: '404.html', // Enable client-side routing
            precompress: false,
            strict: true
        }),
        paths: {
            base: process.env.BASE_PATH || '' // For GitHub Pages subdirectory
        }
    }
};
// +layout.ts (not +layout.server.ts for static sites)
export const prerender = true; // Enable prerendering
export const ssr = true;

export const load: LayoutLoad = async () => {
    // Language detection happens on client side
    return {
        locale: i18n.locale,
        locales: i18n.locales
    };
};

Server-Side Rendering (Node.js, Express)

For SSR with cookie-based locale persistence:

// svelte.config.js
import adapter from '@sveltejs/adapter-node';
// +layout.server.ts
export const load: LayoutServerLoad = async ({ cookies }) => {
    await i18n.serverLoad(cookies); // Load locale from cookie
    return {
        locale: i18n.locale,
        locales: i18n.locales
    };
};

πŸ“˜ Core Features

Type-Safe Translations

// Auto-generated types from your JSON
i18n.t('user.profile.name'); // βœ… Type-safe
i18n.t('user.profle.name'); // ❌ TypeScript error

Interpolation & Pluralization

i18n.t('items.count', { count: 0 }); // "No items"
i18n.t('items.count', { count: 1 }); // "1 item"
i18n.t('items.count', { count: 5 }); // "5 items"

Formatting API

// Dates
i18n.formatDate(new Date()); // "January 15, 2024"
i18n.formatDate(new Date(), 'short'); // "1/15/24"

// Numbers
i18n.formatNumber(1234567.89); // "1,234,567.89"
i18n.formatCurrency(99.99, 'EUR'); // "€99.99"
i18n.formatPercent(0.85); // "85%"

// Relative Time
i18n.formatRelativeTime(-1, 'hour'); // "1 hour ago"
i18n.formatRelativeTime(3, 'month'); // "in 3 months"

// Lists
i18n.formatList(['A', 'B', 'C']); // "A, B, and C"

Runtime Validation

Get instant feedback during development:

❌ Translation validation failed for app in locale "ja":
  β€’ Missing translation: demo.title
  β€’ Missing translation: demo.description
  β€’ Invalid translation type: user.age (expected string, got number)

Namespace Isolation

Perfect for micro-frontends and component libraries:

// Component library
const libI18n = setupI18n({
    namespace: '@my-lib/components',
    defaultLocale: 'en'
});

// Main application
const appI18n = setupI18n({
    defaultLocale: 'en'
});

// Translations are completely isolated
libI18n.t('button.label'); // From library translations
appI18n.t('page.title'); // From app translations

🎨 Translation Editor

Built-in visual editor for non-developers:

  1. Import translations from files or URLs
  2. Edit with live preview and validation
  3. Translate with OpenAI integration
  4. Export production-ready JSON files
<script>
    import { TranslationEditor } from '@shelchin/svelte-i18n';
</script>

<TranslationEditor />

Features:

  • πŸ“ Multi-source import (files, URLs, saved sessions)
  • πŸ€– AI-powered translation with OpenAI
  • πŸ’Ύ Automatic session saving with IndexedDB
  • πŸ” Smart search and filtering
  • βœ… Real-time validation
  • πŸ“Š Translation progress tracking
  • 🎯 Side-by-side editing
  • πŸ“₯ One-click export

πŸ› οΈ Installation & Setup

Basic Setup

npm install @shelchin/svelte-i18n
// src/lib/i18n.ts
import { setupI18n } from '@shelchin/svelte-i18n';

export const i18n = setupI18n({
    defaultLocale: 'en',
    fallbackLocale: 'en'
});

With Built-in Translations

// Import your translations
import en from './locales/en.json';
import es from './locales/es.json';

// Register them
import { registerBuiltInTranslations } from '@shelchin/svelte-i18n';

registerBuiltInTranslations({
    app: { en, es }
});

With Auto-Discovery

Create /static/translations/index.json:

{
    "autoDiscovery": {
        "app": ["fr", "de", "ja"]
    }
}

Then translations are auto-loaded from /static/translations/app/{locale}.json.

SSR (Server-Side Rendering) Example

For a complete SSR example with SvelteKit, check out the demo repository.


πŸ“¦ Package Structure

@shelchin/svelte-i18n
β”œβ”€β”€ /components          # Pre-built UI components
β”‚   β”œβ”€β”€ LanguageSwitcher # Dropdown/button language selector
β”‚   β”œβ”€β”€ Trans           # Component with HTML support
β”‚   └── ValidationPopup # Dev-mode validation display
β”œβ”€β”€ /stores             # Reactive stores
β”œβ”€β”€ /cli                # CLI tools for type generation
└── /editor            # Translation editor component

πŸ”§ CLI Tools

Generate TypeScript Definitions

npx @shelchin/svelte-i18n generate-types

Automatically generates type definitions from your translation files for 100% type safety.


🌍 Supported Languages

Built-in support for 100+ locales via the native Intl API. No locale data to ship!

Popular locales include: en, es, fr, de, it, pt, ru, zh, ja, ko, ar, hi, tr, pl, nl, sv, da, no, fi, cs, hu, ro, th, vi, id, ms, tl, he, el, uk, bg, hr, sr, sk, sl, lt, lv, et, is, ga, mt, sq, mk, ka, hy, az, kk, uz, ky, tg, tk, mn, bo, ne, si, my, km, lo, am, ti, or, as, ml, kn, ta, te, gu, mr, pa, bn, ur, ps, fa, and many more!


🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repo
git clone https://github.com/yourusername/svelte-i18n.git
cd svelte-i18n

# Install dependencies
npm install

# Start dev server
npm run dev

# Run tests
npm test

# Build for production
npm run build

πŸ“„ License

MIT Β© shelchin


πŸ™ Acknowledgments

Built with ❀️ using:

  • Svelte 5 - The magical disappearing framework
  • SvelteKit - The fastest way to build apps
  • TypeScript - JavaScript with superpowers
  • Vite - Next generation frontend tooling

πŸ“¬ Support


Ready to revolutionize your i18n?

Get Started β€’ View Demo β€’ Star on GitHub

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes