mtcute/packages/i18n
2024-12-03 09:55:37 +03:00
..
src chore: migrate to antfu eslint config (+ reformat) 2024-08-18 07:18:13 +03:00
tests chore: bumped @antfu/eslint-config + reformat 2024-12-03 09:55:37 +03:00
package.json asd 2024-11-20 19:52:39 +03:00
README.md docs: updated packages readmes 2023-11-01 14:05:45 +03:00
tsconfig.json build: build with vite (initial) 2024-08-24 22:55:25 +03:00
typedoc.cjs chore: moved most configs to .config 2023-11-13 13:28:11 +03:00

@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))
})