0.8.1 • Published 7 months ago
international-types v0.8.1
Features
- Autocompletion: For locale keys, scopes and params!
- Extensible: Designed to be used with any library
Note: Using Next.js? Check out next-international!
Usage
pnpm install international-types
Type-safe keys
import type { LocaleKeys } from 'international-types'
type Locale = {
hello: 'Hello'
'hello.world': 'Hello World!'
}
function t<Key extends LocaleKeys<Locale, undefined>>(key: Key) {
// ...
}
t('')
// hello | hello.world
Type-safe scopes with keys
import type { LocaleKeys, Scopes } from 'international-types'
type Locale = {
hello: 'Hello'
'scope.nested.demo': 'Nested scope'
'scope.nested.another.demo': 'Another nested scope'
}
function scopedT<Scope extends Scopes<Locale>>(scope: Scope) {
return function t<Key extends LocaleKeys<Locale, Scope>>(key: Key) {
// ...
}
}
const t = scopedT('')
// scope | scope.nested
t('')
// For scope: nested.demo | nested.another.demo
// For scope.nested: demo | another.demo
Type-safe params
import type { LocaleKeys, BaseLocale, Scopes, ScopedValue, CreateParams, ParamsObject } from 'international-types'
type Locale = {
param: 'This is a {value}'
'hello.people': 'Hello {name}! You are {age} years old.'
}
function scopedT<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined>(scope?: Scope) {
return function t<Key extends LocaleKeys<Locale, Scope>, Value extends ScopedValue<Locale, Scope, Key>>(
key: Key,
...params: CreateParams<ParamsObject<Value>, Locale, Scope, Key, Value>
) {
// ...
}
}
const t = scopedT<Locale, undefined>();
t('param', {
value: ''
// value is required
})
t('hello.people', {
name: '',
age: ''
// name and age are required
})
License
0.8.1
7 months ago
0.8.0
9 months ago
0.6.2
10 months ago
0.5.3
10 months ago
0.5.0
10 months ago
0.7.0
10 months ago
0.6.1
10 months ago
0.5.2
10 months ago
0.6.0
10 months ago
0.5.1
10 months ago
0.4.1
1 year ago
0.4.0
1 year ago
0.3.8
1 year ago
0.3.7
1 year ago
0.3.6
2 years ago
0.3.5
2 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.4
2 years ago
0.3.3
2 years ago
0.3.0
2 years ago
0.2.0
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago