|
| 1 | +Scan `lib/` for hardcoded Chinese strings and internationalize them following the project's ARB conventions. |
| 2 | + |
| 3 | +## Instructions |
| 4 | + |
| 5 | +You are performing i18n extraction for a Flutter project that uses the Flutter Intl plugin with ARB files. |
| 6 | + |
| 7 | +### Project localization context |
| 8 | + |
| 9 | +- **ARB files**: `arb/intl_en.arb`, `arb/intl_zh_CN.arb`, `arb/intl_ja.arb`, `arb/intl_ru.arb` |
| 10 | +- **Key conventions**: camelCase, flat keys (no nesting, no `@` metadata), semantic naming |
| 11 | + - Short labels: `rule`, `global`, `direct`, `edit`, `confirm` |
| 12 | + - Descriptive suffix `Desc`: `themeDesc`, `tunDesc`, `logsDesc` |
| 13 | + - Validation suffix: `profileNameNullValidationDesc` |
| 14 | +- **Generated code**: `lib/l10n/l10n.dart` (DO NOT edit generated files) |
| 15 | +- **Access patterns**: |
| 16 | + - In widgets with BuildContext: `context.appLocalizations.key` (import `common.dart`) |
| 17 | + - In controllers/providers/non-widget code: `currentAppLocalizations.key` (import `app_localizations.dart`) |
| 18 | + |
| 19 | +### Step 1: Find hardcoded Chinese strings |
| 20 | + |
| 21 | +Use Grep to search `lib/` for Chinese characters. The regex pattern for Chinese characters is `[\x{4e00}-\x{9fff}]`. |
| 22 | + |
| 23 | +Important filters: |
| 24 | +- **Exclude** `lib/l10n/` (generated localization files) |
| 25 | +- **Exclude** lines that already use `appLocalizations` or `currentAppLocalizations` |
| 26 | +- **Exclude** false positives that are NOT Chinese text: |
| 27 | + - Arrow symbols: `↑` `↓` `←` `→` (Unicode arrows, not CJK) |
| 28 | + - Middle dot: `·` (U+00B7, not CJK) |
| 29 | + - Command symbol: `⌘` (U+2318, not CJK) |
| 30 | + - Other CJK punctuation that is used as UI symbols, not translatable text |
| 31 | + |
| 32 | +For each match, read the surrounding context (5-10 lines) to understand: |
| 33 | +- What the string represents (label, error message, tooltip, dialog text, etc.) |
| 34 | +- Whether it's inside a widget (has `BuildContext` available) or non-widget code |
| 35 | +- Whether it appears in a `Text()`, `TextSpan()`, `title:`, `label:`, or other text position |
| 36 | + |
| 37 | +### Step 2: Generate ARB keys |
| 38 | + |
| 39 | +For each hardcoded Chinese string: |
| 40 | + |
| 41 | +1. **Choose a key name** following project conventions: |
| 42 | + - Use the Chinese meaning to derive an English camelCase key |
| 43 | + - Keep it concise: `createConfig` not `createAConfigurationForTheProfile` |
| 44 | + - Use `Desc` suffix for descriptive/explanatory text |
| 45 | + - Use existing similar keys as reference (check `arb/intl_en.arb` for patterns) |
| 46 | + |
| 47 | +2. **Determine the English translation** (the value for `intl_en.arb`) |
| 48 | + |
| 49 | +3. **Determine the Chinese translation** (the value for `intl_zh_CN.arb`) — this is the original hardcoded string |
| 50 | + |
| 51 | +4. **For ja and ru**: use the English translation as a placeholder (translators will fill these in later) |
| 52 | + |
| 53 | +### Step 3: Update ARB files |
| 54 | + |
| 55 | +For each new key, add it to all 4 ARB files. Read each ARB file first to find the right insertion point (alphabetical order is not required, but appending near the end is clean). |
| 56 | + |
| 57 | +Format: add a new line like `"keyName": "value",` before the closing `}`. |
| 58 | + |
| 59 | +### Step 4: Replace hardcoded strings in Dart files |
| 60 | + |
| 61 | +Replace each hardcoded Chinese string with the appropriate localization call: |
| 62 | + |
| 63 | +- If inside a widget BuildContext: `context.appLocalizations.keyName` |
| 64 | +- If in controller/provider code: `currentAppLocalizations.keyName` |
| 65 | + |
| 66 | +Ensure the correct import exists: |
| 67 | +- For `context.appLocalizations`: the file should import `common.dart` (check if it already does) |
| 68 | +- For `currentAppLocalizations`: the file should import `app_localizations.dart` (check if it already does) |
| 69 | + |
| 70 | +If the file uses string interpolation (e.g., `'创建 $name 配置'`), convert to the ARB parameterized format: |
| 71 | +- In ARB: `"keyName": "Create $name config"` |
| 72 | +- In Dart: `currentAppLocalizations.keyName(name)` |
| 73 | + |
| 74 | +### Step 5: Report changes |
| 75 | + |
| 76 | +After all modifications, output a summary: |
| 77 | +1. List each file modified and what changed |
| 78 | +2. List each new ARB key added with its translations |
| 79 | +3. Remind the user to run code generation if needed: |
| 80 | + ``` |
| 81 | + dart run build_runner build --delete-conflicting-outputs |
| 82 | + ``` |
| 83 | + or trigger Flutter Intl regeneration in their IDE. |
| 84 | + |
| 85 | +### Important notes |
| 86 | + |
| 87 | +- Only extract strings that are user-facing UI text. Do NOT extract: |
| 88 | + - Comments (lines starting with `//`) |
| 89 | + - Log messages (unless they appear in the UI) |
| 90 | + - Variable names or identifiers |
| 91 | + - String literals used as keys/identifiers (not displayed to users) |
| 92 | +- If a Chinese string is split across multiple lines or concatenations, merge them into a single ARB entry |
| 93 | +- If a string contains dynamic content (variables, URLs), use ARB parameter syntax `$variableName` |
0 commit comments