Skip to content

Commit bf6c9f8

Browse files
committed
Used is-unicode-supported
1 parent 39b4262 commit bf6c9f8

9 files changed

Lines changed: 18 additions & 42 deletions

File tree

get-min-py/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ license-files = [
1919
]
2020
dependencies = [
2121
"colorama~=0.4.6 ; platform_system == 'Windows'",
22+
"is-unicode-supported~=1.0.0",
2223
"json5~=0.13.0",
2324
"ucs-detect~=2.0.2",
2425
]
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
import sys
22

3-
def can_render_non_latin_scripts() -> bool: # e.g. ar, dv, zh
4-
import json, os, subprocess
5-
try:
6-
result = subprocess.run(
7-
['ucs-detect', '--quick', '--save-json', '-'], # to stdout vs. file
8-
capture_output=True, text=True, timeout=0.1
9-
)
10-
return json.loads(result.stdout).get('wide', False)
11-
except (subprocess.TimeoutExpired, json.JSONDecodeError, FileNotFoundError):
12-
return os.environ.get('WT_SESSION') is not None if sys.platform == 'win32' else True
13-
143
def is_debug_mode() -> bool:
154
return any(arg in ('--debug', '-V') for arg in sys.argv[1:])

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_locales() -> List[str]:
5555
return random_lang
5656

5757
def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
58-
from . import env, jsdelivr, url
58+
from . import jsdelivr, url
5959

6060
lang_code = format_code(lang_code)
6161
if getattr(get_msgs, 'cached', None) and lang_code == get_msgs.cached_lang:
@@ -65,8 +65,10 @@ def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
6565
Path(__file__).parent.parent.parent / 'data/_locales/en/messages.json'))
6666

6767
if not lang_code.startswith('en'): # fetch non-English msgs from jsDelivr
68-
import non_latin_locales
69-
if lang_code.split('_')[0] in non_latin_locales and not env.can_render_non_latin_scripts(): # type: ignore
68+
import is_unicode_supported, non_latin_locales
69+
if not hasattr(get_msgs, 'cached_unicode_support'):
70+
get_msgs.cached_unicode_support = is_unicode_supported() # type: ignore
71+
if lang_code.split('_')[0] in non_latin_locales and not get_msgs.cached_unicode_support: # type: ignore
7072
return sn(**msgs) # EN ones cuz non-Latin not supported
7173
msg_base_url = f'{jsdelivr.create_commit_url(cli, cli.commit_hashes.locales)}' \
7274
'/src/get_min_py/data/_locales'

remove-json-keys/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ license-files = [
2020
dependencies = [
2121
"colorama~=0.4.6 ; platform_system == 'Windows'",
2222
"find-project-root~=1.0.3",
23+
"is-unicode-supported~=1.0.0",
2324
"json5~=0.13.0",
2425
"non-latin-locales~=1.0.1",
2526
"ucs-detect~=2.0.2",
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
import sys
22

3-
def can_render_non_latin_scripts() -> bool: # e.g. ar, dv, zh
4-
import json, os, subprocess
5-
try:
6-
result = subprocess.run(
7-
['ucs-detect', '--quick', '--save-json', '-'], # to stdout vs. file
8-
capture_output=True, text=True, timeout=0.1
9-
)
10-
return json.loads(result.stdout).get('wide', False)
11-
except (subprocess.TimeoutExpired, json.JSONDecodeError, FileNotFoundError):
12-
return os.environ.get('WT_SESSION') is not None if sys.platform == 'win32' else True
13-
143
def is_debug_mode() -> bool:
154
return any(arg in ('--debug', '-V') for arg in sys.argv[1:])

remove-json-keys/src/remove_json_keys/cli/lib/language.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_locales() -> List[str]:
5555
return random_lang
5656

5757
def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
58-
from . import env, jsdelivr, url
58+
from . import jsdelivr, url
5959

6060
lang_code = format_code(lang_code)
6161
if getattr(get_msgs, 'cached', None) and lang_code == get_msgs.cached_lang:
@@ -65,8 +65,10 @@ def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
6565
Path(__file__).parent.parent.parent / 'data/_locales/en/messages.json'))
6666

6767
if not lang_code.startswith('en'): # fetch non-English msgs from jsDelivr
68-
import non_latin_locales
69-
if lang_code.split('_')[0] in non_latin_locales and not env.can_render_non_latin_scripts(): # type: ignore
68+
import is_unicode_supported, non_latin_locales
69+
if not hasattr(get_msgs, 'cached_unicode_support'):
70+
get_msgs.cached_unicode_support = is_unicode_supported() # type: ignore
71+
if lang_code.split('_')[0] in non_latin_locales and not get_msgs.cached_unicode_support: # type: ignore
7072
return sn(**msgs) # EN ones cuz non-Latin not supported
7173
msg_base_url = f'{jsdelivr.create_commit_url(cli, cli.commit_hashes.locales)}' \
7274
'/src/remove_json_keys/data/_locales'

translate-messages/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ license-files = [
2020
dependencies = [
2121
"colorama~=0.4.6 ; platform_system == 'Windows'",
2222
"find-project-root~=1.0.3",
23+
"is-unicode-supported~=1.0.0",
2324
"json5~=0.13.0",
2425
"non-latin-locales~=1.0.1",
2526
"translate~=3.8.0",
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
import sys
22

3-
def can_render_non_latin_scripts() -> bool: # e.g. ar, dv, zh
4-
import json, os, subprocess
5-
try:
6-
result = subprocess.run(
7-
['ucs-detect', '--quick', '--save-json', '-'], # to stdout vs. file
8-
capture_output=True, text=True, timeout=0.1
9-
)
10-
return json.loads(result.stdout).get('wide', False)
11-
except (subprocess.TimeoutExpired, json.JSONDecodeError, FileNotFoundError):
12-
return os.environ.get('WT_SESSION') is not None if sys.platform == 'win32' else True
13-
143
def is_debug_mode() -> bool:
154
return any(arg in ('--debug', '-V') for arg in sys.argv[1:])

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def get_locales() -> List[str]:
8686
return random_lang
8787

8888
def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
89-
from . import env, jsdelivr, url
89+
from . import jsdelivr, url
9090

9191
lang_code = format_code(lang_code)
9292
if getattr(get_msgs, 'cached', None) and lang_code == get_msgs.cached_lang:
@@ -96,8 +96,10 @@ def get_msgs(cli: sn, lang_code: str = 'en') -> sn:
9696
Path(__file__).parent.parent.parent / 'data/_locales/en/messages.json'))
9797

9898
if not lang_code.startswith('en'): # fetch non-English msgs from jsDelivr
99-
import non_latin_locales
100-
if lang_code.split('_')[0] in non_latin_locales and not env.can_render_non_latin_scripts(): # type: ignore
99+
import is_unicode_supported, non_latin_locales
100+
if not hasattr(get_msgs, 'cached_unicode_support'):
101+
get_msgs.cached_unicode_support = is_unicode_supported() # type: ignore
102+
if lang_code.split('_')[0] in non_latin_locales and not get_msgs.cached_unicode_support: # type: ignore
101103
return sn(**msgs) # EN ones cuz non-Latin not supported
102104
msg_base_url = f'{jsdelivr.create_commit_url(cli, cli.commit_hashes.locales)}' \
103105
'/src/translate_messages/data/_locales'

0 commit comments

Comments
 (0)