Skip to main content

Function: registerTranslations()

registerTranslations(resources): void

Defined in: registry.ts:47

Registers default translations contributed by a package.

Companion packages (for example @react-text-game/messenger) ship their own namespace of default strings. Registering them here means the game author gets working text without copying resource bundles into Game.init(), while still being able to override any key.

Precedence is: registered package defaults, then @react-text-game/ui defaults, then the author's translations.resources - the author always wins.

Parameters

resources

Resource

i18next resources, keyed by language and then namespace

Returns

void

Remarks

Call order does not matter. Registering before Game.init() folds the resources into the initial i18next configuration; registering afterwards adds them through addResourceBundle without overwriting existing keys. Calling this repeatedly accumulates resources, so several packages can contribute.

Example

import { registerTranslations } from '@react-text-game/core/i18n';

registerTranslations({
en: { myPackage: { greeting: 'Hello' } },
ru: { myPackage: { greeting: 'Привет' } },
});