Add translation
Add one or more localization keys to both assets/translations/en.json and assets/translations/ar.json in sync, then regenerate lib/core/helpers/localization/locale_keys.g.dart. Use when the user asks to add a translation, add a string, add a new key, or wire up a new label/error message in the UI.From its SKILL.md
npx -y skills add OmarAly92/flutter-knowledge --skill add-translationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.5 KB, as published. Nobody here has run it
Add translation key(s)
Argument: $ARGUMENTS = key + value, free-form. Examples:
welcomeBack "Welcome back" "مرحبا بعودتك"— single key with both translations.welcomeBack "Welcome back"— English only; ask the user for the Arabic.- empty — ask the user for keys to add.
Critical rule
Both en.json and ar.json must always contain the same set of keys. A key in one but not the other causes the missing locale to display the raw key string and may break locale_keys.g.dart codegen. Never edit one file without the other.
Steps
-
Parse the request. Identify each
(key, en, ar)triple. Key must becamelCase(matches existing convention:loginButton,pleaseLoginToContinue,enterValidPhoneNumber). -
Check for collisions. Read both
assets/translations/en.jsonandassets/translations/ar.jsonand verify the key does not already exist in either. If it does, ask the user whether to overwrite or pick a new key. -
Ask for any missing Arabic translation. If the user only supplied English, ask them for the Arabic — do not auto-translate.
-
Edit both files. Add the new entry in the same logical location in each file (group related keys together — e.g., put a new validation message near other
*IsRequiredkeys). Preserve JSON formatting (2-space indent, trailing comma rules matching the existing file). Both files must remain in the same key order. -
Regenerate codegen. Tell the user to run:
flutter pub run easy_localization:generate -S assets/translations -O lib/core/helpers/localization -f keys -o locale_keys.g.dart(or just
flutter pub getif their setup regenerates on pub get). Do not run this yourself — leave it to the user, since it touches generated files and requires their toolchain. -
Show usage. Print a one-liner showing how to use the new key in code, e.g.:
Text(LocaleKeys.welcomeBack.tr())
What NOT to do
- Do not auto-translate Arabic from English. Ask the user.
- Do not edit
lib/core/helpers/localization/locale_keys.g.dartby hand — it is generated. - Do not add keys to only one of the two JSON files.
- Do not reorder or reformat unrelated entries in the JSON files.