sisyo 1.7.0 → 1.9.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.
Files changed (61) hide show
  1. package/LICENSE +16 -16
  2. package/README.md +177 -166
  3. package/bin/known-hashes.json +8 -1
  4. package/bin/sisyo.js +285 -285
  5. package/package.json +30 -30
  6. package/templates/.claude/rules/agents-and-tests.md +32 -24
  7. package/templates/.claude/rules/docs.md +39 -19
  8. package/templates/.claude/skills/fastapi-best-practices/ASYNC-PATTERNS.md +121 -121
  9. package/templates/.claude/skills/fastapi-best-practices/DATABASE.md +153 -153
  10. package/templates/.claude/skills/fastapi-best-practices/DEPENDENCIES.md +140 -140
  11. package/templates/.claude/skills/fastapi-best-practices/PROJECT-STRUCTURE.md +90 -90
  12. package/templates/.claude/skills/fastapi-best-practices/PYDANTIC-GUIDE.md +155 -155
  13. package/templates/.claude/skills/fastapi-best-practices/SKILL.md +123 -123
  14. package/templates/.claude/skills/g6-style/SKILL.md +125 -125
  15. package/templates/.claude/skills/g6-style/references/checks.md +58 -58
  16. package/templates/.claude/skills/g6-style/references/imagery.md +103 -103
  17. package/templates/.claude/skills/g6-style/references/motion.md +121 -121
  18. package/templates/.claude/skills/g6-style/references/sections.md +263 -263
  19. package/templates/.claude/skills/g6-style/references/tokens.md +197 -197
  20. package/templates/.claude/skills/hindsight/SKILL.md +175 -175
  21. package/templates/.claude/skills/hoang-auth/SKILL.md +188 -0
  22. package/templates/.claude/skills/html-docs/SKILL.md +207 -207
  23. package/templates/.claude/skills/i18n-multilang/SKILL.md +153 -153
  24. package/templates/.claude/skills/i18n-multilang/assets/languages.json +47 -47
  25. package/templates/.claude/skills/i18n-multilang/assets/plural-vectors.json +46 -46
  26. package/templates/.claude/skills/i18n-multilang/assets/project/README.md +17 -17
  27. package/templates/.claude/skills/i18n-multilang/assets/project/gitattributes.txt +6 -6
  28. package/templates/.claude/skills/i18n-multilang/assets/project/gitignore.txt +4 -4
  29. package/templates/.claude/skills/i18n-multilang/assets/project/glossary.json +6 -6
  30. package/templates/.claude/skills/i18n-multilang/assets/project/i18n.config.json +22 -22
  31. package/templates/.claude/skills/i18n-multilang/assets/project/locales/__source__/common.json +10 -10
  32. package/templates/.claude/skills/i18n-multilang/assets/project/notes/common.json +5 -5
  33. package/templates/.claude/skills/i18n-multilang/assets/project/style.md +20 -20
  34. package/templates/.claude/skills/i18n-multilang/references/format.md +100 -100
  35. package/templates/.claude/skills/i18n-multilang/references/languages.md +97 -97
  36. package/templates/.claude/skills/i18n-multilang/references/layout-and-versioning.md +256 -256
  37. package/templates/.claude/skills/i18n-multilang/references/numbers.md +161 -161
  38. package/templates/.claude/skills/i18n-multilang/references/platform-unity.md +142 -142
  39. package/templates/.claude/skills/i18n-multilang/references/platform-web.md +107 -107
  40. package/templates/.claude/skills/i18n-multilang/references/translation.md +143 -143
  41. package/templates/.claude/skills/i18n-multilang/references/voice.md +271 -271
  42. package/templates/.claude/skills/i18n-multilang/scripts/i18n.py +1041 -1041
  43. package/templates/.claude/skills/i18n-multilang/scripts/numwords.py +1013 -1013
  44. package/templates/.claude/skills/i18n-multilang/scripts/voice.py +478 -478
  45. package/templates/.claude/skills/neon-game-ui-ux-skill/COMPONENTS.md +490 -490
  46. package/templates/.claude/skills/neon-game-ui-ux-skill/GAMIFICATION.md +246 -246
  47. package/templates/.claude/skills/neon-game-ui-ux-skill/ICONS.md +249 -249
  48. package/templates/.claude/skills/neon-game-ui-ux-skill/LAYOUT-NAV.md +362 -362
  49. package/templates/.claude/skills/neon-game-ui-ux-skill/MOTION-A11Y.md +168 -168
  50. package/templates/.claude/skills/neon-game-ui-ux-skill/SKILL.md +137 -137
  51. package/templates/.claude/skills/neon-game-ui-ux-skill/TOKENS.md +323 -323
  52. package/templates/.claude/skills/react-page-oriented/SKILL.md +407 -407
  53. package/templates/.claude/skills/react-page-oriented/triggers.md +12 -12
  54. package/templates/.claude/skills/terraform-best-practices/SKILL.md +341 -341
  55. package/templates/.claude/skills/typesafe-jev/SKILL.md +148 -148
  56. package/templates/.claude/skills/vibe-docs/SKILL.md +139 -242
  57. package/templates/SISYO.md +39 -37
  58. package/templates/docs/99_progress/features.md +7 -7
  59. package/templates/docs/99_progress/handoff.md +19 -19
  60. package/templates/docs/99_progress/todo.md +15 -15
  61. package/templates/docs/MAP.md +26 -26
@@ -1,142 +1,142 @@
1
- # Unity games
2
-
3
- ## Contents
4
- 1. The runtime contract
5
- 2. Where the files go
6
- 3. Loading and updating packs
7
- 4. Text, fonts and layout
8
- 5. Language setting, picker, the wire
9
- 6. Tests a game must have
10
- 7. Adopting the standard in an existing game
11
-
12
- There is no shared Unity package yet. The first game to implement this contract should write it as a small UPM
13
- package (pure C# core with no engine references + a thin Unity layer), so the second game installs it instead of
14
- copying. Until then each game's own `Loc` class must behave as described here.
15
-
16
- ## 1. The runtime contract
17
-
18
- A game's localisation code does exactly these things, and the same way in every game:
19
-
20
- | Behaviour | Rule |
21
- |---|---|
22
- | Key | `ns:key.path` (a default namespace may be implied). Lookup is a dictionary hit on the pack's flat keys |
23
- | Placeholders | `{{name}}` replaced from named values; an unknown name is left as written and logged in development builds |
24
- | Plurals | with a `count` value: look up `key_<category>` where the category comes from the language's CLDR rule, then `key_other`, then the fallback chain. Port `plural_category()` from `scripts/i18n.py` |
25
- | Fallback | active language (downloaded pack over bundled pack) → the manifest's `fallback` list → source language → the key itself |
26
- | Change | `SetLanguage(code)` raises one event; every visible label re-reads its text in that frame. No restart, no scene reload unless content itself is per-language |
27
- | Formatting | numbers, dates and durations are formatted in code for the active language before they go into a placeholder |
28
- | Safety | a pack is data. Its texts are never evaluated, used as format strings for `string.Format`, or shown as rich text unless the label is meant to hold rich text |
29
-
30
- Minimal API shape (names may follow the game's existing class):
31
-
32
- ```csharp
33
- Loc.T("shop:title");
34
- Loc.T("shop:buy", ("price", price));
35
- Loc.T("shop:items", ("count", n)); // picks shop:items_one / _few / _many / _other
36
- Loc.Language; // "ja", "pt-BR", "zh-Hans"
37
- Loc.SetLanguage("ko"); // event: Loc.Changed
38
- Loc.Available; // ready languages from the manifest: code, name, native, state
39
- ```
40
-
41
- Do not keep a second copy of the source text in code (`Loc.T("key", "Tiếng Việt")`) in new code: the source file is
42
- the single place a text lives, and a test (section 6) catches a key that is missing from it.
43
-
44
- ## 2. Where the files go
45
-
46
- - `i18n/` at the repository root is the source of truth ([layout-and-versioning.md](layout-and-versioning.md)).
47
- - `bundle.copyTo` → `Assets/<Game>/Resources/i18n/`: `pack` writes `<lang>.json` and `manifest.json` there with
48
- stable names. `Resources` is deliberate: packs must be readable synchronously before the first scene on every
49
- platform (on Android, `StreamingAssets` sits inside the APK and needs a web request). Each language is its own
50
- `TextAsset`, so only the active one and its fallbacks are loaded into memory.
51
- - Downloaded packs: `Application.persistentDataPath/i18n/c<compat>/` (`manifest.json`, `<lang>.<hash12>.json`).
52
- - Voice clips: `Application.persistentDataPath/voice/clips/<lang>/…` with the set indexes beside them. A clip is
53
- played only when the hash of the text now shown for that key is in the index entry's `text` list
54
- ([voice.md](voice.md) §9: the index lists the hashes of the texts a clip may be played with); add a test with the
55
- vector given there.
56
- - Never edit the copies under `Assets/`: change `i18n/locales`, run `pack`.
57
-
58
- ## 3. Loading and updating packs
59
-
60
- Start-up (before the first scene, `RuntimeInitializeOnLoadMethod(BeforeSceneLoad)`):
61
- 1. Read the saved language, or choose the default ([languages.md](languages.md)).
62
- 2. Load the bundled manifest; load the downloaded manifest if there is one.
63
- 3. For the language and each fallback, load the copy with the higher `version`; keep the bundled one underneath.
64
-
65
- Background, after the first screen is up, at most once per launch:
66
- 4. `GET <cdn>/i18n/c<compat>/manifest.json` (5 s timeout). On any error: stop silently.
67
- 5. For the active language and every language already downloaded: if the CDN `version` is higher, download `file`,
68
- check SHA-256 against `hash`, write to `*.tmp`, rename over the final name, save the new manifest. Apply on the
69
- next `SetLanguage` or at the next launch; applying immediately is allowed if the screen can refresh.
70
- 6. Delete downloaded packs that are older than the bundled ones (after an app update) and files no manifest names.
71
-
72
- A language that is in the CDN manifest but not in the app (added after the release) is downloaded when the user picks
73
- it: show progress, keep the old language until the hash check passed.
74
-
75
- Addressables content (chapters, models) stays in Addressables. Text packs and voice clips are plain files on purpose:
76
- a new language or a corrected sentence must not need a Unity build.
77
-
78
- ## 4. Text, fonts and layout
79
-
80
- - **Capabilities**: legacy uGUI `Text` and plain TextMeshPro do not shape Arabic, Persian, Urdu, Hindi, Bengali,
81
- Tamil or Thai and do not lay out right-to-left. Leave `capabilities` empty until a shaping solution is in and a
82
- screenshot of real sentences proves it. Those 8 languages are then simply not offered: better than broken text.
83
- - **Fonts**: check every script the product offers on a real device of each platform. The game's own font covers
84
- some scripts (M PLUS Rounded 1c: Latin, Cyrillic, Greek, Japanese); for others a dynamic font falls back to the
85
- operating system's fonts, which usually exist for Korean, Chinese and Thai but look different and can be missing on
86
- desktop. Where the fallback is missing or unacceptable, ship a font for that script (Noto Sans KR / SC / TC / Thai)
87
- as a downloadable asset tied to the language, not inside the base app: a CJK font is 5–10 MB.
88
- - **Layout**: labels grow. Enable best-fit or wrapping with a minimum size on buttons and tabs, never a fixed width
89
- cut to the Vietnamese word. German and Russian are the overflow test; Thai, Korean and Chinese are the font test.
90
- - **Line breaking**: Japanese, Chinese and Thai have no spaces. If the text component breaks only at spaces, insert
91
- zero-width spaces at allowed break points when loading the pack, or keep such texts short.
92
- - Baked labels in scenes and prefabs hold a key (a `LocalizedText` component), not a sentence. Editor builders attach
93
- it when they create a label.
94
- - Text inside textures, videos and 3D signs is content: either keep it language-neutral or treat it as a
95
- per-language asset.
96
-
97
- ## 5. Language setting, picker, the wire
98
-
99
- - Store the language as its **code string** (`"pt-BR"`), in settings and in every network message. An enum or a byte
100
- cannot name a language added by a download.
101
- - Default on first launch: the device's ordered language list, matched against the ready languages
102
- ([languages.md](languages.md)). Read the list natively (iOS `NSLocale.preferredLanguages`, Android
103
- `LocaleList.getDefault()`); `Application.systemLanguage` is the fallback.
104
- - An install that already has a saved language keeps it through updates.
105
- - The picker: searchable list, rows `English name (native name)`, state per row, globe icon
106
- ([languages.md](languages.md)).
107
- - **Server-written texts** (refusals, notices): the server sends `key` + named values and the client renders them in
108
- its own language. The server then needs no translation tables and speaks all 40 languages at once. For old clients,
109
- keep sending a rendered source-language string beside the key until they are gone. A protocol change follows the
110
- project's own contract rules.
111
- - iOS: put the ready languages in `CFBundleLocalizations` (post-process the Xcode project). Android: `locales_config`.
112
-
113
- ## 6. Tests a game must have
114
-
115
- | Test | Catches |
116
- |---|---|
117
- | EditMode: `python i18n.py check` exits 0 (run it from the test or from the build script) | broken placeholders, missing plural forms, forbidden words |
118
- | EditMode: every key the code uses exists in the source (extract `Loc.T("…")` literals and keys held by `LocalizedText`) | a typo in a key, a deleted text still in use |
119
- | EditMode: the C# plural rule returns the category in `assets/plural-vectors.json` for every language and number | a wrong plural port |
120
- | EditMode: bundled `manifest.json` hashes equal the SHA-256 of the bundled files | a hand-edited copy under `Assets/` |
121
- | PlayMode: for each ready language, open the main screens and capture them | overflow, missing glyphs (tofu boxes), untranslated labels |
122
- | PlayMode: first launch with device language X selects X (inject the device list) | default-language regressions |
123
- | Device: download of a newer pack with the network cut mid-way leaves the old pack working | update safety |
124
-
125
- ## 7. Adopting the standard in an existing game
126
-
127
- Do it as its own approved piece of work, never in passing while changing something else. Re-read the game's
128
- localisation code first: the table lists what such code usually looks like and where it goes.
129
-
130
- | Usually found | Standard |
131
- |---|---|
132
- | string tables under `Assets/…/Resources/`, one per language, sometimes wrapped (`{"language": …, "strings": {…}}`) | `i18n/locales/<lang>/<ns>.json` holding the strings only; `pack` writes the bundle copies back under `Resources/i18n/` |
133
- | the source text also written in code (`Loc.T("key", "source text")`) and pulled out by an extractor | keep the extractor for now and point its output at `i18n/locales/<source>/`; new code uses keys only |
134
- | positional `{0}` or single-brace `{name}` placeholders | `{{name}}`: convert the files and the formatter in one commit, with its tests ([format.md](format.md), legacy formats) |
135
- | languages hard-coded in an array or an `enum`, sometimes sent over the network as a byte | the manifest decides the list; the language is a code string in settings and on the wire (a contract change) |
136
- | a server-side table with one column per language | a `server` namespace in the locales; the server sends key + values |
137
- | "write the sentence so one form fits every number" | plural keys wherever a count is shown, before adding a language that needs them |
138
- | product rules about words (a word that must never be shown, names never translated) | `glossary.json`: `forbidden`, `keep` |
139
- | translations that already exist | check them, then `i18n.py stamp --all` |
140
- | voice clips inside the app | they may stay; a new voice language is CDN-only, so the player needs a path that plays downloaded clips |
141
- | numbers composed from recorded pieces by per-language code | the reading rules as data, tested against `numwords.py` with the product's `numberStyle` |
142
- | a content CDN that already serves other downloads | add the `i18n/` and `voice/` prefixes and their cache behaviours ([layout-and-versioning.md](layout-and-versioning.md) §7) |
1
+ # Unity games
2
+
3
+ ## Contents
4
+ 1. The runtime contract
5
+ 2. Where the files go
6
+ 3. Loading and updating packs
7
+ 4. Text, fonts and layout
8
+ 5. Language setting, picker, the wire
9
+ 6. Tests a game must have
10
+ 7. Adopting the standard in an existing game
11
+
12
+ There is no shared Unity package yet. The first game to implement this contract should write it as a small UPM
13
+ package (pure C# core with no engine references + a thin Unity layer), so the second game installs it instead of
14
+ copying. Until then each game's own `Loc` class must behave as described here.
15
+
16
+ ## 1. The runtime contract
17
+
18
+ A game's localisation code does exactly these things, and the same way in every game:
19
+
20
+ | Behaviour | Rule |
21
+ |---|---|
22
+ | Key | `ns:key.path` (a default namespace may be implied). Lookup is a dictionary hit on the pack's flat keys |
23
+ | Placeholders | `{{name}}` replaced from named values; an unknown name is left as written and logged in development builds |
24
+ | Plurals | with a `count` value: look up `key_<category>` where the category comes from the language's CLDR rule, then `key_other`, then the fallback chain. Port `plural_category()` from `scripts/i18n.py` |
25
+ | Fallback | active language (downloaded pack over bundled pack) → the manifest's `fallback` list → source language → the key itself |
26
+ | Change | `SetLanguage(code)` raises one event; every visible label re-reads its text in that frame. No restart, no scene reload unless content itself is per-language |
27
+ | Formatting | numbers, dates and durations are formatted in code for the active language before they go into a placeholder |
28
+ | Safety | a pack is data. Its texts are never evaluated, used as format strings for `string.Format`, or shown as rich text unless the label is meant to hold rich text |
29
+
30
+ Minimal API shape (names may follow the game's existing class):
31
+
32
+ ```csharp
33
+ Loc.T("shop:title");
34
+ Loc.T("shop:buy", ("price", price));
35
+ Loc.T("shop:items", ("count", n)); // picks shop:items_one / _few / _many / _other
36
+ Loc.Language; // "ja", "pt-BR", "zh-Hans"
37
+ Loc.SetLanguage("ko"); // event: Loc.Changed
38
+ Loc.Available; // ready languages from the manifest: code, name, native, state
39
+ ```
40
+
41
+ Do not keep a second copy of the source text in code (`Loc.T("key", "Tiếng Việt")`) in new code: the source file is
42
+ the single place a text lives, and a test (section 6) catches a key that is missing from it.
43
+
44
+ ## 2. Where the files go
45
+
46
+ - `i18n/` at the repository root is the source of truth ([layout-and-versioning.md](layout-and-versioning.md)).
47
+ - `bundle.copyTo` → `Assets/<Game>/Resources/i18n/`: `pack` writes `<lang>.json` and `manifest.json` there with
48
+ stable names. `Resources` is deliberate: packs must be readable synchronously before the first scene on every
49
+ platform (on Android, `StreamingAssets` sits inside the APK and needs a web request). Each language is its own
50
+ `TextAsset`, so only the active one and its fallbacks are loaded into memory.
51
+ - Downloaded packs: `Application.persistentDataPath/i18n/c<compat>/` (`manifest.json`, `<lang>.<hash12>.json`).
52
+ - Voice clips: `Application.persistentDataPath/voice/clips/<lang>/…` with the set indexes beside them. A clip is
53
+ played only when the hash of the text now shown for that key is in the index entry's `text` list
54
+ ([voice.md](voice.md) §9: the index lists the hashes of the texts a clip may be played with); add a test with the
55
+ vector given there.
56
+ - Never edit the copies under `Assets/`: change `i18n/locales`, run `pack`.
57
+
58
+ ## 3. Loading and updating packs
59
+
60
+ Start-up (before the first scene, `RuntimeInitializeOnLoadMethod(BeforeSceneLoad)`):
61
+ 1. Read the saved language, or choose the default ([languages.md](languages.md)).
62
+ 2. Load the bundled manifest; load the downloaded manifest if there is one.
63
+ 3. For the language and each fallback, load the copy with the higher `version`; keep the bundled one underneath.
64
+
65
+ Background, after the first screen is up, at most once per launch:
66
+ 4. `GET <cdn>/i18n/c<compat>/manifest.json` (5 s timeout). On any error: stop silently.
67
+ 5. For the active language and every language already downloaded: if the CDN `version` is higher, download `file`,
68
+ check SHA-256 against `hash`, write to `*.tmp`, rename over the final name, save the new manifest. Apply on the
69
+ next `SetLanguage` or at the next launch; applying immediately is allowed if the screen can refresh.
70
+ 6. Delete downloaded packs that are older than the bundled ones (after an app update) and files no manifest names.
71
+
72
+ A language that is in the CDN manifest but not in the app (added after the release) is downloaded when the user picks
73
+ it: show progress, keep the old language until the hash check passed.
74
+
75
+ Addressables content (chapters, models) stays in Addressables. Text packs and voice clips are plain files on purpose:
76
+ a new language or a corrected sentence must not need a Unity build.
77
+
78
+ ## 4. Text, fonts and layout
79
+
80
+ - **Capabilities**: legacy uGUI `Text` and plain TextMeshPro do not shape Arabic, Persian, Urdu, Hindi, Bengali,
81
+ Tamil or Thai and do not lay out right-to-left. Leave `capabilities` empty until a shaping solution is in and a
82
+ screenshot of real sentences proves it. Those 8 languages are then simply not offered: better than broken text.
83
+ - **Fonts**: check every script the product offers on a real device of each platform. The game's own font covers
84
+ some scripts (M PLUS Rounded 1c: Latin, Cyrillic, Greek, Japanese); for others a dynamic font falls back to the
85
+ operating system's fonts, which usually exist for Korean, Chinese and Thai but look different and can be missing on
86
+ desktop. Where the fallback is missing or unacceptable, ship a font for that script (Noto Sans KR / SC / TC / Thai)
87
+ as a downloadable asset tied to the language, not inside the base app: a CJK font is 5–10 MB.
88
+ - **Layout**: labels grow. Enable best-fit or wrapping with a minimum size on buttons and tabs, never a fixed width
89
+ cut to the Vietnamese word. German and Russian are the overflow test; Thai, Korean and Chinese are the font test.
90
+ - **Line breaking**: Japanese, Chinese and Thai have no spaces. If the text component breaks only at spaces, insert
91
+ zero-width spaces at allowed break points when loading the pack, or keep such texts short.
92
+ - Baked labels in scenes and prefabs hold a key (a `LocalizedText` component), not a sentence. Editor builders attach
93
+ it when they create a label.
94
+ - Text inside textures, videos and 3D signs is content: either keep it language-neutral or treat it as a
95
+ per-language asset.
96
+
97
+ ## 5. Language setting, picker, the wire
98
+
99
+ - Store the language as its **code string** (`"pt-BR"`), in settings and in every network message. An enum or a byte
100
+ cannot name a language added by a download.
101
+ - Default on first launch: the device's ordered language list, matched against the ready languages
102
+ ([languages.md](languages.md)). Read the list natively (iOS `NSLocale.preferredLanguages`, Android
103
+ `LocaleList.getDefault()`); `Application.systemLanguage` is the fallback.
104
+ - An install that already has a saved language keeps it through updates.
105
+ - The picker: searchable list, rows `English name (native name)`, state per row, globe icon
106
+ ([languages.md](languages.md)).
107
+ - **Server-written texts** (refusals, notices): the server sends `key` + named values and the client renders them in
108
+ its own language. The server then needs no translation tables and speaks all 40 languages at once. For old clients,
109
+ keep sending a rendered source-language string beside the key until they are gone. A protocol change follows the
110
+ project's own contract rules.
111
+ - iOS: put the ready languages in `CFBundleLocalizations` (post-process the Xcode project). Android: `locales_config`.
112
+
113
+ ## 6. Tests a game must have
114
+
115
+ | Test | Catches |
116
+ |---|---|
117
+ | EditMode: `python i18n.py check` exits 0 (run it from the test or from the build script) | broken placeholders, missing plural forms, forbidden words |
118
+ | EditMode: every key the code uses exists in the source (extract `Loc.T("…")` literals and keys held by `LocalizedText`) | a typo in a key, a deleted text still in use |
119
+ | EditMode: the C# plural rule returns the category in `assets/plural-vectors.json` for every language and number | a wrong plural port |
120
+ | EditMode: bundled `manifest.json` hashes equal the SHA-256 of the bundled files | a hand-edited copy under `Assets/` |
121
+ | PlayMode: for each ready language, open the main screens and capture them | overflow, missing glyphs (tofu boxes), untranslated labels |
122
+ | PlayMode: first launch with device language X selects X (inject the device list) | default-language regressions |
123
+ | Device: download of a newer pack with the network cut mid-way leaves the old pack working | update safety |
124
+
125
+ ## 7. Adopting the standard in an existing game
126
+
127
+ Do it as its own approved piece of work, never in passing while changing something else. Re-read the game's
128
+ localisation code first: the table lists what such code usually looks like and where it goes.
129
+
130
+ | Usually found | Standard |
131
+ |---|---|
132
+ | string tables under `Assets/…/Resources/`, one per language, sometimes wrapped (`{"language": …, "strings": {…}}`) | `i18n/locales/<lang>/<ns>.json` holding the strings only; `pack` writes the bundle copies back under `Resources/i18n/` |
133
+ | the source text also written in code (`Loc.T("key", "source text")`) and pulled out by an extractor | keep the extractor for now and point its output at `i18n/locales/<source>/`; new code uses keys only |
134
+ | positional `{0}` or single-brace `{name}` placeholders | `{{name}}`: convert the files and the formatter in one commit, with its tests ([format.md](format.md), legacy formats) |
135
+ | languages hard-coded in an array or an `enum`, sometimes sent over the network as a byte | the manifest decides the list; the language is a code string in settings and on the wire (a contract change) |
136
+ | a server-side table with one column per language | a `server` namespace in the locales; the server sends key + values |
137
+ | "write the sentence so one form fits every number" | plural keys wherever a count is shown, before adding a language that needs them |
138
+ | product rules about words (a word that must never be shown, names never translated) | `glossary.json`: `forbidden`, `keep` |
139
+ | translations that already exist | check them, then `i18n.py stamp --all` |
140
+ | voice clips inside the app | they may stay; a new voice language is CDN-only, so the player needs a path that plays downloaded clips |
141
+ | numbers composed from recorded pieces by per-language code | the reading rules as data, tested against `numwords.py` with the product's `numberStyle` |
142
+ | a content CDN that already serves other downloads | add the `i18n/` and `voice/` prefixes and their cache behaviours ([layout-and-versioning.md](layout-and-versioning.md) §7) |
@@ -1,107 +1,107 @@
1
- # Web and apps (i18next)
2
-
3
- The standard format **is** i18next's, so a site that already uses `i18next`, `react-i18next` or `next-i18next` needs
4
- configuration, not conversion.
5
-
6
- ## Project setup
7
-
8
- - `i18n/` at the repository root as everywhere ([layout-and-versioning.md](layout-and-versioning.md)), or point
9
- `localesDir` / `layout` at the folder the site already has:
10
- - one file per language (`src/i18n/locales/en.json`): `"layout": "{lang}.json"` (namespace `translation`)
11
- - per namespace (`public/locales/en/common.json`): `"layout": "{lang}/{ns}.json"`
12
- - `capabilities: ["rtl", "shaping"]`: browsers render every script. All 40 languages are open, provided the layout is
13
- checked right-to-left (below).
14
- - Use the registry codes. A site that used `jp` renames the folder to `ja` and redirects old URLs.
15
-
16
- ## i18next configuration
17
-
18
- ```ts
19
- import i18n from 'i18next'
20
- import { initReactI18next } from 'react-i18next'
21
- import manifest from '../../i18n/manifest.json' // written by "i18n.py pack"
22
-
23
- const ready = Object.entries(manifest.languages).filter(([, l]) => l.status === 'ready').map(([code]) => code)
24
- const fallbackLng = Object.fromEntries(
25
- Object.entries(manifest.languages).map(([code, l]) => [code, l.fallback]),
26
- )
27
-
28
- i18n.use(initReactI18next).init({
29
- lng: pickLanguage(ready), // below
30
- supportedLngs: ready,
31
- fallbackLng: { ...fallbackLng, default: [manifest.fallbackLanguage] },
32
- load: 'currentOnly', // "pt-BR" is a language, not "pt" + region
33
- ns: ['common'], defaultNS: 'common',
34
- interpolation: { escapeValue: false }, // React escapes; keep the default {{ }} delimiters
35
- returnNull: false,
36
- })
37
- ```
38
-
39
- Keep i18next's defaults for everything the format relies on: `{{ }}` interpolation, `:` namespace separator, `.` key
40
- separator, `_` plural separator, JSON v4 plurals.
41
-
42
- Loading the texts, by size of the site:
43
- - **Small site**: import the JSON of each language lazily (`import.meta.glob('../../i18n/locales/*/*.json')` in
44
- Vite, dynamic `import()` elsewhere) and `i18n.addResourceBundle(lng, ns, data)`. Nothing is fetched at runtime.
45
- - **Larger site / translations updated without a deploy**: `i18next-http-backend` with
46
- `loadPath: '<cdn>/locales/{{lng}}/{{ns}}.json'` (the repository layout served as is), or fetch the pack file named
47
- in the CDN manifest and add each namespace: `Object.entries(pack.strings).forEach(([ns, s]) =>
48
- i18n.addResourceBundle(lng, ns, s, true, true))`. Flat dotted keys in the pack are read by i18next as they are.
49
- - **Next.js**: `next-i18next` or the App Router's own i18n routing with the same files; locales list from the
50
- manifest.
51
-
52
- ## Choosing the language
53
-
54
- ```ts
55
- function pickLanguage(ready: string[], wantedList = navigator.languages ?? [navigator.language]): string {
56
- const find = (code?: string) => code && ready.find(r => r.toLowerCase() === code.toLowerCase())
57
- const saved = find(localStorage.getItem('lang') ?? undefined)
58
- if (saved) return saved
59
- const alias = (code: string) => Object.keys(manifest.languages).find(k =>
60
- (manifest.languages[k].aliases ?? []).some(a => a.toLowerCase() === code.toLowerCase()))
61
- for (const wanted of wantedList) {
62
- let loc: Intl.Locale
63
- try { loc = new Intl.Locale(wanted).maximize() } catch { continue } // zh-TW -> zh-Hant-TW
64
- const hit = find(wanted) ?? find(alias(wanted)) ?? find(`${loc.language}-${loc.script}`)
65
- ?? find(loc.language) ?? find(alias(loc.language))
66
- ?? (loc.language === 'zh' ? undefined : ready.find(r => r.split('-')[0] === loc.language))
67
- if (hit) return hit // es-MX -> es; pt-PT -> pt-BR when that is the only Portuguese
68
- }
69
- return find('en') ?? manifest.sourceLanguage
70
- }
71
- ```
72
-
73
- This is the matching rule of [languages.md](languages.md) in code (tested on zh-TW, zh-MY, pt-PT, es-MX, no, iw, tl
74
- and others); a game ports the same steps. Save the choice when the user changes it (`localStorage`, and the account
75
- profile if there is one). A URL that names a language (`/ja/…`) wins over both.
76
-
77
- ## Page-level rules
78
-
79
- - `<html lang="{code}" dir="{ltr|rtl}">` updated on every language change (`dir` comes from the manifest).
80
- - Right-to-left: use logical CSS (`margin-inline-start`, `padding-inline-end`, `text-align: start`), flip directional
81
- icons, test one Arabic page before declaring it done.
82
- - Language switcher: the same picker rules as the games ([languages.md](languages.md)): searchable, rows
83
- `English name (native name)`, a globe icon. `Intl.DisplayNames` may add the name in the current language as a third
84
- search term.
85
- - Numbers, dates, currency, lists and relative times: `Intl.NumberFormat`, `Intl.DateTimeFormat`, `Intl.ListFormat`,
86
- `Intl.RelativeTimeFormat` with the active language, then pass the result into a `{{placeholder}}`.
87
- - Fonts: a font stack with system CJK / Thai / Arabic fallbacks; do not ship one webfont for all scripts.
88
- - SEO for public pages: one URL per language (`/en/…`, `/ja/…`), `<link rel="alternate" hreflang="…">` for every
89
- ready language plus `x-default`, translated `<title>` and meta description (keep them in a `seo` namespace), and a
90
- sitemap that lists the alternates. Static sites are generated per language from the same
91
- locale files at build.
92
- - Never build a sentence in JSX from fragments; use one key with placeholders, or `<Trans>` when markup must sit
93
- inside the sentence (web-only namespace, see [format.md](format.md)).
94
-
95
- ## Checks for a web project
96
-
97
- - `python i18n.py check` in CI; `i18n.py pack` before a release so `manifest.json` is current.
98
- - A script (or `i18next-parser` in check mode) that fails when the code uses a key the source lacks.
99
- - A visual pass per new language on the main pages at phone width: overflow, clipped buttons, mixed directions.
100
-
101
- ## Apps
102
-
103
- | App type | How it uses the standard |
104
- |---|---|
105
- | React Native, Electron, Capacitor | i18next exactly as above; packs bundled, optional CDN update |
106
- | Native iOS / Android, Flutter | the texts are still authored in `i18n/locales` (one source, same translation loop). No exporter exists yet: when the first such app appears, add an export step to `pack` that writes `.xcstrings` / `strings.xml` / `.arb` from the locale files, and keep those generated files out of hand editing |
107
- | Store listing (name, subtitle, description, keywords, what's new) | a `store` namespace translated with the same loop; note the stores' length limits in `notes/store.json` |
1
+ # Web and apps (i18next)
2
+
3
+ The standard format **is** i18next's, so a site that already uses `i18next`, `react-i18next` or `next-i18next` needs
4
+ configuration, not conversion.
5
+
6
+ ## Project setup
7
+
8
+ - `i18n/` at the repository root as everywhere ([layout-and-versioning.md](layout-and-versioning.md)), or point
9
+ `localesDir` / `layout` at the folder the site already has:
10
+ - one file per language (`src/i18n/locales/en.json`): `"layout": "{lang}.json"` (namespace `translation`)
11
+ - per namespace (`public/locales/en/common.json`): `"layout": "{lang}/{ns}.json"`
12
+ - `capabilities: ["rtl", "shaping"]`: browsers render every script. All 40 languages are open, provided the layout is
13
+ checked right-to-left (below).
14
+ - Use the registry codes. A site that used `jp` renames the folder to `ja` and redirects old URLs.
15
+
16
+ ## i18next configuration
17
+
18
+ ```ts
19
+ import i18n from 'i18next'
20
+ import { initReactI18next } from 'react-i18next'
21
+ import manifest from '../../i18n/manifest.json' // written by "i18n.py pack"
22
+
23
+ const ready = Object.entries(manifest.languages).filter(([, l]) => l.status === 'ready').map(([code]) => code)
24
+ const fallbackLng = Object.fromEntries(
25
+ Object.entries(manifest.languages).map(([code, l]) => [code, l.fallback]),
26
+ )
27
+
28
+ i18n.use(initReactI18next).init({
29
+ lng: pickLanguage(ready), // below
30
+ supportedLngs: ready,
31
+ fallbackLng: { ...fallbackLng, default: [manifest.fallbackLanguage] },
32
+ load: 'currentOnly', // "pt-BR" is a language, not "pt" + region
33
+ ns: ['common'], defaultNS: 'common',
34
+ interpolation: { escapeValue: false }, // React escapes; keep the default {{ }} delimiters
35
+ returnNull: false,
36
+ })
37
+ ```
38
+
39
+ Keep i18next's defaults for everything the format relies on: `{{ }}` interpolation, `:` namespace separator, `.` key
40
+ separator, `_` plural separator, JSON v4 plurals.
41
+
42
+ Loading the texts, by size of the site:
43
+ - **Small site**: import the JSON of each language lazily (`import.meta.glob('../../i18n/locales/*/*.json')` in
44
+ Vite, dynamic `import()` elsewhere) and `i18n.addResourceBundle(lng, ns, data)`. Nothing is fetched at runtime.
45
+ - **Larger site / translations updated without a deploy**: `i18next-http-backend` with
46
+ `loadPath: '<cdn>/locales/{{lng}}/{{ns}}.json'` (the repository layout served as is), or fetch the pack file named
47
+ in the CDN manifest and add each namespace: `Object.entries(pack.strings).forEach(([ns, s]) =>
48
+ i18n.addResourceBundle(lng, ns, s, true, true))`. Flat dotted keys in the pack are read by i18next as they are.
49
+ - **Next.js**: `next-i18next` or the App Router's own i18n routing with the same files; locales list from the
50
+ manifest.
51
+
52
+ ## Choosing the language
53
+
54
+ ```ts
55
+ function pickLanguage(ready: string[], wantedList = navigator.languages ?? [navigator.language]): string {
56
+ const find = (code?: string) => code && ready.find(r => r.toLowerCase() === code.toLowerCase())
57
+ const saved = find(localStorage.getItem('lang') ?? undefined)
58
+ if (saved) return saved
59
+ const alias = (code: string) => Object.keys(manifest.languages).find(k =>
60
+ (manifest.languages[k].aliases ?? []).some(a => a.toLowerCase() === code.toLowerCase()))
61
+ for (const wanted of wantedList) {
62
+ let loc: Intl.Locale
63
+ try { loc = new Intl.Locale(wanted).maximize() } catch { continue } // zh-TW -> zh-Hant-TW
64
+ const hit = find(wanted) ?? find(alias(wanted)) ?? find(`${loc.language}-${loc.script}`)
65
+ ?? find(loc.language) ?? find(alias(loc.language))
66
+ ?? (loc.language === 'zh' ? undefined : ready.find(r => r.split('-')[0] === loc.language))
67
+ if (hit) return hit // es-MX -> es; pt-PT -> pt-BR when that is the only Portuguese
68
+ }
69
+ return find('en') ?? manifest.sourceLanguage
70
+ }
71
+ ```
72
+
73
+ This is the matching rule of [languages.md](languages.md) in code (tested on zh-TW, zh-MY, pt-PT, es-MX, no, iw, tl
74
+ and others); a game ports the same steps. Save the choice when the user changes it (`localStorage`, and the account
75
+ profile if there is one). A URL that names a language (`/ja/…`) wins over both.
76
+
77
+ ## Page-level rules
78
+
79
+ - `<html lang="{code}" dir="{ltr|rtl}">` updated on every language change (`dir` comes from the manifest).
80
+ - Right-to-left: use logical CSS (`margin-inline-start`, `padding-inline-end`, `text-align: start`), flip directional
81
+ icons, test one Arabic page before declaring it done.
82
+ - Language switcher: the same picker rules as the games ([languages.md](languages.md)): searchable, rows
83
+ `English name (native name)`, a globe icon. `Intl.DisplayNames` may add the name in the current language as a third
84
+ search term.
85
+ - Numbers, dates, currency, lists and relative times: `Intl.NumberFormat`, `Intl.DateTimeFormat`, `Intl.ListFormat`,
86
+ `Intl.RelativeTimeFormat` with the active language, then pass the result into a `{{placeholder}}`.
87
+ - Fonts: a font stack with system CJK / Thai / Arabic fallbacks; do not ship one webfont for all scripts.
88
+ - SEO for public pages: one URL per language (`/en/…`, `/ja/…`), `<link rel="alternate" hreflang="…">` for every
89
+ ready language plus `x-default`, translated `<title>` and meta description (keep them in a `seo` namespace), and a
90
+ sitemap that lists the alternates. Static sites are generated per language from the same
91
+ locale files at build.
92
+ - Never build a sentence in JSX from fragments; use one key with placeholders, or `<Trans>` when markup must sit
93
+ inside the sentence (web-only namespace, see [format.md](format.md)).
94
+
95
+ ## Checks for a web project
96
+
97
+ - `python i18n.py check` in CI; `i18n.py pack` before a release so `manifest.json` is current.
98
+ - A script (or `i18next-parser` in check mode) that fails when the code uses a key the source lacks.
99
+ - A visual pass per new language on the main pages at phone width: overflow, clipped buttons, mixed directions.
100
+
101
+ ## Apps
102
+
103
+ | App type | How it uses the standard |
104
+ |---|---|
105
+ | React Native, Electron, Capacitor | i18next exactly as above; packs bundled, optional CDN update |
106
+ | Native iOS / Android, Flutter | the texts are still authored in `i18n/locales` (one source, same translation loop). No exporter exists yet: when the first such app appears, add an export step to `pack` that writes `.xcstrings` / `strings.xml` / `.arb` from the locale files, and keep those generated files out of hand editing |
107
+ | Store listing (name, subtitle, description, keywords, what's new) | a `store` namespace translated with the same loop; note the stores' length limits in `notes/store.json` |