Skip to content

Commit 21be8e0

Browse files
committed
Expanded --debug mode to cover regional langs
1 parent a8b50e8 commit 21be8e0

15 files changed

Lines changed: 23 additions & 90 deletions

File tree

get-min-py/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies = [
2222
"is-unicode-supported>=1.1.2,<2",
2323
"json5>=0.13.0,<1",
2424
"non-latin-locales>=1.0.1,<2",
25+
"sys-lang>=1.0.0,<2",
2526
]
2627
requires-python = ">=3.8,<4"
2728
keywords = [
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from pathlib import Path
22
from types import SimpleNamespace as sn
33

4+
from sys_lang import get_sys_lang
5+
46
from . import data
57

68
def cli() -> sn:
79
from . import env, language, settings
810
cli = data.sns.from_dict(data.json.read(Path(__file__).parent.parent.parent / 'data/package_data.json'))
911
cli.msgs = language.get_msgs(cli,
10-
language.generate_random_lang(excludes=['en']) if env.is_debug_mode() else language.get_sys_lang())
12+
language.generate_random_lang(excludes=['en']) if env.is_debug_mode() else get_sys_lang())
1113
settings.load(cli)
1214
return cli

get-min-py/src/get_min_py/cli/lib/language.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
import re, sys
2+
import re
33
from types import SimpleNamespace as sn
44
from typing import List, Optional
55

@@ -84,20 +84,3 @@ def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
8484
get_msgs.cached_lang = lang_code
8585

8686
return sn(**msgs)
87-
88-
def get_sys_lang(cli: Optional[sn] = None) -> str:
89-
import os, subprocess
90-
try:
91-
if sys.platform == 'win32':
92-
return subprocess.run(
93-
['powershell', '-Command', '(Get-Culture).TwoLetterISOLanguageName'],
94-
capture_output=True, text=True, check=True
95-
).stdout.strip()
96-
else: # macOS/Linux
97-
for env_lang_var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']:
98-
sys_lang = os.environ.get(env_lang_var)
99-
if sys_lang : return sys_lang.split('.')[0]
100-
return 'en'
101-
except Exception as err:
102-
if cli : log.error(f'{cli.msgs.err_FAILED_TO_FETCH_SYS_LANG}: {err}')
103-
return 'en'

is-legacy-terminal/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies = [
2222
"is-unicode-supported>=1.1.2,<2",
2323
"json5>=0.13.0,<1",
2424
"non-latin-locales>=1.0.1,<2",
25+
"sys-lang>=1.0.0,<2",
2526
]
2627
requires-python = ">=3.8,<4"
2728
keywords = [
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from pathlib import Path
22
from types import SimpleNamespace as sn
33

4+
from sys_lang import get_sys_lang
5+
46
from . import data
57

68
def cli() -> sn:
79
from . import env, language, settings
810
cli = data.sns.from_dict(data.json.read(Path(__file__).parent.parent.parent / 'data/package_data.json'))
911
cli.msgs = language.get_msgs(cli,
10-
language.generate_random_lang(excludes=['en']) if env.is_debug_mode() else language.get_sys_lang())
12+
language.generate_random_lang(excludes=['en']) if env.is_debug_mode() else get_sys_lang())
1113
settings.load(cli)
1214
return cli

is-legacy-terminal/src/is_legacy_terminal/cli/lib/language.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
import re, sys
2+
import re
33
from types import SimpleNamespace as sn
44
from typing import List, Optional
55

@@ -85,19 +85,3 @@ def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
8585

8686
return sn(**msgs)
8787

88-
def get_sys_lang(cli: Optional[sn] = None) -> str:
89-
import os, subprocess
90-
try:
91-
if sys.platform == 'win32':
92-
return subprocess.run(
93-
['powershell', '-Command', '(Get-Culture).TwoLetterISOLanguageName'],
94-
capture_output=True, text=True, check=True
95-
).stdout.strip()
96-
else: # macOS/Linux
97-
for env_lang_var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']:
98-
sys_lang = os.environ.get(env_lang_var)
99-
if sys_lang : return sys_lang.split('.')[0]
100-
return 'en'
101-
except Exception as err:
102-
if cli : log.error(f'{cli.msgs.err_FAILED_TO_FETCH_SYS_LANG}: {err}')
103-
return 'en'

is-unicode-supported/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies = [
2323
"is-legacy-terminal>=1.0.0,<2",
2424
"json5>=0.13.0,<1",
2525
"non-latin-locales>=1.0.1,<2",
26+
"sys-lang>=1.0.0,<2",
2627
]
2728
requires-python = ">=3.8,<4"
2829
keywords = [
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from pathlib import Path
22
from types import SimpleNamespace as sn
33

4+
from sys_lang import get_sys_lang
5+
46
from . import data
57

68
def cli() -> sn:
79
from . import env, language, settings
810
cli = data.sns.from_dict(data.json.read(Path(__file__).parent.parent.parent / 'data/package_data.json'))
911
cli.msgs = language.get_msgs(cli,
10-
language.generate_random_lang(excludes=['en']) if env.is_debug_mode() else language.get_sys_lang())
12+
language.generate_random_lang(excludes=['en']) if env.is_debug_mode() else get_sys_lang())
1113
settings.load(cli)
1214
return cli

is-unicode-supported/src/is_unicode_supported/cli/lib/language.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
import re, sys
2+
import re
33
from types import SimpleNamespace as sn
44
from typing import List, Optional
55

@@ -86,19 +86,3 @@ def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
8686

8787
return sn(**msgs)
8888

89-
def get_sys_lang(cli: Optional[sn] = None) -> str:
90-
import os, subprocess
91-
try:
92-
if sys.platform == 'win32':
93-
return subprocess.run(
94-
['powershell', '-Command', '(Get-Culture).TwoLetterISOLanguageName'],
95-
capture_output=True, text=True, check=True
96-
).stdout.strip()
97-
else: # macOS/Linux
98-
for env_lang_var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']:
99-
sys_lang = os.environ.get(env_lang_var)
100-
if sys_lang : return sys_lang.split('.')[0]
101-
return 'en'
102-
except Exception as err:
103-
if cli : log.error(f'{cli.msgs.err_FAILED_TO_FETCH_SYS_LANG}: {err}')
104-
return 'en'

remove-json-keys/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies = [
2323
"is-unicode-supported>=1.1.2,<2",
2424
"json5>=0.13.0,<1",
2525
"non-latin-locales>=1.0.1,<2",
26+
"sys-lang>=1.0.0,<2",
2627
]
2728
requires-python = ">=3.8,<4"
2829
keywords = [

0 commit comments

Comments
 (0)