Skip to content

Commit a77ad91

Browse files
committed
Added --only-stable option
1 parent f75c8e7 commit a77ad91

5 files changed

Lines changed: 20 additions & 13 deletions

File tree

translate-messages/.translate-msgs.config.json5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"keys": "", // keys to translate (e.g. "app_DESC,err_NOT_FOUND") (default: all missing src keys)
55
"exclude_langs": "", // languages to exclude (e.g. "en,es")
66
"exclude_keys": "", // keys to ignore (e.g. "app_NAME,author")
7+
"only_stable": false, // only use stable locales (skip auto-discovery)
78
"force": false, // force overwrite existing config file when using init
89
"no_wizard": false // skip interactive prompts during start-up
910
}

translate-messages/docs/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,34 @@ Options can be set by using command-line arguments:
4242
| Option | Description | Example
4343
| ---------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------
4444
| `-d`, `--locales-dir` | Name of the folder containing locale files (default: `_locales`) | `--locales-dir=_messages`
45-
| `-t`, `--target-langs` | Comma-separated list of languages to translate to (default: all [`supported_locales`][supported-locales]) | `--target-langs=en,es,fr`
45+
| `-t`, `--target-langs` | Comma-separated list of languages to translate to (default: all [`stable_locales`][stable-locales]) | `--target-langs=es,fr`
4646
| `-k`, `--keys` | Comma-separated list of keys to translate (default: all found src keys missing in target files) | `--keys=app_DESC,err_NOT_FOUND`
47-
| `--exclude-langs` | Comma-separated list of languages to exclude | `--exclude-langs=en,es`
47+
| `--exclude-langs` | Comma-separated list of languages to exclude | `--exclude-langs=es,zh`
4848
| `--exclude-keys` | Comma-separated list of keys to ignore | `--exclude-keys=app_NAME,author`
49+
| `--only-stable` | Only use stable locales (skip auto-discovery) |
4950
| `init`, `-i`, `--init` | Create `.translate-msgs.config.json5` in project root to store default options |
5051
| `-f`, `--force` | Force overwrite of existing config file when using `init` |
5152
| `-n`, `--no-wizard` | Skip interactive prompts during start-up |
5253
| `-h`, `--help` | Show help screen |
5354

5455
## Examples
5556

56-
Translate all keys except `app_NAME` from `_locales/en/messages.json` to all [`supported_locales`][supported-locales]:
57+
Translate all keys except `app_NAME` from `_locales/en/messages.json` to all [`stable_locales`][stable-locales]:
5758

5859
```bash
59-
translate-messages --ignore-keys=app_NAME # prompts for more keys to ignore
60+
translate-messages --ignore-keys=app_NAME # prompts for more keys to ignore
6061
```
6162

6263
Translate `app_DESC` key from `messges/en/messages.json` to French:
6364

6465
```bash
65-
translate-messages --keys=app_DESC --locales-dir=messages --target-langs=fr -n # no prompts
66+
translate-messages --keys=app_DESC --locales-dir=messages --target-langs=fr -n # no prompts
6667
```
6768

6869
Translate `app_DESC` + `err_NOT_FOUND` keys from `_msgs/en/messages.json` to Spanish and Hindi:
6970

7071
```bash
71-
translate-msgs -k app_DESC,err_NOT_FOUND -d _msgs -t es,hi -n # no prompts
72+
translate-msgs -k app_DESC,err_NOT_FOUND -d _msgs -t es,hi -n # no prompts
7273
```
7374

7475
## Config file
@@ -105,4 +106,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
105106

106107
<a href="#top">Back to top ↑</a>
107108

108-
[supported-locales]: https://github.com/adamlui/python-utils/blob/translate-messages-1.2.2/translate-messages/src/translate_messages/package_data.json#L21-L26
109+
[stable-locales]: https://github.com/adamlui/python-utils/blob/translate-messages-1.2.2/translate-messages/src/translate_messages/package_data.json#L22-L27

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"pypistats": "https://pypistats.org/packages/translate-messages",
1919
"support": "https://github.com/adamlui/python-utils/issues"
2020
},
21-
"supported_locales": [
21+
"stable_locales": [
2222
"af", "am", "ar", "az", "be", "bem", "bg", "bn", "bo", "bs", "ca", "ceb", "cs", "cy", "da", "de", "dv", "dz", "el",
2323
"en", "en-GB", "eo", "es", "et", "eu", "fa", "fi", "fo", "fr", "gd", "gl", "gu", "haw", "he", "hi", "hr", "ht",
2424
"hu", "hy", "id", "is", "it", "ja", "ka", "kab", "kk", "km", "kn", "ko", "ku", "ky", "la", "lb", "lo", "lt", "lv",

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ def src_msgs(cli):
4848

4949
def target_langs(cli):
5050
cli.config.target_langs = list(set(cli.config.target_langs)) # remove dupes
51-
if not cli.config.target_langs:
52-
cli.config.target_langs = cli.supported_locales
53-
for lang_path in cli.locales_path.rglob(f'*/{cli.msgs_filename}'): # merge discovered locales
51+
if not cli.config.target_langs: # init to stable ones
52+
cli.config.target_langs = cli.stable_locales
53+
if not cli.config.only_stable: # merge discovered locales
54+
for lang_path in cli.locales_path.rglob(f'*/{cli.msgs_filename}'):
5455
discovered_lang = lang_path.parent.name.replace('_', '-')
5556
if discovered_lang not in cli.config.target_langs:
5657
cli.config.target_langs.append(discovered_lang)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@
1111
),
1212
target_langs=sn(
1313
args=['-t', '--target-langs', '--include-langs'],
14-
type=str, parser='csv', help='Languages to translate to (e.g. "en,es,fr") (default: all 100+ supported locales)'
14+
type=str, parser='csv', help='Languages to translate to (e.g. "es,fr") (default: all 100+ supported locales)'
1515
),
1616
keys=sn(
1717
args=['-k', '--keys', '--include-keys', '--translate-keys'],
1818
type=str, parser='csv', help='Keys to translate (e.g. "app_DESC,err_NOT_FOUND") (default: all found src keys missing in target files)'
1919
),
2020
exclude_langs=sn(
2121
args=['--exclude-langs', '--ignore-langs'],
22-
type=str, parser='csv', help='Languages to exclude (e.g. "en,es")'
22+
type=str, parser='csv', help='Languages to exclude (e.g. "es,zh")'
2323
),
2424
exclude_keys=sn(
2525
args=['--exclude-keys', '--ignore-keys'],
2626
type=str, parser='csv', help='Keys to ignore (e.g. "app_NAME,author")'
2727
),
28+
only_stable=sn(
29+
args=['-s', '--only-stable', '--no-discovery'],
30+
action='store_true', help='Only use stable locales (skip auto-discovery)'
31+
),
2832
init=sn(
2933
args=['-i', '--init'],
3034
action='store_true', subcmd='true', help='Create .translate-msgs.config.json5 file to store default options'

0 commit comments

Comments
 (0)