Skip to content

Commit a533ad2

Browse files
committed
Added --keys option
1 parent 9fd5739 commit a533ad2

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

translate-messages/.translate-msgs.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"locales_dir": "_locales",
33
"target_langs": "",
44
"exclude_langs": "",
5+
"keys": "",
56
"exclude_keys": "",
67
"no_wizard": false
78
}

translate-messages/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Options can be set by using command-line arguments:
4444
| `-d`, `--locales-dir` | Name of the folder containing locale files (default: `_locales`) | `--locales-dir=_messages`
4545
| `-t`, `--target-langs` | Comma-separated list of languages to include (default: all [`supported_locales`][supported-locales]) | `--target-langs=en,es,fr`
4646
| `--exclude-langs` | Comma-separated list of languages to exclude | `--exclude-langs=en,es`
47+
| `-k`, `--keys` | Comma-separated list of keys to translate | `--keys=appDesc,err_notFound`
4748
| `--exclude-keys` | Comma-separated list of keys to ignore | `--exclude-keys=appName,author`
4849
| `-i`, `--init` | Create .translate-msgs.config.json in project root to store defaults |
4950
| `-W`, `--no-wizard` | Skip interactive prompts during start-up |
@@ -68,6 +69,7 @@ Example defaults:
6869
"locales_dir": "_locales",
6970
"target_langs": "",
7071
"exclude_langs": "",
72+
"keys": "",
7173
"exclude_keys": "",
7274
"no_wizard": false
7375
}

translate-messages/src/translate_messages/lib/init.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def cli(caller_file):
3131
argp.add_argument('-t', '--target-langs', '--target-lang', '--include-langs', '--include-lang',
3232
type=str, help='Languages to include (e.g. "en,es,fr") (default: all supported locales)')
3333
argp.add_argument('--exclude-langs', '--exclude-lang', type=str, help='Languages to exclude (e.g. "en,es")')
34+
argp.add_argument('-k', '--keys', '--key', '--include-keys', '--include-key',
35+
type=str, help='Keys to translate (e.g. "appDesc,err_notFound")')
3436
argp.add_argument('--exclude-keys', '--ignore-keys', type=str, help='Keys to ignore (e.g. "appName,author")')
3537
argp.add_argument('-i', '--init', action='store_true', help=f'Create {cli.name}.config.json file to store defaults')
3638
argp.add_argument('-W', '--no-wizard', '--skip-wizard',
@@ -42,6 +44,7 @@ def cli(caller_file):
4244
cli.config.target_langs = data.csv.parse(getattr(cli.config, 'target_langs', None))
4345
cli.config.target_locales = cli.config.target_langs or cli.supported_locales
4446
cli.config.exclude_langs = data.csv.parse(getattr(cli.config, 'exclude_langs', None))
47+
cli.config.keys = data.csv.parse(getattr(cli.config, 'keys', None))
4548
cli.config.exclude_keys = data.csv.parse(getattr(cli.config, 'exclude_keys', None))
4649
cli.config.locales_dir = getattr(cli.config, 'locales_dir', '_locales')
4750
if cli.config.exclude_langs:

translate-messages/src/translate_messages/lib/language.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
def create_translations(cli, target_msgs, lang_code):
66
fail_flags = ['INVALID TARGET LANGUAGE', 'TOO MANY REQUESTS', 'MYMEMORY']
7-
src_keys = list(cli.config.en_msgs.keys())
7+
src_keys = cli.config.keys or list(cli.config.en_msgs.keys())
8+
src_keys = [key for key in src_keys if key in cli.config.en_msgs]
89
translated_msgs = {}
910

1011
for key in src_keys:

0 commit comments

Comments
 (0)