@react-text-game/core 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -1
- package/dist/game.d.ts.map +1 -1
- package/dist/game.js +2 -0
- package/dist/game.js.map +1 -1
- package/dist/i18n/constants.d.ts +21 -0
- package/dist/i18n/constants.d.ts.map +1 -0
- package/dist/i18n/constants.js +21 -0
- package/dist/i18n/constants.js.map +1 -0
- package/dist/i18n/hooks/index.d.ts +13 -0
- package/dist/i18n/hooks/index.d.ts.map +1 -0
- package/dist/i18n/hooks/index.js +13 -0
- package/dist/i18n/hooks/index.js.map +1 -0
- package/dist/i18n/hooks/useGameTranslation.d.ts +81 -0
- package/dist/i18n/hooks/useGameTranslation.d.ts.map +1 -0
- package/dist/i18n/hooks/useGameTranslation.js +102 -0
- package/dist/i18n/hooks/useGameTranslation.js.map +1 -0
- package/dist/i18n/index.d.ts +69 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +69 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/init.d.ts +62 -0
- package/dist/i18n/init.d.ts.map +1 -0
- package/dist/i18n/init.js +114 -0
- package/dist/i18n/init.js.map +1 -0
- package/dist/i18n/types.d.ts +54 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +2 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/i18n/utils.d.ts +55 -0
- package/dist/i18n/utils.d.ts.map +1 -0
- package/dist/i18n/utils.js +69 -0
- package/dist/i18n/utils.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/options.d.ts +2 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +2 -0
- package/dist/options.js.map +1 -1
- package/dist/tests/game.test.js.map +1 -1
- package/dist/tests/i18n.test.d.ts +2 -0
- package/dist/tests/i18n.test.d.ts.map +1 -0
- package/dist/tests/i18n.test.js +590 -0
- package/dist/tests/i18n.test.js.map +1 -0
- package/package.json +16 -5
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ A powerful, reactive text-based game engine built for React applications. This p
|
|
|
11
11
|
- **Factory-Based Entities** - Plain-object factories for beginners with class-based escape hatches
|
|
12
12
|
- **Type-Safe** - Full TypeScript support with comprehensive types
|
|
13
13
|
- **React Hooks** - Built-in hooks for seamless React integration
|
|
14
|
+
- **Internationalization** - i18next-powered translations with automatic language persistence
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
@@ -35,7 +36,21 @@ import { Game, createEntity, newStory } from '@react-text-game/core';
|
|
|
35
36
|
|
|
36
37
|
// IMPORTANT: Initialize the game first
|
|
37
38
|
await Game.init({
|
|
38
|
-
|
|
39
|
+
gameName: 'My Adventure',
|
|
40
|
+
translations: {
|
|
41
|
+
defaultLanguage: 'en',
|
|
42
|
+
fallbackLanguage: 'en',
|
|
43
|
+
resources: {
|
|
44
|
+
en: {
|
|
45
|
+
passages: { intro: 'Welcome to the Game' },
|
|
46
|
+
common: { save: 'Save', load: 'Load' }
|
|
47
|
+
},
|
|
48
|
+
ru: {
|
|
49
|
+
passages: { intro: 'Добро пожаловать в игру' }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
// ...other options
|
|
39
54
|
});
|
|
40
55
|
|
|
41
56
|
// Create a game entity with the factory (recommended)
|
|
@@ -82,6 +97,88 @@ Game.jumpTo(introStory);
|
|
|
82
97
|
|
|
83
98
|
> Prefer writing classes? Jump to [Advanced Entities](#advanced-entities-basegameobject) for a drop-in replacement using inheritance.
|
|
84
99
|
|
|
100
|
+
## Internationalization
|
|
101
|
+
|
|
102
|
+
The core engine ships with first-class i18n based on `i18next` and `react-i18next`. Language preferences are persisted to the save database and automatically restored on load.
|
|
103
|
+
|
|
104
|
+
### Configuring translations
|
|
105
|
+
|
|
106
|
+
Pass an `I18nConfig` via the `translations` field when you call `Game.init()`:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import type { I18nConfig } from '@react-text-game/core/i18n';
|
|
110
|
+
|
|
111
|
+
const translations: I18nConfig = {
|
|
112
|
+
defaultLanguage: 'en',
|
|
113
|
+
fallbackLanguage: 'en',
|
|
114
|
+
debug: false,
|
|
115
|
+
resources: {
|
|
116
|
+
en: {
|
|
117
|
+
passages: { intro: 'Welcome to the game' },
|
|
118
|
+
common: { save: 'Save', load: 'Load' }
|
|
119
|
+
},
|
|
120
|
+
es: {
|
|
121
|
+
passages: { intro: '¡Bienvenido al juego!' }
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
modules: []
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
await Game.init({
|
|
128
|
+
gameName: 'My Adventure',
|
|
129
|
+
translations,
|
|
130
|
+
// ...other options
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- `resources` contains your language namespaces. Users normally keep them in `src/locales/{lang}/{namespace}.json` before importing into the app entry.
|
|
135
|
+
- The engine reads any modules you supply (e.g. `i18next-browser-languagedetector`) and registers them after `initReactI18next`.
|
|
136
|
+
- If you omit `translations`, the engine falls back to an English-only default config.
|
|
137
|
+
|
|
138
|
+
A saved language preference is loaded from the settings store before i18next initializes, so players continue in the language they selected.
|
|
139
|
+
|
|
140
|
+
### Using translations in React
|
|
141
|
+
|
|
142
|
+
Use the `useGameTranslation` hook from `@react-text-game/core/i18n`:
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import { useGameTranslation } from '@react-text-game/core/i18n';
|
|
146
|
+
|
|
147
|
+
export function LanguageSwitcher() {
|
|
148
|
+
const { t, languages, currentLanguage, changeLanguage } = useGameTranslation('common');
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div>
|
|
152
|
+
<p>{t('currentLanguage', { language: currentLanguage })}</p>
|
|
153
|
+
<select value={currentLanguage} onChange={(event) => changeLanguage(event.target.value)}>
|
|
154
|
+
{languages.map((lang) => (
|
|
155
|
+
<option key={lang} value={lang}>
|
|
156
|
+
{lang}
|
|
157
|
+
</option>
|
|
158
|
+
))}
|
|
159
|
+
</select>
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The hook filters out the `cimode` debug language unless you enable `debug` and persists language changes via the save system.
|
|
166
|
+
|
|
167
|
+
### Outside React components
|
|
168
|
+
|
|
169
|
+
For game logic or utilities, grab a namespace-specific translator with `getGameTranslation`:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { getGameTranslation } from '@react-text-game/core/i18n';
|
|
173
|
+
|
|
174
|
+
const t = getGameTranslation('passages');
|
|
175
|
+
const intro = t('forest.description');
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### UI package integration
|
|
179
|
+
|
|
180
|
+
If the optional `@react-text-game/ui` package is installed, the core engine automatically loads its bundled namespaces and merges them with your resources. Your translations override the UI defaults when both provide the same keys, and the engine happily runs without the UI package when you ship a custom interface.
|
|
181
|
+
|
|
85
182
|
## Core Concepts
|
|
86
183
|
|
|
87
184
|
### Game
|
package/dist/game.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"game.d.ts","sourceRoot":"","sources":["../src/game.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"game.d.ts","sourceRoot":"","sources":["../src/game.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,EAAe,UAAU,EAAc,OAAO,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAE,aAAa,EAAY,MAAM,QAAQ,CAAC;AAWjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,IAAI;IACb,OAAO,CAAC,M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AC,cAAc,CAAC;IAIrD;;;;;OAKG;IACH,MAAM,KAAK,SAAS;0BA/LU,MAAM,GAAG,IAAI;MAkM1C;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,IAAI;IAUnB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,IAAI;IAWnB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,UAAQ,GAAG,aAAa;IAY9C;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAU3C;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAWnC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,cAAc,IAAI,IAAI;IA2B7B;;;;;;OAMG;IACH,MAAM,CAAC,eAAe,IAAI,IAAI;IAuB9B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,sBAAsB,IAAI,OAAO;IAoBxC;;;;;;;;;OASG;IACH,MAAM,CAAC,aAAa,IAAI,IAAI;IAM5B;;;;;;;;;;;;;;;;;;;;OAoBG;WACU,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA6ClD;;;;;OAKG;IACH,MAAM,KAAK,OAAO,IAAI,OAAO,CAI5B;IAED;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAM/C;;;;;;;OAOG;IACH,MAAM,CAAC,gBAAgB,IAAI,IAAI;CAgBlC"}
|
package/dist/game.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { proxy, subscribe } from "valtio";
|
|
2
2
|
import { STORAGE_SYSTEM_PATH, SYSTEM_PASSAGE_NAMES } from "./constants";
|
|
3
|
+
import { initI18n } from "./i18n";
|
|
3
4
|
import { logger } from "./logger";
|
|
4
5
|
import { _getOptions, newOptions } from "./options";
|
|
5
6
|
import { createOrUpdateSystemSave } from "./saves";
|
|
@@ -430,6 +431,7 @@ export class Game {
|
|
|
430
431
|
static async init(opts) {
|
|
431
432
|
newOptions(opts);
|
|
432
433
|
Game.initialized = true;
|
|
434
|
+
await initI18n(opts.translations);
|
|
433
435
|
if (Game.options.isDevMode) {
|
|
434
436
|
logger.warn("Game is running in dev mode, do not use in production!");
|
|
435
437
|
}
|
package/dist/game.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"game.js","sourceRoot":"","sources":["../src/game.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,WAAW,EAAc,UAAU,EAAW,MAAM,UAAU,CAAC;AAExE,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,cAAc,GAAG,IAAI,GAAG,EAA0B,CAAC;AACzD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAmB,CAAC;AAEpD,MAAM,QAAQ,GAAG,GAAG,mBAAmB,OAAmC,CAAC;AAM3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,IAAI;IACL,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,gBAAgB,EAAE,IAAqB;KAC1C,CAAC,CAAC;IAEK,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,MAAM,CAAC,eAAe,GAAG,KAAK,CAAC;IAC/B,MAAM,CAAC,SAAS,GAAyC,IAAI,CAAC;IAC9D,MAAM,CAAC,oBAAoB,GAAsB,EAAE,C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CAAC;QAEjD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,wBAAwB,CAAC,YAAY,CAAC,CAAC;QAE7C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC9B,IAAI,CAAC,cAAc,EAAE,CAAC;QAC1B,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,IAAI,CACP,uDAAuD,CAC1D,CAAC;QACN,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,kCAAkC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH,MAAM,KAAK,OAAO;QACd,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,OAAO,WAAW,EAAE,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,OAAmB;QACpC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,UAAU,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,gBAAgB;QACnB,+BAA+B;QAC/B,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACvB,IAAI,CAAC,eAAe,EAAE,CAAC;QAC3B,CAAC;QAED,uBAAuB;QACvB,cAAc,CAAC,KAAK,EAAE,CAAC;QACvB,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAEzB,6BAA6B;QAC7B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAEzB,cAAc;QACd,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACvC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration for the i18n system.
|
|
3
|
+
*
|
|
4
|
+
* This configuration is used when no custom i18n config is provided to `initI18n()`.
|
|
5
|
+
* It sets English as both the default and fallback language, disables debug mode,
|
|
6
|
+
* and provides an empty resources object.
|
|
7
|
+
*
|
|
8
|
+
* @constant
|
|
9
|
+
* @type {I18nConfig}
|
|
10
|
+
* @property {string} defaultLanguage - Set to "en" (English)
|
|
11
|
+
* @property {string} fallbackLanguage - Set to "en" (English)
|
|
12
|
+
* @property {boolean} debug - Set to false (debug mode disabled)
|
|
13
|
+
* @property {object} resources - Empty object (no translations by default)
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_CONFIG: {
|
|
16
|
+
readonly defaultLanguage: "en";
|
|
17
|
+
readonly fallbackLanguage: "en";
|
|
18
|
+
readonly debug: false;
|
|
19
|
+
readonly resources: {};
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/i18n/constants.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc;;;;;CAKI,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration for the i18n system.
|
|
3
|
+
*
|
|
4
|
+
* This configuration is used when no custom i18n config is provided to `initI18n()`.
|
|
5
|
+
* It sets English as both the default and fallback language, disables debug mode,
|
|
6
|
+
* and provides an empty resources object.
|
|
7
|
+
*
|
|
8
|
+
* @constant
|
|
9
|
+
* @type {I18nConfig}
|
|
10
|
+
* @property {string} defaultLanguage - Set to "en" (English)
|
|
11
|
+
* @property {string} fallbackLanguage - Set to "en" (English)
|
|
12
|
+
* @property {boolean} debug - Set to false (debug mode disabled)
|
|
13
|
+
* @property {object} resources - Empty object (no translations by default)
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_CONFIG = {
|
|
16
|
+
defaultLanguage: "en",
|
|
17
|
+
fallbackLanguage: "en",
|
|
18
|
+
debug: false,
|
|
19
|
+
resources: {},
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/i18n/constants.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,IAAI;IACtB,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,EAAE;CACc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module i18n/hooks
|
|
3
|
+
*
|
|
4
|
+
* React hooks for internationalization (i18n) in the game engine.
|
|
5
|
+
*
|
|
6
|
+
* This module exports hooks for accessing translation functionality within React components.
|
|
7
|
+
* The primary hook is `useGameTranslation`, which provides translation functions, language
|
|
8
|
+
* switching capabilities, and access to available languages.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link useGameTranslation} for the main i18n hook
|
|
11
|
+
*/
|
|
12
|
+
export * from './useGameTranslation';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/i18n/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module i18n/hooks
|
|
3
|
+
*
|
|
4
|
+
* React hooks for internationalization (i18n) in the game engine.
|
|
5
|
+
*
|
|
6
|
+
* This module exports hooks for accessing translation functionality within React components.
|
|
7
|
+
* The primary hook is `useGameTranslation`, which provides translation functions, language
|
|
8
|
+
* switching capabilities, and access to available languages.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link useGameTranslation} for the main i18n hook
|
|
11
|
+
*/
|
|
12
|
+
export * from './useGameTranslation';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/i18n/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook for accessing translation functionality within game components.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides a translation function (`t`), the current language, available languages,
|
|
5
|
+
* and a method to change the language. It's the primary way to use i18n in React components.
|
|
6
|
+
*
|
|
7
|
+
* The hook automatically:
|
|
8
|
+
* - Re-renders components when the language changes
|
|
9
|
+
* - Persists language changes to the database
|
|
10
|
+
* - Filters out the "cimode" debug language (unless debug mode is enabled)
|
|
11
|
+
*
|
|
12
|
+
* @param {string} [namespace='passages'] - The translation namespace to use. Defaults to 'passages'.
|
|
13
|
+
* Common namespaces include 'passages', 'common', 'ui', etc.
|
|
14
|
+
*
|
|
15
|
+
* @returns {Object} An object containing translation utilities:
|
|
16
|
+
* @returns {Function} t - Translation function. Call with a key to get the translated string.
|
|
17
|
+
* Supports interpolation, pluralization, and other i18next features.
|
|
18
|
+
* @returns {Function} changeLanguage - Async function to change the current language.
|
|
19
|
+
* Accepts a language code (e.g., 'en', 'ru') and persists
|
|
20
|
+
* the preference to the database.
|
|
21
|
+
* @returns {string} currentLanguage - The currently active language code (e.g., 'en', 'ru').
|
|
22
|
+
* @returns {string[]} languages - Array of available language codes, excluding 'cimode'
|
|
23
|
+
* (unless debug mode is enabled).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Basic usage in a React component
|
|
28
|
+
* function MyPassage() {
|
|
29
|
+
* const { t } = useGameTranslation('passages');
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <div>
|
|
33
|
+
* <h1>{t('intro')}</h1>
|
|
34
|
+
* <p>{t('description')}</p>
|
|
35
|
+
* </div>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* // Language switcher component
|
|
40
|
+
* function LanguageSwitcher() {
|
|
41
|
+
* const { currentLanguage, languages, changeLanguage } = useGameTranslation();
|
|
42
|
+
*
|
|
43
|
+
* return (
|
|
44
|
+
* <select
|
|
45
|
+
* value={currentLanguage}
|
|
46
|
+
* onChange={(e) => changeLanguage(e.target.value)}
|
|
47
|
+
* >
|
|
48
|
+
* {languages.map(lang => (
|
|
49
|
+
* <option key={lang} value={lang}>{lang}</option>
|
|
50
|
+
* ))}
|
|
51
|
+
* </select>
|
|
52
|
+
* );
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* // With interpolation
|
|
56
|
+
* function Greeting() {
|
|
57
|
+
* const { t } = useGameTranslation('common');
|
|
58
|
+
*
|
|
59
|
+
* // Translation: "Hello, {{name}}!"
|
|
60
|
+
* return <p>{t('greeting', { name: 'Player' })}</p>;
|
|
61
|
+
* // Output: "Hello, Player!"
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* // Different namespace
|
|
65
|
+
* function UIComponent() {
|
|
66
|
+
* const { t } = useGameTranslation('ui');
|
|
67
|
+
*
|
|
68
|
+
* return <button>{t('save')}</button>;
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @see {@link initI18n} for initializing the i18n system
|
|
73
|
+
* @see {@link getGameTranslation} for using translations outside React components
|
|
74
|
+
*/
|
|
75
|
+
export declare function useGameTranslation(namespace?: string): {
|
|
76
|
+
t: import("i18next").TFunction<string, undefined>;
|
|
77
|
+
changeLanguage: (lang: string) => Promise<void>;
|
|
78
|
+
currentLanguage: string;
|
|
79
|
+
languages: readonly string[];
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=useGameTranslation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGameTranslation.d.ts","sourceRoot":"","sources":["../../../src/i18n/hooks/useGameTranslation.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,GAAE,MAAmB;;2BASzB,MAAM;;;EAmB7C"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useTranslation } from "react-i18next";
|
|
2
|
+
import { setSetting } from "../../saves/db";
|
|
3
|
+
/**
|
|
4
|
+
* React hook for accessing translation functionality within game components.
|
|
5
|
+
*
|
|
6
|
+
* This hook provides a translation function (`t`), the current language, available languages,
|
|
7
|
+
* and a method to change the language. It's the primary way to use i18n in React components.
|
|
8
|
+
*
|
|
9
|
+
* The hook automatically:
|
|
10
|
+
* - Re-renders components when the language changes
|
|
11
|
+
* - Persists language changes to the database
|
|
12
|
+
* - Filters out the "cimode" debug language (unless debug mode is enabled)
|
|
13
|
+
*
|
|
14
|
+
* @param {string} [namespace='passages'] - The translation namespace to use. Defaults to 'passages'.
|
|
15
|
+
* Common namespaces include 'passages', 'common', 'ui', etc.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Object} An object containing translation utilities:
|
|
18
|
+
* @returns {Function} t - Translation function. Call with a key to get the translated string.
|
|
19
|
+
* Supports interpolation, pluralization, and other i18next features.
|
|
20
|
+
* @returns {Function} changeLanguage - Async function to change the current language.
|
|
21
|
+
* Accepts a language code (e.g., 'en', 'ru') and persists
|
|
22
|
+
* the preference to the database.
|
|
23
|
+
* @returns {string} currentLanguage - The currently active language code (e.g., 'en', 'ru').
|
|
24
|
+
* @returns {string[]} languages - Array of available language codes, excluding 'cimode'
|
|
25
|
+
* (unless debug mode is enabled).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Basic usage in a React component
|
|
30
|
+
* function MyPassage() {
|
|
31
|
+
* const { t } = useGameTranslation('passages');
|
|
32
|
+
*
|
|
33
|
+
* return (
|
|
34
|
+
* <div>
|
|
35
|
+
* <h1>{t('intro')}</h1>
|
|
36
|
+
* <p>{t('description')}</p>
|
|
37
|
+
* </div>
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Language switcher component
|
|
42
|
+
* function LanguageSwitcher() {
|
|
43
|
+
* const { currentLanguage, languages, changeLanguage } = useGameTranslation();
|
|
44
|
+
*
|
|
45
|
+
* return (
|
|
46
|
+
* <select
|
|
47
|
+
* value={currentLanguage}
|
|
48
|
+
* onChange={(e) => changeLanguage(e.target.value)}
|
|
49
|
+
* >
|
|
50
|
+
* {languages.map(lang => (
|
|
51
|
+
* <option key={lang} value={lang}>{lang}</option>
|
|
52
|
+
* ))}
|
|
53
|
+
* </select>
|
|
54
|
+
* );
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* // With interpolation
|
|
58
|
+
* function Greeting() {
|
|
59
|
+
* const { t } = useGameTranslation('common');
|
|
60
|
+
*
|
|
61
|
+
* // Translation: "Hello, {{name}}!"
|
|
62
|
+
* return <p>{t('greeting', { name: 'Player' })}</p>;
|
|
63
|
+
* // Output: "Hello, Player!"
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* // Different namespace
|
|
67
|
+
* function UIComponent() {
|
|
68
|
+
* const { t } = useGameTranslation('ui');
|
|
69
|
+
*
|
|
70
|
+
* return <button>{t('save')}</button>;
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @see {@link initI18n} for initializing the i18n system
|
|
75
|
+
* @see {@link getGameTranslation} for using translations outside React components
|
|
76
|
+
*/
|
|
77
|
+
export function useGameTranslation(namespace = "passages") {
|
|
78
|
+
const { t, i18n } = useTranslation(namespace);
|
|
79
|
+
/**
|
|
80
|
+
* Changes the current language and persists the preference to the database.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} lang - ISO 639-1 language code (e.g., 'en', 'ru', 'de')
|
|
83
|
+
* @returns {Promise<void>}
|
|
84
|
+
*/
|
|
85
|
+
const changeLanguage = async (lang) => {
|
|
86
|
+
await i18n.changeLanguage(lang);
|
|
87
|
+
// Persist language preference to the database
|
|
88
|
+
await setSetting("language", lang);
|
|
89
|
+
};
|
|
90
|
+
const languages = i18n.options.supportedLngs || [];
|
|
91
|
+
// Filter out cimode unless debug is enabled
|
|
92
|
+
const filteredLanguages = i18n.options.debug
|
|
93
|
+
? languages
|
|
94
|
+
: languages.filter((lng) => lng !== "cimode");
|
|
95
|
+
return {
|
|
96
|
+
t,
|
|
97
|
+
changeLanguage,
|
|
98
|
+
currentLanguage: i18n.language,
|
|
99
|
+
languages: filteredLanguages,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=useGameTranslation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGameTranslation.js","sourceRoot":"","sources":["../../../src/i18n/hooks/useGameTranslation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAAoB,UAAU;IAC7D,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAE9C;;;;;OAKG;IACH,MAAM,cAAc,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;QAC1C,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAChC,8CAA8C;QAC9C,MAAM,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,EAAE,CAAC;IAEnD,4CAA4C;IAC5C,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACxC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAElD,OAAO;QACH,CAAC;QACD,cAAc;QACd,eAAe,EAAE,IAAI,CAAC,QAAQ;QAC9B,SAAS,EAAE,iBAAiB;KAC/B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module i18n
|
|
3
|
+
*
|
|
4
|
+
* Internationalization (i18n) module for the @react-text-game/core engine.
|
|
5
|
+
*
|
|
6
|
+
* This module provides a complete i18n solution built on top of i18next and react-i18next,
|
|
7
|
+
* designed specifically for text-based games. It includes:
|
|
8
|
+
*
|
|
9
|
+
* - **Initialization:** `initI18n()` function to set up i18n with custom configurations
|
|
10
|
+
* - **React Hooks:** `useGameTranslation()` hook for accessing translations in components
|
|
11
|
+
* - **Utility Functions:** `getGameTranslation()` for translations outside React components
|
|
12
|
+
* - **Type Definitions:** TypeScript types for i18n configuration
|
|
13
|
+
* - **Auto-loading:** Automatic loading and merging of UI package translations
|
|
14
|
+
* - **Persistence:** Automatic saving and loading of language preferences
|
|
15
|
+
*
|
|
16
|
+
* ## Quick Start
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { initI18n, useGameTranslation } from '@react-text-game/core';
|
|
20
|
+
*
|
|
21
|
+
* // 1. Initialize i18n during game startup
|
|
22
|
+
* await initI18n({
|
|
23
|
+
* defaultLanguage: 'en',
|
|
24
|
+
* fallbackLanguage: 'en',
|
|
25
|
+
* resources: {
|
|
26
|
+
* en: {
|
|
27
|
+
* passages: { intro: 'Welcome to the game' },
|
|
28
|
+
* common: { save: 'Save', load: 'Load' }
|
|
29
|
+
* },
|
|
30
|
+
* ru: {
|
|
31
|
+
* passages: { intro: 'Добро пожаловать в игру' },
|
|
32
|
+
* common: { save: 'Сохранить', load: 'Загрузить' }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // 2. Use translations in React components
|
|
38
|
+
* function MyPassage() {
|
|
39
|
+
* const { t } = useGameTranslation('passages');
|
|
40
|
+
* return <h1>{t('intro')}</h1>;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // 3. Use translations outside React (e.g., in game logic)
|
|
44
|
+
* const t = getGameTranslation('passages');
|
|
45
|
+
* const text = t('intro');
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* ## Organization
|
|
49
|
+
*
|
|
50
|
+
* Translations are organized by **language** and **namespace**:
|
|
51
|
+
*
|
|
52
|
+
* - **Language:** ISO 639-1 language code (e.g., 'en', 'ru', 'de')
|
|
53
|
+
* - **Namespace:** Logical grouping of translations (e.g., 'passages', 'common', 'ui')
|
|
54
|
+
*
|
|
55
|
+
* Common namespaces:
|
|
56
|
+
* - `passages` - Story passages and game content
|
|
57
|
+
* - `common` - Shared text across the game
|
|
58
|
+
* - `ui` - UI-specific text (automatically loaded from UI package if installed)
|
|
59
|
+
*
|
|
60
|
+
* @see {@link initI18n} - Initialize the i18n system
|
|
61
|
+
* @see {@link useGameTranslation} - React hook for translations
|
|
62
|
+
* @see {@link getGameTranslation} - Get translations outside React
|
|
63
|
+
* @see {@link I18nConfig} - Configuration type
|
|
64
|
+
*/
|
|
65
|
+
export * from './hooks';
|
|
66
|
+
export * from './init';
|
|
67
|
+
export * from './types';
|
|
68
|
+
export { getGameTranslation } from './utils';
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module i18n
|
|
3
|
+
*
|
|
4
|
+
* Internationalization (i18n) module for the @react-text-game/core engine.
|
|
5
|
+
*
|
|
6
|
+
* This module provides a complete i18n solution built on top of i18next and react-i18next,
|
|
7
|
+
* designed specifically for text-based games. It includes:
|
|
8
|
+
*
|
|
9
|
+
* - **Initialization:** `initI18n()` function to set up i18n with custom configurations
|
|
10
|
+
* - **React Hooks:** `useGameTranslation()` hook for accessing translations in components
|
|
11
|
+
* - **Utility Functions:** `getGameTranslation()` for translations outside React components
|
|
12
|
+
* - **Type Definitions:** TypeScript types for i18n configuration
|
|
13
|
+
* - **Auto-loading:** Automatic loading and merging of UI package translations
|
|
14
|
+
* - **Persistence:** Automatic saving and loading of language preferences
|
|
15
|
+
*
|
|
16
|
+
* ## Quick Start
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { initI18n, useGameTranslation } from '@react-text-game/core';
|
|
20
|
+
*
|
|
21
|
+
* // 1. Initialize i18n during game startup
|
|
22
|
+
* await initI18n({
|
|
23
|
+
* defaultLanguage: 'en',
|
|
24
|
+
* fallbackLanguage: 'en',
|
|
25
|
+
* resources: {
|
|
26
|
+
* en: {
|
|
27
|
+
* passages: { intro: 'Welcome to the game' },
|
|
28
|
+
* common: { save: 'Save', load: 'Load' }
|
|
29
|
+
* },
|
|
30
|
+
* ru: {
|
|
31
|
+
* passages: { intro: 'Добро пожаловать в игру' },
|
|
32
|
+
* common: { save: 'Сохранить', load: 'Загрузить' }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // 2. Use translations in React components
|
|
38
|
+
* function MyPassage() {
|
|
39
|
+
* const { t } = useGameTranslation('passages');
|
|
40
|
+
* return <h1>{t('intro')}</h1>;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // 3. Use translations outside React (e.g., in game logic)
|
|
44
|
+
* const t = getGameTranslation('passages');
|
|
45
|
+
* const text = t('intro');
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* ## Organization
|
|
49
|
+
*
|
|
50
|
+
* Translations are organized by **language** and **namespace**:
|
|
51
|
+
*
|
|
52
|
+
* - **Language:** ISO 639-1 language code (e.g., 'en', 'ru', 'de')
|
|
53
|
+
* - **Namespace:** Logical grouping of translations (e.g., 'passages', 'common', 'ui')
|
|
54
|
+
*
|
|
55
|
+
* Common namespaces:
|
|
56
|
+
* - `passages` - Story passages and game content
|
|
57
|
+
* - `common` - Shared text across the game
|
|
58
|
+
* - `ui` - UI-specific text (automatically loaded from UI package if installed)
|
|
59
|
+
*
|
|
60
|
+
* @see {@link initI18n} - Initialize the i18n system
|
|
61
|
+
* @see {@link useGameTranslation} - React hook for translations
|
|
62
|
+
* @see {@link getGameTranslation} - Get translations outside React
|
|
63
|
+
* @see {@link I18nConfig} - Configuration type
|
|
64
|
+
*/
|
|
65
|
+
export * from './hooks';
|
|
66
|
+
export * from './init';
|
|
67
|
+
export * from './types';
|
|
68
|
+
export { getGameTranslation } from './utils';
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|