@bight-ts/i18n
import { createI18nService, createI18nPlugin, type I18nService,} from "@bight-ts/i18n";createI18nService(options)
Section titled “createI18nService(options)”Creates a locale-aware translation service backed by i18next.
CreateI18nServiceOptions
Section titled “CreateI18nServiceOptions”| Property | Type | Required | Description |
|---|---|---|---|
fallbackLocale | string | Yes | Locale used when the user’s locale isn’t supported |
resources | Record<string, Record<string, unknown>> | Yes | Translation keys per locale |
defaultNamespace | string | No | i18next namespace. Defaults to "translation" |
I18nService
Section titled “I18nService”| Method | Signature | Description |
|---|---|---|
resolveLocale | (input: { locale?, guildLocale? }) => string | Resolves the best matching locale from user/guild locale |
t | (locale, key, values?) => string | Translate a key for a given locale |
forInteraction | (interaction) => { locale, t } | Returns a scoped translator using the interaction’s locale |
exists | (locale, key) => boolean | Check if a translation key exists |
Locale resolution tries: user locale → guild locale → fallback. Partial matches work (e.g, en-GB matches en).
createI18nPlugin(options)
Section titled “createI18nPlugin(options)”Registers a diagnostics source that reports available locales and key counts.
I18nPluginOptions<TServices>
Section titled “I18nPluginOptions<TServices>”| Property | Type | Required | Description |
|---|---|---|---|
getI18n | (context) => I18nService | Yes | Accessor for the i18n service from context |
validateOnStartup | boolean | No | Validate the service was created by createI18nService(). Defaults to true |
reportResources | boolean | No | Include key counts in diagnostic snapshots. Defaults to true |
enabled | boolean | No | Toggle the plugin. Defaults to true |
name | string | No | Plugin name. Defaults to "i18n" |