SKILL.md
Angular i18n Refactoring Skill (Namespaced)
Use this skill to systematically refactor Angular components for internationalization (ngx-translate) using a nested JSON structure (Namespaces).
workflow
1. Scan and Extract
- Analyze the user-selected HTML file.
- Determine the Namespace based on the component name (e.g.,
UserProfileComponent->USER_PROFILE). - Identify all hardcoded text nodes and static attributes (specifically
placeholder,title,alt,aria-label). - Generate keys nested under the namespace in
UPPERSNAKECASE(e.g., Namespace:USERPROFILE, Key:SUBMITBTN).
2. Template Refactoring (HTML)
- Replace text content with the pipe syntax using dot notation:
{{ 'NAMESPACE.KEY' | translate }}.
- Example: {{ 'USERPROFILE.SUBMITBTN' | translate }}
- Replace attributes with bound syntax:
[placeholder]="'NAMESPACE.KEY' | translate".
3. Component Dependency Injection (TS)
- Locate the corresponding
.tsfile. - Check Imports: Ensure
import { TranslateService } from '@ngx-translate/core';exists. - Check Injection: Verify if
TranslateServiceis injected.
- If missing, add: private translate = inject(TranslateService); (Use constructor injection for older Angular versions).
4. Translation Generation (JSON)
- Locate
src/assets/i18n/en.jsonandsrc/assets/i18n/tc.json. - Structure: Create or update the JSON with nested objects, not flat keys.
Example Structure: "USERPROFILE": { "SUBMITBTN": "Submit", "CANCEL_BTN": "Cancel" }
- English (en.json): Add the nested keys with original text.
- Traditional Chinese (tc.json): Auto-translate text to Traditional Chinese (Hong Kong style, zh-HK) and maintain the same nested structure.
5. Final Reporting
- Output a markdown table summary of the changes:
| Key ID | English (en.json) | Chinese (tc.json) |
|---|---|---|
USERPROFILE.SUBMITBTN |
"Submit" | "提交" |
Guidelines
- Strictly maintain JSON nesting. Do not create keys like
"USERPROFILE.SUBMITBTN": "...". It must be"USERPROFILE": { "SUBMITBTN": "..." }. - Prioritize "Hong Kong" terminology for
tc.json(e.g., use "登入" for Login, not "登錄"). - If the translation files are not in context, ask the user for their location.