Internationalization (i18n)
Since 1.6.0
Types for internationalization and localization.
Overview
Internationalization Types provides types for building multilingual applications including locale management, translations, message formatting, and regional settings. It supports plural rules, date/time formatting, number formatting, and RTL support.
This module enables building type-safe i18n systems with proper constraints for locales, translations, and formatting options.
Basic Usage
typescript
import type { Locale, Translation, TranslationKey, Currency, TimeZone, DateFormat } from 'uni-types'
// Locale configuration
type AppLocale = Locale<{
code: 'en-US'
language: 'en'
country: 'US'
}>
// Translation mapping
type AppTranslation = Translation<{
welcome: TranslationValue
greeting: TranslationValue
}>
// Currency formatting
type PriceFormat = Currency<{
code: 'USD'
symbol: '$'
}>Key Types
LocaleCode
Locale code types.
typescript
type LocaleCode = 'en-US' | 'en-GB' | 'zh-CN' | 'zh-TW' | 'ja-JP' | 'ko-KR' | 'de-DE' | 'fr-FR' | 'es-ES' | 'pt-BR' | 'ru-RU' | 'ar-SA' | 'hi-IN' | stringLanguageCode
Language code types.
typescript
type LanguageCode = 'en' | 'zh' | 'ja' | 'ko' | 'de' | 'fr' | 'es' | 'pt' | 'ru' | 'ar' | 'hi' | 'it' | 'nl' | 'pl' | 'tr' | stringCountryCode
Country code types.
typescript
type CountryCode = 'US' | 'GB' | 'CN' | 'TW' | 'JP' | 'KR' | 'DE' | 'FR' | 'ES' | 'BR' | 'RU' | 'SA' | 'IN' | stringLocale
Locale configuration type.
typescript
type Locale<T = unknown> = {
code: LocaleCode
language: LanguageCode
country?: CountryCode
direction: Direction
config: T
}Direction
Text direction types.
typescript
type Direction = 'ltr' | 'rtl'Translation
Translation mapping type.
typescript
type Translation<T = unknown> = {
locale: LocaleCode
messages: TranslationMap<T>
}PluralForm
Plural form types.
typescript
type PluralForm = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'Currency
Currency types.
typescript
type Currency = 'USD' | 'EUR' | 'GBP' | 'CNY' | 'JPY' | 'KRW' | 'INR' | 'AUD' | 'CAD' | 'CHF' | stringTimeZone
Time zone types.
typescript
type TimeZone = 'UTC' | 'America/New_York' | 'Europe/London' | 'Asia/Shanghai' | 'Asia/Tokyo' | stringDateFormat
Date format configuration.
typescript
type DateFormat = {
format: string
locale: LocaleCode
timeZone?: TimeZone
}NumberFormat
Number format configuration.
typescript
type NumberFormat = {
style: 'decimal' | 'currency' | 'percent'
locale: LocaleCode
currency?: Currency
}