@mtcute/i18n
TypeScript icon, indicating that this package has built-in type declarations

0.12.0 • Public • Published

@mtcute/i18n

📖 API Reference

Internationalization library built with TypeScript and mtcute in mind.

Features

  • Type-safe: All string keys and parameters are type-checked
  • Plurals: Supports pluralization
  • Customizable: Supports custom locales and customizing existing ones
  • Pluggable: Can be used with any library, not just mtcute. Can also be used with other i18n libraries.

Usage

// i18n/en.ts
export const en = {
    hello: (name: string) => `Hello, ${name}!`,
}

// i18n/ru.ts
export const ru: OtherLanguageWrap<typeof en> = {
    hello: (name: string) => `Привет, ${name}!`,
}

// i18n/index.ts
export const tr = createMtcuteI18n({
    primaryLanguage: {
        name: 'en',
        strings: en,
    },
    otherLanguages: { ru },
})

// main.ts
dp.onNewMessage(async (upd) => {
    await upd.replyText(tr(upd, 'hello', upd.sender.displayName))
})

Readme

Keywords

none

Package Sidebar

Install

npm i @mtcute/i18n

Weekly Downloads

267

Version

0.12.0

License

MIT

Unpacked Size

62.2 kB

Total Files

36

Last publish

Collaborators

  • teidesu