@nano_kit/intl
v3.0.0
Published
A lightweight internationalization library for Nano Kit applications.
Maintainers
Readme
@nano_kit/intl
A lightweight internationalization library for Nano Kit applications.
- Reactive. Locale changes update messages through
@nano_kit/storesignals. - Type-safe. Message schemes are checked against translation data.
- Composable. Build messages from small formats like
text,params,plural,match, andnumber. - Tree-shakeable. Import only the formats your app uses.
- SSR-ready. Use
@nano_kit/queryfor cached translation loading and dehydration.
Installation
pnpm add @nano_kit/store @nano_kit/intl
# or
npm install @nano_kit/store @nano_kit/intl
# or
yarn add @nano_kit/store @nano_kit/intlQuick Start
Here is a minimal example with a reactive locale and typed messages:
import {
resolved,
signal
} from '@nano_kit/store'
import {
intl,
params,
plural,
text
} from '@nano_kit/intl'
const $locale = signal<'en' | 'de'>('en')
const { messages } = intl(
$locale,
resolved(() => fetch(`/locales/${$locale()}.json`).then(res => res.json()))
)
const [$t, $loading] = messages('common', {
title: text(),
greeting: params({
name: text()
}),
unread: plural('count')
})
/* Text message */
$t().title
/* Parameterized message */
$t().greeting({
name: 'Ada'
})
/* Pluralized message */
$t().unread({
count: 5
})
/* Switching locale */
$locale('de')Documentation
For comprehensive guides, advanced patterns, and API reference, visit the documentation website.
