Skip to content

Commit a6feb96

Browse files
committed
Extracted/used msgs
1 parent 3126050 commit a6feb96

10 files changed

Lines changed: 38 additions & 18 deletions

File tree

remove-json-keys/src/remove_json_keys/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def main():
2626
keys_removed, keys_skipped, files_processed_cnt = data.json.remove_keys(cli.json_path, cli.config.keys)
2727

2828
log.final_summary(cli.msgs, {
29-
'removed': [f'{key} ({file_path})' for key, file_path in keys_removed],
30-
'skipped': [f'{key} ({file_path})' for key, file_path in keys_skipped],
29+
cli.msgs.log_REMOVED.lower(): [f'{key} ({file_path})' for key, file_path in keys_removed],
30+
cli.msgs.log_SKIPPED.lower(): [f'{key} ({file_path})' for key, file_path in keys_skipped],
3131
})
3232
log.data(f'{cli.msgs.log_TOTAL_JSON_PROCESSED}: {files_processed_cnt}')
3333

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"log_DIR_FOUND": { "message": "Directory found" },
1010
"log_ADDED": { "message": "Added" },
1111
"log_SKIPPING": { "message": "Skipping" },
12+
"log_SKIPPED": { "message": "Skipped" },
13+
"log_REMOVED": { "message": "Removed" },
1214
"log_KEYS": { "message": "Keys" },
1315
"log_KEYS_TO_REMOVE": { "message": "Current keys to remove" },
1416
"log_NO_NEW_KEYS_ADDED": { "message": "No new keys added (all already present)" },
@@ -17,6 +19,7 @@
1719
"log_TYPE": { "message": "Type" },
1820
"log_TO_CREATE_DEFAULT_CONFIG": { "message": "to create default config file" },
1921
"log_FOR_AVAIL_OPTIONS": { "message": "for available options" },
22+
"log_VERSION": { "message": "version" },
2023
"tip_FOR_MORE_HELP_VISIT": { "message": "For more help, visit" },
2124
"tip_PASS_FORCE_TO_OVERWRITE": { "message": "Pass --force to overwrite" },
2225
"tip_MOVE_CONFIG_TO_ROOT": { "message": "Move config file to root of project you wish to use it in" },
@@ -26,6 +29,8 @@
2629
"warn_SPECIFIED_CONFIG": { "message": "Specified config" },
2730
"warn_NOT_FOUND": { "message": "Not found" },
2831
"err_UNRECOGNIZED_ARGS": { "message": "Unrecognized argument(s)" },
32+
"err_INVALID_KEY": { "message": "Invalid key" },
33+
"err_FOUND_IN": { "message": "found in" },
2934
"help_JSON_DIR": { "message": "Name of the folder containing JSON files (default: \"_locales\")" },
3035
"help_KEYS": { "message": "Keys to remove (e.g. \"app_NAME,author\")" },
3136
"help_CONFIG": { "message": "Use custom config file (e.g. \"path/to/file\")" },

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def config_filepath(cli): # for settings.load()
4747
log.debug(f'Config file found: {cli.config_filepath}')
4848
return
4949
else:
50-
log.warn(f'{cli.msgs.warn_SPECIFIED_CONFIG} {cli.config_filepath} not found')
50+
log.warn(f'{cli.msgs.warn_SPECIFIED_CONFIG} {cli.config_filepath} {cli.msgs.warn_NOT_FOUND}')
5151

5252
# Search upwards
5353
possible_config_filenames = [

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def overwrite_print(msg, *args, **kwargs):
2929
sys.stdout.write('\r' + msg.format(*args, **kwargs).ljust(terminal_width)[:terminal_width])
3030
def success(msg, *args, **kwargs) : print(f'\n{colors.bg}{msg.format(*args, **kwargs)}{colors.nc}')
3131
def tip(msg, *args, **kwargs) : print(f'\n{colors.bc}TIP: {msg.format(*args, **kwargs)}{colors.nc}')
32-
def version(cli) : print(f'\n{colors.by}{cli.name}\n{colors.bw}version: {cli.version}{colors.nc}')
32+
def version(cli) : print(f'\n{colors.by}{cli.name}\n{colors.bw}{cli.msgs.log_VERSION}: {cli.version}{colors.nc}')
3333
def warn(msg, *args, **kwargs) : print(f'\n{colors.bo}WARNING: {msg.format(*args, **kwargs)}{colors.nc}')
3434

3535
def debug(msg, cli=None, *args, **kwargs):
@@ -42,8 +42,10 @@ def debug(msg, cli=None, *args, **kwargs):
4242
debug_key = sys.argv[debug_argidx +1].replace('-', '_')
4343

4444
if cli: # init data line
45-
data_val = getattr(cli.config, debug_key, f'cli.config key "{debug_key}" not found') if debug_key \
46-
else cli.config
45+
if debug_key:
46+
data_val = getattr(cli.config, debug_key, f'cli.config key "{debug_key}" {cli.msgs.warn_NOT_FOUND.lower()}')
47+
else:
48+
data_val = cli.config
4749
msg += f'\n{colors.gry}{data_val}{colors.nc}'
4850

4951
if args: # use 'em
@@ -56,7 +58,7 @@ def final_summary(msgs, summary_dict):
5658
for name, file_set in summary_dict.items():
5759
if file_set:
5860
status = name.replace('_', ' ')
59-
status_color = colors.by if status == 'removed' else colors.gry
61+
status_color = colors.by if status == msgs.log_REMOVED.lower() else colors.gry
6062
data(f'{msgs.log_KEYS} {status}: {len(file_set)}')
6163
print(f'{status_color}[\n ' + '\n '.join(file_set) + f'\n]{colors.nc}')
6264

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def load(cli):
6767
setattr(cli.config, key, val)
6868
else:
6969
log.init_cmd_docs_url_exit(cli,
70-
f"Invalid key '{key}' found in \n{log.colors.gry}{cli.config_filepath}")
70+
f"{cli.msgs.err_INVALID_KEY} '{key}' {cli.msgs.err_FOUND_IN}"
71+
f'\n{log.colors.gry}{cli.config_filepath}'
72+
)
7173
log.debug('Config file loaded!', cli)
7274
else:
7375
log.debug('No config file found.')

translate-messages/src/translate_messages/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def main():
2929
langs_translated, langs_skipped, langs_added, langs_not_translated = language.write_translations(cli)
3030

3131
log.final_summary(cli.msgs, {
32-
'translated': langs_translated,
33-
'skipped': langs_skipped,
34-
'added': langs_added,
35-
'not translated': langs_not_translated,
32+
cli.msgs.log_TRANSLATED.lower(): langs_translated,
33+
cli.msgs.log_SKIPPED.lower(): langs_skipped,
34+
cli.msgs.log_ADDED.lower(): langs_added,
35+
cli.msgs.log_NOT_TRANSLATED.lower(): langs_not_translated,
3636
})
3737

3838
if __name__ == '__main__' : main()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
"log_SKIPPED": { "message": "Skipped" },
1212
"log_UPDATING": { "message": "Updating" },
1313
"log_UPDATED": { "message": "Updated" },
14+
"log_TRANSLATED": { "message": "Translated" },
15+
"log_NOT_TRANSLATED": { "message": "Not translated" },
1416
"log_LANGUAGES": { "message": "Languages" },
1517
"log_IGNORED_KEYS": { "message": "Ignored key(s)" },
1618
"log_NO_NEW_KEYS_ADDED": { "message": "No new keys added (all already present)" },
1719
"log_ALL_JSON_UPDATED": { "message": "All JSON files updated successfully" },
1820
"log_TYPE": { "message": "Type" },
1921
"log_TO_CREATE_DEFAULT_CONFIG": { "message": "to create default config file" },
2022
"log_FOR_AVAIL_OPTIONS": { "message": "for available options" },
23+
"log_VERSION": { "message": "version" },
2124
"tip_FOR_MORE_HELP_VISIT": { "message": "For more help, visit" },
2225
"tip_PASS_FORCE_TO_OVERWRITE": { "message": "Pass --force to overwrite" },
2326
"tip_MOVE_CONFIG_TO_ROOT": { "message": "Move config file to root of project you wish to use it in" },
@@ -33,6 +36,8 @@
3336
"err_PARSE_FAILED": { "message": "Failed to parse" },
3437
"err_TRANSLATE_FAILED_FOR_KEY": { "message": "Translation failed for key" },
3538
"err_EN_LOC_NOT_FOUND_AT": { "message": "English locale not found at" },
39+
"err_INVALID_KEY": { "message": "Invalid key" },
40+
"err_FOUND_IN": { "message": "found in" },
3641
"help_LOCALES_DIR": { "message": "Name of the folder containing locale files (default: \"_locales\")" },
3742
"help_TARGET_LANGS": { "message": "Languages to translate to (e.g. \"es,fr\") (default: all 100+ supported locales)" },
3843
"help_KEYS": { "message": "Keys to translate (e.g. \"app_DESC,err_NOT_FOUND\") (default: all found src keys missing in target files)" },

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def config_filepath(cli): # for settings.load()
4848
log.debug(f'Config file found: {cli.config_filepath}')
4949
return
5050
else:
51-
log.warn(f'{cli.msgs.warn_SPECIFIED_CONFIG} {cli.config_filepath} not found')
51+
log.warn(f'{cli.msgs.warn_SPECIFIED_CONFIG} {cli.config_filepath} {cli.msgs.warn_NOT_FOUND}')
5252

5353
# Search upwards
5454
possible_config_filenames = [

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def overwrite_print(msg, *args, **kwargs):
2929
sys.stdout.write('\r' + msg.format(*args, **kwargs).ljust(terminal_width)[:terminal_width])
3030
def success(msg, *args, **kwargs) : print(f'\n{colors.bg}{msg.format(*args, **kwargs)}{colors.nc}')
3131
def tip(msg, *args, **kwargs) : print(f'\n{colors.bc}TIP: {msg.format(*args, **kwargs)}{colors.nc}')
32-
def version(cli) : print(f'\n{colors.by}{cli.name}\n{colors.bw}version: {cli.version}{colors.nc}')
32+
def version(cli) : print(f'\n{colors.by}{cli.name}\n{colors.bw}{cli.msgs.log_VERSION}: {cli.version}{colors.nc}')
3333
def warn(msg, *args, **kwargs) : print(f'\n{colors.bo}WARNING: {msg.format(*args, **kwargs)}{colors.nc}')
3434

3535
def debug(msg, cli=None, *args, **kwargs):
@@ -42,8 +42,10 @@ def debug(msg, cli=None, *args, **kwargs):
4242
debug_key = sys.argv[debug_argidx +1].replace('-', '_')
4343

4444
if cli: # init data line
45-
data_val = getattr(cli.config, debug_key, f'cli.config key "{debug_key}" not found') if debug_key \
46-
else cli.config
45+
if debug_key:
46+
data_val = getattr(cli.config, debug_key, f'cli.config key "{debug_key}" {cli.msgs.warn_NOT_FOUND.lower()}')
47+
else:
48+
data_val = cli.config
4749
msg += f'\n{colors.gry}{data_val}{colors.nc}'
4850

4951
if args: # use 'em
@@ -56,7 +58,9 @@ def final_summary(msgs, summary_dict):
5658
for name, lang_set in summary_dict.items():
5759
if lang_set:
5860
status = name.replace('_', ' ')
59-
status_color = colors.by if status == 'translated' else colors.bg if status == 'added' else colors.gry
61+
status_color = colors.by if status == msgs.log_TRANSLATED.lower() \
62+
else colors.bg if status == msgs.log_ADDED.lower() \
63+
else colors.gry
6064
data(f'{msgs.log_LANGUAGES} {status}: {len(lang_set)}')
6165
print(f"{status_color}[ {', '.join(lang_set)} ]{colors.nc}")
6266

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def load(cli):
7777
setattr(cli.config, key, val)
7878
else:
7979
log.init_cmd_docs_url_exit(cli,
80-
f"Invalid key '{key}' found in \n{log.colors.gry}{cli.config_filepath}")
80+
f"{cli.msgs.err_INVALID_KEY} '{key}' {cli.msgs.err_FOUND_IN}"
81+
f'\n{log.colors.gry}{cli.config_filepath}'
82+
)
8183
log.debug('Config file loaded!', cli)
8284
else:
8385
log.debug('No config file found.')

0 commit comments

Comments
 (0)