Skip to content

@bight-ts/i18n

import {
createI18nService,
createI18nPlugin,
type I18nService,
} from "@bight-ts/i18n";

Creates a locale-aware translation service backed by i18next.

PropertyTypeRequiredDescription
fallbackLocalestringYesLocale used when the user’s locale isn’t supported
resourcesRecord<string, Record<string, unknown>>YesTranslation keys per locale
defaultNamespacestringNoi18next namespace. Defaults to "translation"
MethodSignatureDescription
resolveLocale(input: { locale?, guildLocale? }) => stringResolves the best matching locale from user/guild locale
t(locale, key, values?) => stringTranslate a key for a given locale
forInteraction(interaction) => { locale, t }Returns a scoped translator using the interaction’s locale
exists(locale, key) => booleanCheck if a translation key exists

Locale resolution tries: user locale → guild locale → fallback. Partial matches work (e.g, en-GB matches en).

Registers a diagnostics source that reports available locales and key counts.

PropertyTypeRequiredDescription
getI18n(context) => I18nServiceYesAccessor for the i18n service from context
validateOnStartupbooleanNoValidate the service was created by createI18nService(). Defaults to true
reportResourcesbooleanNoInclude key counts in diagnostic snapshots. Defaults to true
enabledbooleanNoToggle the plugin. Defaults to true
namestringNoPlugin name. Defaults to "i18n"