Skip to content

Commit d715268

Browse files
committed
Extracted settings.controls[key].help msgs
1 parent f444af9 commit d715268

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

remove-json-keys/src/remove_json_keys/assets/data/messages.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@
1414
"log_TOTAL_JSON_PROCESSED": { "message": "Total JSON files processed" },
1515
"tip_PASS_FORCE_TO_OVERWRITE": { "message": "Pass --force to overwrite" },
1616
"warn_CONFIG_EXISTS_AT": { "message": "Config already exists at" },
17-
"warn_DIR_NOT_FOUND": { "message": "Unable to locate directory" }
17+
"warn_DIR_NOT_FOUND": { "message": "Unable to locate directory" },
18+
"help_JSON_DIR": { "message": "Name of the folder containing JSON files (default: \"_locales\")" },
19+
"help_KEYS": { "message": "Keys to remove (e.g. \"app_NAME,author\")" },
20+
"help_INIT": { "message": "Create .remove-json.config.json5 file to store default options" },
21+
"help_FORCE": { "message": "Force overwrite existing config file when using init" },
22+
"help_NO_WIZARD": { "message": "Skip interactive prompts during start-up" },
23+
"help_HELP": { "message": "Show help screen" },
24+
"help_DEBUG": { "message": "Show debug logs" }
1825
}

remove-json-keys/src/remove_json_keys/lib/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737

3838
def load(cli, caller_file):
3939

40+
# Assign help tips from cli.msgs
41+
for ctrl_key, ctrl in vars(controls).items():
42+
if not hasattr(ctrl, 'help') : ctrl.help = getattr(cli.msgs, f'help_{ctrl_key.upper()}')
43+
4044
# Load from config file
4145
cli.config = sn()
4246
caller_path = Path(caller_file)

translate-messages/src/translate_messages/assets/data/messages.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,16 @@
2222
"warn_DIR_NOT_FOUND": { "message": "Unable to locate directory" },
2323
"err_PARSE_FAILED": { "message": "Failed to parse" },
2424
"err_TRANSLATE_FAILED_FOR_KEY": { "message": "Translation failed for key" },
25-
"err_EN_LOC_NOT_FOUND_AT": { "message": "English locale not found at" }
25+
"err_EN_LOC_NOT_FOUND_AT": { "message": "English locale not found at" },
26+
"help_LOCALES_DIR": { "message": "Name of the folder containing locale files (default: \"_locales\")" },
27+
"help_TARGET_LANGS": { "message": "Languages to translate to (e.g. \"es,fr\") (default: all 100+ supported locales)" },
28+
"help_KEYS": { "message": "Keys to translate (e.g. \"app_DESC,err_NOT_FOUND\") (default: all found src keys missing in target files)" },
29+
"help_EXCLUDE_LANGS": { "message": "Languages to exclude (e.g. \"es,zh\")" },
30+
"help_EXCLUDE_KEYS": { "message": "Keys to ignore (e.g. \"app_NAME,author\")" },
31+
"help_ONLY_STABLE": { "message": "Only use stable locales (skip auto-discovery)" },
32+
"help_INIT": { "message": "Create .translate-msgs.config.json5 file to store default options" },
33+
"help_FORCE": { "message": "Force overwrite existing config file when using init" },
34+
"help_NO_WIZARD": { "message": "Skip interactive prompts during start-up" },
35+
"help_HELP": { "message": "Show help screen" },
36+
"help_DEBUG": { "message": "Show debug logs" }
2637
}

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

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,36 @@
77
controls = sn(
88
locales_dir=sn(
99
args=['-d', '--locales-dir', '--locales-folder', '--json-dir', '--json-folder'],
10-
type=str, default_val='_locales', help='Name of the folder containing locale files (default: "_locales")'
10+
type=str, default_val='_locales'
1111
),
1212
target_langs=sn(
13-
args=['-t', '--target-langs', '--include-langs'],
14-
type=str, parser='csv', help='Languages to translate to (e.g. "es,fr") (default: all 100+ supported locales)'
15-
),
13+
args=['-t', '--target-langs', '--include-langs'], type=str, parser='csv' ),
1614
keys=sn(
17-
args=['-k', '--keys', '--include-keys', '--translate-keys'],
18-
type=str, parser='csv', help='Keys to translate (e.g. "app_DESC,err_NOT_FOUND") (default: all found src keys missing in target files)'
19-
),
15+
args=['-k', '--keys', '--include-keys', '--translate-keys'], type=str, parser='csv'),
2016
exclude_langs=sn(
21-
args=['--exclude-langs', '--ignore-langs'],
22-
type=str, parser='csv', help='Languages to exclude (e.g. "es,zh")'
23-
),
17+
args=['--exclude-langs', '--ignore-langs'], type=str, parser='csv'),
2418
exclude_keys=sn(
25-
args=['--exclude-keys', '--ignore-keys'],
26-
type=str, parser='csv', help='Keys to ignore (e.g. "app_NAME,author")'
27-
),
19+
args=['--exclude-keys', '--ignore-keys'], type=str, parser='csv'),
2820
only_stable=sn(
29-
args=['-s', '--only-stable', '--no-discovery'],
30-
action='store_true', help='Only use stable locales (skip auto-discovery)'
31-
),
21+
args=['-s', '--only-stable', '--no-discovery'], action='store_true'),
3222
init=sn(
33-
args=['-i', '--init'],
34-
action='store_true', subcmd='true', help='Create .translate-msgs.config.json5 file to store default options'
35-
),
23+
args=['-i', '--init'], action='store_true', subcmd='true'),
3624
force=sn(
37-
args=['-f', '--force', '--overwrite'],
38-
action='store_true', help='Force overwrite existing config file when using init'
39-
),
25+
args=['-f', '--force', '--overwrite'], action='store_true'),
4026
no_wizard=sn(
41-
args=['-n', '-W', '--no-wizard', '--skip-wizard'],
42-
action='store_true', default=None, help='Skip interactive prompts during start-up'
43-
),
27+
args=['-n', '-W', '--no-wizard', '--skip-wizard'], action='store_true', default=None),
4428
help=sn(
45-
args=['-h', '--help'],
46-
action='help', help='Show help screen'
47-
),
29+
args=['-h', '--help'], action='help'),
4830
debug=sn(
49-
args=['--debug'],
50-
action='store_true', help='Show debug logs'
51-
)
31+
args=['--debug'], action='store_true')
5232
)
5333

5434
def load(cli, caller_file):
5535

36+
# Assign help tips from cli.msgs
37+
for ctrl_key, ctrl in vars(controls).items():
38+
if not hasattr(ctrl, 'help') : ctrl.help = getattr(cli.msgs, f'help_{ctrl_key.upper()}')
39+
5640
# Load from config file
5741
cli.config = sn()
5842
caller_path = Path(caller_file)

0 commit comments

Comments
 (0)