@xivdyetools/bot-i18n 1.0.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 +99 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/de.json +737 -0
- package/dist/locales/en.json +737 -0
- package/dist/locales/fr.json +737 -0
- package/dist/locales/ja.json +737 -0
- package/dist/locales/ko.json +737 -0
- package/dist/locales/zh.json +737 -0
- package/dist/translator.d.ts +45 -0
- package/dist/translator.d.ts.map +1 -0
- package/dist/translator.js +112 -0
- package/dist/translator.js.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @xivdyetools/bot-i18n
|
|
2
|
+
|
|
3
|
+
> Platform-agnostic translation engine for XIV Dye Tools bot UI strings — error messages, help text, command descriptions, and status messages in 6 languages.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@xivdyetools/bot-i18n)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`@xivdyetools/bot-i18n` provides a lightweight translation engine for bot-facing UI strings (not dye names — those come from `@xivdyetools/core`). Locale data is bundled as static JSON imports, making it compatible with Cloudflare Workers, Node.js, and browsers.
|
|
11
|
+
|
|
12
|
+
**Supported locales:** English (`en`), Japanese (`ja`), German (`de`), French (`fr`), Korean (`ko`), Chinese (`zh`)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @xivdyetools/bot-i18n
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Translator Class
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createTranslator } from '@xivdyetools/bot-i18n';
|
|
26
|
+
|
|
27
|
+
const t = createTranslator('ja');
|
|
28
|
+
|
|
29
|
+
// Simple key lookup (dot notation)
|
|
30
|
+
t.t('common.footer');
|
|
31
|
+
// → "XIV Dye Tools"
|
|
32
|
+
|
|
33
|
+
// With variable interpolation
|
|
34
|
+
t.t('errors.dyeNotFound', { name: 'Snow White' });
|
|
35
|
+
// → 'Could not find a dye named "Snow White".'
|
|
36
|
+
|
|
37
|
+
// Falls back to English for missing keys
|
|
38
|
+
t.t('some.key.only.in.english');
|
|
39
|
+
// → English value (with a warning if logger is provided)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Stateless Translation
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { translate } from '@xivdyetools/bot-i18n';
|
|
46
|
+
|
|
47
|
+
// One-off translation without creating an instance
|
|
48
|
+
const text = translate('en', 'dye.info.detailedInfo', { category: 'Red' });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Locale Utilities
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { getAvailableLocales, isLocaleSupported } from '@xivdyetools/bot-i18n';
|
|
55
|
+
|
|
56
|
+
getAvailableLocales();
|
|
57
|
+
// → ['en', 'ja', 'de', 'fr', 'ko', 'zh']
|
|
58
|
+
|
|
59
|
+
isLocaleSupported('ja'); // → true
|
|
60
|
+
isLocaleSupported('es'); // → false
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
| Export | Kind | Description |
|
|
66
|
+
|--------|------|-------------|
|
|
67
|
+
| `Translator` | class | Locale-bound translator with fallback to English |
|
|
68
|
+
| `createTranslator(locale)` | function | Factory for `Translator` instances |
|
|
69
|
+
| `translate(locale, key, vars?)` | function | Stateless one-off translation |
|
|
70
|
+
| `getAvailableLocales()` | function | Returns array of supported locale codes |
|
|
71
|
+
| `isLocaleSupported(code)` | function | Type guard for locale validation |
|
|
72
|
+
|
|
73
|
+
### Types
|
|
74
|
+
|
|
75
|
+
| Export | Description |
|
|
76
|
+
|--------|-------------|
|
|
77
|
+
| `LocaleCode` | `'en' \| 'ja' \| 'de' \| 'fr' \| 'ko' \| 'zh'` |
|
|
78
|
+
| `LocaleData` | Shape of a locale's translation JSON |
|
|
79
|
+
| `TranslatorLogger` | Optional logger interface for missing-key warnings |
|
|
80
|
+
|
|
81
|
+
## Translation Keys
|
|
82
|
+
|
|
83
|
+
Translation keys use dot notation to navigate the JSON structure:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
common.footer → Footer text
|
|
87
|
+
errors.dyeNotFound → Dye not found message
|
|
88
|
+
dye.info.detailedInfo → Dye info card description
|
|
89
|
+
harmony.title → Harmony wheel title
|
|
90
|
+
gradient.title → Gradient bar title
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Adding Translations
|
|
94
|
+
|
|
95
|
+
Locale files are in `src/locales/*.json`. Each file mirrors the English (`en.json`) structure. Missing keys automatically fall back to English at runtime.
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC"}
|