stackping-i18n 0.0.0-stage → 0.1.2
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 +46 -2
- package/dist/index.cjs +825 -0
- package/dist/index.d.cts +266 -0
- package/dist/index.d.ts +266 -0
- package/dist/index.js +791 -0
- package/package.json +45 -4
package/README.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# stackping-i18n
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Translations for StackPing (**az**, **en**, **ru**), shared by `stackping-backend` (API errors,
|
|
4
|
+
emails, later the Telegram bot) and `stackping-client` (the website).
|
|
5
|
+
|
|
6
|
+
## Use
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { createTranslator, resolveLanguage, resources, LANGUAGES, DEFAULT_LANG } from 'stackping-i18n';
|
|
10
|
+
|
|
11
|
+
// Backend: no i18next needed.
|
|
12
|
+
const t = createTranslator(resolveLanguage(req.headers['accept-language']));
|
|
13
|
+
t('errors.skillNotFound', { name: 'Kafka' }); // "Naməlum texnologiya: Kafka."
|
|
14
|
+
t('jobs.count', { count: 5 }); // plural form chosen by language rules
|
|
15
|
+
|
|
16
|
+
// Client: i18next / react-i18next take `resources` as is (namespaces = top-level keys).
|
|
17
|
+
i18n.init({ resources, lng: DEFAULT_LANG, fallbackLng: ['az', 'en'], defaultNS: 'common' });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- Keys are full dotted paths, namespace first: `auth.logIn.title`. `TranslationKey` is the union of
|
|
21
|
+
all of them, so a wrong key does not compile.
|
|
22
|
+
- Plurals follow i18next (`_one`, `_few`, `_many`, `_other`); pass `count` and leave the suffix off.
|
|
23
|
+
- `DEFAULT_LANG` is `az`. Fallback: the language → az → en → the key itself.
|
|
24
|
+
|
|
25
|
+
## Namespaces
|
|
26
|
+
|
|
27
|
+
`common`, `auth`, `profile`, `jobs`, `skills`, `errors`, `validation`, `email`, `bot`.
|
|
28
|
+
|
|
29
|
+
## Adding or changing text
|
|
30
|
+
|
|
31
|
+
1. Edit `src/locales/en.json` (the reference), then the same key in `az.json` and `ru.json`.
|
|
32
|
+
2. `npm run types` regenerates `src/resources.type.ts` from `en.json`.
|
|
33
|
+
3. `npm test` checks that all three languages have the same keys, the plural forms each language
|
|
34
|
+
needs, the same `{{placeholders}}`, and no empty strings. A missing key also fails `typecheck`.
|
|
35
|
+
|
|
36
|
+
## Release
|
|
37
|
+
|
|
38
|
+
The owner publishes by hand:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm version patch # or minor
|
|
42
|
+
npm publish # prepublishOnly: types:check, typecheck, test, build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
CI (`.github/workflows/ci.yml`) runs the same checks plus `npm pack --dry-run`; it never publishes.
|
|
46
|
+
Use Node 22+ (`engines`). Before the first public publish, choose a license (`license` is
|
|
47
|
+
`UNLICENSED` for now).
|