π 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.
Stop wrestling with i18n libraries. We've built the one that just works.
π€ AI-Powered Translation Editor - Non-developers can create translations with OpenAI integration. No JSON editing, no technical knowledge required.
β‘ True Zero-Config - Auto-discovers languages, auto-loads translations from static files, auto-detects user preferences. It literally just works.
π 100% Type-Safe - Every translation key is typed with auto-completion. Get suggestions as you type i18n.t('...')
. Typos are compile-time errors.
π¨ Svelte 5 Native - Built with runes from the ground up. Not a port, not a wrapper - pure Svelte 5.
π Global Formatting - Format dates, numbers, currencies for 100+ locales using native Intl API. Zero dependencies.
π¦ Enterprise-Ready - Namespace isolation for micro-frontends, static site generation support, post-build language addition via auto-discovery, comprehensive testing.
πΎ Translation Caching - Save and resume translation work anytime. Browser-based IndexedDB storage keeps your progress safe.
π Flexible Import Options - Import from files, URLs, or resume incomplete translations. Supports multiple source languages for context.
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.
Revolutionary for teams: Translators can add new languages by simply dropping JSON files in /static/translations/
. No code changes, no rebuilds, no deployments.
/static/translations/index.json
:{
"autoDiscovery": {
"app": ["es", "hi", "ko", "pt", "ru"],
"packages": {
"@shelchin/svelte-i18n": ["fr", "zh"]
}
}
}
/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
// In +layout.svelte
onMount(async () => {
await i18n.clientLoad(); // Auto-discovers and loads all translations
});
Result: New languages appear instantly in your app. Perfect for:
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
};
};
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
};
};
// Auto-generated types from your JSON
i18n.t('user.profile.name'); // β
Type-safe
i18n.t('user.profle.name'); // β TypeScript error
i18n.t('items.count', { count: 0 }); // "No items"
i18n.t('items.count', { count: 1 }); // "1 item"
i18n.t('items.count', { count: 5 }); // "5 items"
// 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"
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)
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
Built-in visual editor for non-developers:
<script>
import { TranslationEditor } from '@shelchin/svelte-i18n';
</script>
<TranslationEditor />
Features:
npm install @shelchin/svelte-i18n
// src/lib/i18n.ts
import { setupI18n } from '@shelchin/svelte-i18n';
export const i18n = setupI18n({
defaultLocale: 'en',
fallbackLocale: 'en'
});
// 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 }
});
Create /static/translations/index.json
:
{
"autoDiscovery": {
"app": ["fr", "de", "ja"]
}
}
Then translations are auto-loaded from /static/translations/app/{locale}.json
.
For a complete SSR example with SvelteKit, check out the demo repository.
@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
npx @shelchin/svelte-i18n generate-types
Automatically generates type definitions from your translation files for 100% type safety.
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!
We welcome contributions! Please see our Contributing Guide for details.
# 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
MIT Β© shelchin
Built with β€οΈ using:
Ready to revolutionize your i18n?
Get Started β’ View Demo β’ Star on GitHub