com.xmobitea.changx.mini-localization 1.5.1 → 1.5.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/AGENTS.md +104 -94
- package/AI_ADD_LOCALIZATION_KEY.md +78 -0
- package/AI_ADD_LOCALIZATION_KEY.md.meta +7 -0
- package/AI_API_REFERENCE.md +279 -278
- package/AI_API_REFERENCE.md.meta +7 -7
- package/AI_BEHAVIOR.md +267 -264
- package/AI_BEHAVIOR.md.meta +7 -7
- package/AI_BIND_UI_TEXT.md +97 -0
- package/AI_BIND_UI_TEXT.md.meta +7 -0
- package/AI_IMPORT_TRANSLATIONS.md +84 -0
- package/AI_IMPORT_TRANSLATIONS.md.meta +7 -0
- package/AI_SETUP.md +24 -20
- package/AI_SETUP.md.meta +7 -7
- package/AI_SETUP_LOCALIZATION_MANAGER.md +94 -89
- package/AI_SETUP_LOCALIZATION_MANAGER.md.meta +7 -7
- package/AI_SETUP_LOCALIZATION_SETTINGS.md +188 -180
- package/AI_SETUP_LOCALIZATION_SETTINGS.md.meta +7 -7
- package/AI_SWITCH_LANGUAGE.md +107 -0
- package/AI_SWITCH_LANGUAGE.md.meta +7 -0
- package/AI_USAGE.md +172 -168
- package/CHANGELOG.md +28 -28
- package/Editor/LocalizationComponentWindowsEditor.cs +206 -206
- package/Editor/LocalizationManagerEditor.cs +3 -3
- package/README.md +167 -154
- package/Runtime/LocalizationComponent.cs +60 -60
- package/Runtime/LocalizationLanguageItem.cs +42 -42
- package/Runtime/LocalizationManager.cs +293 -293
- package/Runtime/LocalizationSettings.cs +54 -54
- package/Runtime/TMP_LocalizationComponent.cs +33 -33
- package/Samples~/Example/English.xml +10 -10
- package/Samples~/Example/English.xml.meta +7 -7
- package/Samples~/Example/LocalizationSample.csv +6 -6
- package/Samples~/Example/LocalizationSample.csv.meta +7 -7
- package/Samples~/Example/README.md +47 -47
- package/Samples~/Example/README.md.meta +7 -7
- package/Samples~/Example/Vietnamese.xml +10 -10
- package/Samples~/Example/Vietnamese.xml.meta +7 -7
- package/Samples~/Example.meta +8 -8
- package/package.json +16 -16
package/AGENTS.md
CHANGED
|
@@ -1,107 +1,117 @@
|
|
|
1
|
-
# XmobiTea Localization Agent Guide
|
|
2
|
-
|
|
3
|
-
Scope: everything inside `Assets/XmobiTea Localization`.
|
|
4
|
-
|
|
5
|
-
## Need-Based Routing
|
|
6
|
-
|
|
7
|
-
Choose by current need. Open the smallest file that answers it.
|
|
8
|
-
|
|
1
|
+
# XmobiTea Localization Agent Guide
|
|
2
|
+
|
|
3
|
+
Scope: everything inside `Assets/XmobiTea Localization`.
|
|
4
|
+
|
|
5
|
+
## Need-Based Routing
|
|
6
|
+
|
|
7
|
+
Choose by current need. Open the smallest file that answers it.
|
|
8
|
+
|
|
9
9
|
| Need | Use |
|
|
10
10
|
| --- | --- |
|
|
11
11
|
| Choose localization API or generate common runtime code | `AI_USAGE.md` |
|
|
12
|
+
| Switch runtime language, read current language, build language selector | `AI_SWITCH_LANGUAGE.md` |
|
|
13
|
+
| Bind fixed UI text or use the bulk localization window | `AI_BIND_UI_TEXT.md` |
|
|
14
|
+
| Add, rename, or remove a localization key | `AI_ADD_LOCALIZATION_KEY.md` |
|
|
15
|
+
| Import translations from CSV or Google Sheets | `AI_IMPORT_TRANSLATIONS.md` |
|
|
12
16
|
| Setup router | `AI_SETUP.md` |
|
|
13
17
|
| Scene object, singleton timing, bootstrap, persistent manager | `AI_SETUP_LOCALIZATION_MANAGER.md` |
|
|
14
18
|
| Settings asset, language items, XML, CSV/Google import, constants | `AI_SETUP_LOCALIZATION_SETTINGS.md` |
|
|
15
|
-
| Exact signatures, return values, serialized fields, XML shape, editor menus | `AI_API_REFERENCE.md` |
|
|
16
|
-
| Lifecycle, source precedence, async refreshes, fetch edge cases | `AI_BEHAVIOR.md` |
|
|
17
|
-
| Package summary for humans | `README.md` |
|
|
18
|
-
| Missing or conflicting doc detail | source code |
|
|
19
|
-
|
|
20
|
-
## Hard Rules
|
|
21
|
-
|
|
22
|
-
- `LocalizationManager` is a scene-hosted `Singleton<LocalizationManager>`.
|
|
23
|
-
- The package does not auto-create a missing manager.
|
|
24
|
-
- Static APIs require the singleton to initialize first.
|
|
25
|
-
- The conventional host object name is `LocalizationManager`, but runtime depends on the initialized component.
|
|
26
|
-
- Use `XmobiTea.MiniSingleton.DontDestroy` only when later scenes need the same host.
|
|
27
|
-
- Runtime settings lookup key is `XmobiTea LocalizationSettings`; `Open Settings` creates the asset at `Assets/Resources/XmobiTea LocalizationSettings.asset`.
|
|
28
|
-
- `LocalizationSettings.ResourcesPath` is exactly `XmobiTea LocalizationSettings`.
|
|
29
|
-
- `ChooseLanguage(...)` populates the active dictionary.
|
|
30
|
-
- `GetText(...)` falls back to the original key.
|
|
31
|
-
- `LocalizationComponent` targets `UnityEngine.UI.Text`.
|
|
32
|
-
- `TMP_LocalizationComponent` targets `TMP_Text` and exists only with TextMesh Pro support.
|
|
33
|
-
- Fixed labels, titles, descriptions, tabs, and button captions should use localization components.
|
|
34
|
-
- `LocalizationManager.OnUpdateText` is a public static `Action`; subscribe with `+=`/`-=` and never overwrite it.
|
|
35
|
-
- Local XML loads synchronously first.
|
|
36
|
-
- Addressables XML can add/overwrite keys after async load completes.
|
|
37
|
-
- Successful online XML clears and replaces the active dictionary.
|
|
38
|
-
- If one language configures both Addressables XML and online XML, both async loads run and the callback that finishes later mutates the dictionary last.
|
|
39
|
-
- `OnUpdateText` can fire more than once for one `ChooseLanguage(...)` call.
|
|
40
|
-
- Runtime never reads CSV or Google Sheets.
|
|
19
|
+
| Exact signatures, return values, serialized fields, XML shape, editor menus | `AI_API_REFERENCE.md` |
|
|
20
|
+
| Lifecycle, source precedence, async refreshes, fetch edge cases | `AI_BEHAVIOR.md` |
|
|
21
|
+
| Package summary for humans | `README.md` |
|
|
22
|
+
| Missing or conflicting doc detail | source code |
|
|
23
|
+
|
|
24
|
+
## Hard Rules
|
|
25
|
+
|
|
26
|
+
- `LocalizationManager` is a scene-hosted `Singleton<LocalizationManager>`.
|
|
27
|
+
- The package does not auto-create a missing manager.
|
|
28
|
+
- Static APIs require the singleton to initialize first.
|
|
29
|
+
- The conventional host object name is `LocalizationManager`, but runtime depends on the initialized component.
|
|
30
|
+
- Use `XmobiTea.MiniSingleton.DontDestroy` only when later scenes need the same host.
|
|
31
|
+
- Runtime settings lookup key is `XmobiTea LocalizationSettings`; `Open Settings` creates the asset at `Assets/Resources/XmobiTea LocalizationSettings.asset`.
|
|
32
|
+
- `LocalizationSettings.ResourcesPath` is exactly `XmobiTea LocalizationSettings`.
|
|
33
|
+
- `ChooseLanguage(...)` populates the active dictionary.
|
|
34
|
+
- `GetText(...)` falls back to the original key.
|
|
35
|
+
- `LocalizationComponent` targets `UnityEngine.UI.Text`.
|
|
36
|
+
- `TMP_LocalizationComponent` targets `TMP_Text` and exists only with TextMesh Pro support.
|
|
37
|
+
- Fixed labels, titles, descriptions, tabs, and button captions should use localization components.
|
|
38
|
+
- `LocalizationManager.OnUpdateText` is a public static `Action`; subscribe with `+=`/`-=` and never overwrite it.
|
|
39
|
+
- Local XML loads synchronously first.
|
|
40
|
+
- Addressables XML can add/overwrite keys after async load completes.
|
|
41
|
+
- Successful online XML clears and replaces the active dictionary.
|
|
42
|
+
- If one language configures both Addressables XML and online XML, both async loads run and the callback that finishes later mutates the dictionary last.
|
|
43
|
+
- `OnUpdateText` can fire more than once for one `ChooseLanguage(...)` call.
|
|
44
|
+
- Runtime never reads CSV or Google Sheets.
|
|
41
45
|
- `fetchType` is editor-only: `None`, `FromGoogleSheets`, `FromCsv`.
|
|
42
46
|
- `worksheetKey` is required only when either fetch type is `FromGoogleSheets`.
|
|
47
|
+
- Empty Google sheet-name fields are sent to the fetch executable as `local` or `online`; explicit sheet names must avoid spaces.
|
|
43
48
|
- CSV rows must include `Key` plus one cell per configured language.
|
|
44
|
-
-
|
|
45
|
-
- Generated
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
- `Runtime/
|
|
95
|
-
- `Runtime/
|
|
96
|
-
- `Runtime/
|
|
97
|
-
- `Runtime/
|
|
98
|
-
- `
|
|
99
|
-
- `Editor/
|
|
100
|
-
- `Editor/
|
|
49
|
+
- After any fetch run, existing `Local-LocalizationFile/<Language>.xml` files are copied into assigned local XML assets, even during online-only fetches.
|
|
50
|
+
- Generated constants come from editor tooling, not runtime discovery.
|
|
51
|
+
- Generated `LocalizationConstantId` members are `public static readonly string`.
|
|
52
|
+
- The generator reads keys from the first configured language item's local XML.
|
|
53
|
+
|
|
54
|
+
## Do Not Assume
|
|
55
|
+
|
|
56
|
+
- `LocalizationManager` or `LocalizationSettings` will be created at runtime.
|
|
57
|
+
- Translations are active before `ChooseLanguage(...)`.
|
|
58
|
+
- A missing key returns `null`.
|
|
59
|
+
- One language switch means exactly one `OnUpdateText` call.
|
|
60
|
+
- Online XML merges with local XML.
|
|
61
|
+
- CSV or Google Sheets are runtime data sources.
|
|
62
|
+
- Generated constants are type-safe or auto-updated.
|
|
63
|
+
- Keys missing from the first local XML will generate constants.
|
|
64
|
+
- Nonexistent APIs exist: `SetLanguage`, `CurrentLanguage`, `GetLocalizedText`, `ReloadLanguage`, `FormatText`, `HasKey`.
|
|
65
|
+
|
|
66
|
+
## Code Generation Guidance
|
|
67
|
+
|
|
68
|
+
- Use `using XmobiTea.MiniLocalization;`.
|
|
69
|
+
- Add `using XmobiTea.MiniLocalization.Core;` only when declaring `LocalizationLanguageItem`.
|
|
70
|
+
- Prefer generated `LocalizationConstantId` values when the generated file exists and is current.
|
|
71
|
+
- Use raw key strings in fresh setups until constants are generated.
|
|
72
|
+
- Put language selection in `Start()` or later unless execution order guarantees manager initialization.
|
|
73
|
+
- Generate scene setup instructions instead of constructing a manager from code.
|
|
74
|
+
- Use `LocalizationComponent` / `TMP_LocalizationComponent` for fixed UI text.
|
|
75
|
+
- Generate custom text refresh code only for dynamic/composed text, non-UI state, or custom rendering.
|
|
76
|
+
- Custom listeners must unsubscribe and must tolerate repeated refreshes.
|
|
77
|
+
- Treat fallback-to-key display as normal runtime behavior.
|
|
78
|
+
- Before using constants, verify the first configured language XML contains the complete key set.
|
|
79
|
+
- Use `Samples~/Example` as the known-good CSV/XML shape.
|
|
80
|
+
|
|
81
|
+
## Setup Contract
|
|
82
|
+
|
|
83
|
+
When generated code depends on localization, require:
|
|
84
|
+
|
|
85
|
+
1. A loaded scene contains one active `LocalizationManager`.
|
|
86
|
+
2. Static APIs run after `LocalizationManager.Awake()`.
|
|
87
|
+
3. A `LocalizationSettings` asset loadable as `Resources.Load<LocalizationSettings>("XmobiTea LocalizationSettings")` exists.
|
|
88
|
+
4. `localizationLanguageItems` contains the requested language.
|
|
89
|
+
5. Runtime language items have local XML unless deliberately online/addressable-only.
|
|
90
|
+
6. Bootstrap calls `ChooseLanguage(...)`.
|
|
91
|
+
7. Fixed UI text uses localization components.
|
|
92
|
+
8. Constants are regenerated after key changes.
|
|
93
|
+
9. Fetch workflows verify assigned CSV assets, local XML targets, Google `worksheetKey`, and complete language columns.
|
|
94
|
+
|
|
95
|
+
## Maintenance Checklist
|
|
96
|
+
|
|
97
|
+
If changing resource paths, manager lifecycle, XML parsing, source precedence, generated constants, editor fetch behavior, component binding, or event semantics, update these together:
|
|
98
|
+
|
|
99
|
+
- `Runtime/LocalizationManager.cs`
|
|
100
|
+
- `Runtime/LocalizationSettings.cs`
|
|
101
|
+
- `Runtime/LocalizationLanguageItem.cs`
|
|
102
|
+
- `Runtime/LocalizationComponent.cs`
|
|
103
|
+
- `Runtime/TMP_LocalizationComponent.cs`
|
|
104
|
+
- `Editor/LocalizationManagerEditor.cs`
|
|
105
|
+
- `Editor/LocalizationSettingsEditor.cs`
|
|
106
|
+
- `Editor/LocalizationKeyDrawer.cs`
|
|
101
107
|
- `AI_USAGE.md`
|
|
108
|
+
- `AI_SWITCH_LANGUAGE.md`
|
|
109
|
+
- `AI_BIND_UI_TEXT.md`
|
|
110
|
+
- `AI_ADD_LOCALIZATION_KEY.md`
|
|
111
|
+
- `AI_IMPORT_TRANSLATIONS.md`
|
|
102
112
|
- `AI_SETUP.md`
|
|
103
113
|
- `AI_SETUP_LOCALIZATION_MANAGER.md`
|
|
104
114
|
- `AI_SETUP_LOCALIZATION_SETTINGS.md`
|
|
105
|
-
- `AI_API_REFERENCE.md`
|
|
106
|
-
- `AI_BEHAVIOR.md`
|
|
107
|
-
- `README.md`
|
|
115
|
+
- `AI_API_REFERENCE.md`
|
|
116
|
+
- `AI_BEHAVIOR.md`
|
|
117
|
+
- `README.md`
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# AI Add Localization Key
|
|
2
|
+
|
|
3
|
+
Use this when a task adds, renames, or removes a localization key, or when `LocalizationConstantId` is missing or stale.
|
|
4
|
+
|
|
5
|
+
## Source Of Truth
|
|
6
|
+
|
|
7
|
+
Choose one source of truth and update that source first:
|
|
8
|
+
|
|
9
|
+
- CSV or Google Sheets when the project imports translations through `Fetch Localization`;
|
|
10
|
+
- local XML files when the project edits runtime XML directly.
|
|
11
|
+
|
|
12
|
+
The first configured language item's local XML must contain the full key set because constant generation reads that file only.
|
|
13
|
+
|
|
14
|
+
## Add A Key
|
|
15
|
+
|
|
16
|
+
Checklist:
|
|
17
|
+
|
|
18
|
+
- add the key to the source of truth;
|
|
19
|
+
- if editing XML directly, add the key to every runtime language XML;
|
|
20
|
+
- keep XML in the runtime parser shape;
|
|
21
|
+
- regenerate constants;
|
|
22
|
+
- update `LocalizationComponent`, `TMP_LocalizationComponent`, and scripts to use the new key.
|
|
23
|
+
|
|
24
|
+
Minimal XML entry:
|
|
25
|
+
|
|
26
|
+
```xml
|
|
27
|
+
<key name='Home_Title'>Home</key>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Rename A Key
|
|
31
|
+
|
|
32
|
+
Checklist:
|
|
33
|
+
|
|
34
|
+
- rename the key in the source of truth;
|
|
35
|
+
- update every affected XML or translation row;
|
|
36
|
+
- regenerate constants;
|
|
37
|
+
- update all component keys and script references;
|
|
38
|
+
- remove old key usages so UI does not fall back to the old raw key string.
|
|
39
|
+
|
|
40
|
+
## Remove A Key
|
|
41
|
+
|
|
42
|
+
Checklist:
|
|
43
|
+
|
|
44
|
+
- delete the key from the source of truth;
|
|
45
|
+
- regenerate constants;
|
|
46
|
+
- remove or replace every component and code reference to that key.
|
|
47
|
+
|
|
48
|
+
## Regenerate Constants
|
|
49
|
+
|
|
50
|
+
Run:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
XmobiTea Tools/Localization/Generate LocalizationConstantId.cs
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Generated file:
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
Assets/XmobiTea-constant/Scripts/LocalizationConstantId.cs
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Use raw strings temporarily when constants are intentionally not regenerated yet.
|
|
63
|
+
|
|
64
|
+
## Verify
|
|
65
|
+
|
|
66
|
+
Checklist:
|
|
67
|
+
|
|
68
|
+
- run `ChooseLanguage(...)`;
|
|
69
|
+
- confirm `LocalizationManager.GetText(key)` returns translated text instead of the raw key;
|
|
70
|
+
- confirm fixed UI text refreshes;
|
|
71
|
+
- confirm the generated constant exists when code uses `LocalizationConstantId.*`.
|
|
72
|
+
|
|
73
|
+
## Hard No
|
|
74
|
+
|
|
75
|
+
- Do not add a key only to a non-first language XML and expect a constant to generate.
|
|
76
|
+
- Do not rename keys in code only.
|
|
77
|
+
- Do not leave stale component keys after a rename or delete.
|
|
78
|
+
- Do not assume runtime discovers new constants automatically.
|