@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 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
+ [![npm version](https://img.shields.io/npm/v/@xivdyetools/bot-i18n)](https://www.npmjs.com/package/@xivdyetools/bot-i18n)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
@@ -0,0 +1,3 @@
1
+ export type { LocaleCode, LocaleData, TranslatorLogger } from './types.js';
2
+ export { Translator, createTranslator, translate, getAvailableLocales, isLocaleSupported, } from './translator.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,2 @@
1
+ export { Translator, createTranslator, translate, getAvailableLocales, isLocaleSupported, } from './translator.js';
2
+ //# sourceMappingURL=index.js.map
@@ -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"}