silentstudio 0.3.2__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {silentstudio-0.3.2/src/silentstudio.egg-info → silentstudio-0.3.3}/PKG-INFO +1 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3}/pyproject.toml +1 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3}/setup.py +1 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/__init__.py +1 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/cli.py +7 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/config_cli.py +4 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/i18n.py +17 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/installer.py +1 -1
- silentstudio-0.3.3/src/silentstudio/language_pack.py +82 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/sources.py +11 -13
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/utils.py +5 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3/src/silentstudio.egg-info}/PKG-INFO +1 -1
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio.egg-info/SOURCES.txt +1 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/LICENSE +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/README.md +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/setup.cfg +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/__main__.py +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/config.py +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/list_packages.py +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/platform.py +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/project_new.py +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio/release.py +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio.egg-info/dependency_links.txt +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio.egg-info/entry_points.txt +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio.egg-info/requires.txt +0 -0
- {silentstudio-0.3.2 → silentstudio-0.3.3}/src/silentstudio.egg-info/top_level.txt +0 -0
|
@@ -29,8 +29,14 @@ GIT_COMMANDS = {
|
|
|
29
29
|
def _main():
|
|
30
30
|
"""主入口"""
|
|
31
31
|
ensure_command_aliases()
|
|
32
|
+
|
|
33
|
+
from .language_pack import first_run_language
|
|
34
|
+
from .i18n import apply_cached_pack
|
|
35
|
+
|
|
36
|
+
detected = first_run_language()
|
|
32
37
|
config = load_config()
|
|
33
|
-
lang = get_system_language(config.get("language", "auto"))
|
|
38
|
+
lang = detected or get_system_language(config.get("language", "auto"))
|
|
39
|
+
apply_cached_pack(lang)
|
|
34
40
|
|
|
35
41
|
argv = sys.argv[1:]
|
|
36
42
|
if argv and argv[0] in ("release", "releases"):
|
|
@@ -66,6 +66,10 @@ def handle_config(argv: list[str]) -> int:
|
|
|
66
66
|
if value != "auto":
|
|
67
67
|
value = normalize_language(value)
|
|
68
68
|
|
|
69
|
+
if key == "language" and value == "auto":
|
|
70
|
+
from .language_pack import reset_first_run
|
|
71
|
+
reset_first_run()
|
|
72
|
+
|
|
69
73
|
config[key] = value
|
|
70
74
|
save_config(config)
|
|
71
75
|
print(f"{key} = {value}")
|
|
@@ -201,7 +201,7 @@ def detect_language() -> str:
|
|
|
201
201
|
def get_language(config_lang: str = "auto") -> str:
|
|
202
202
|
if config_lang and config_lang != "auto":
|
|
203
203
|
return normalize_language(config_lang)
|
|
204
|
-
return
|
|
204
|
+
return "en"
|
|
205
205
|
|
|
206
206
|
|
|
207
207
|
def tr(key: str, lang: str = "en", **kwargs) -> str:
|
|
@@ -310,3 +310,19 @@ def help_text(version: str, lang: str) -> str:
|
|
|
310
310
|
]
|
|
311
311
|
return "\n".join(lines)
|
|
312
312
|
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def apply_cached_pack(lang: str) -> None:
|
|
316
|
+
"""Merge a downloaded language pack over the built-in strings."""
|
|
317
|
+
import json
|
|
318
|
+
from pathlib import Path
|
|
319
|
+
|
|
320
|
+
path = Path.home() / ".silentstudio" / "lang" / f"{lang}.json"
|
|
321
|
+
if not path.is_file():
|
|
322
|
+
return
|
|
323
|
+
try:
|
|
324
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
325
|
+
except Exception:
|
|
326
|
+
return
|
|
327
|
+
STRINGS.setdefault(lang, {}).update(data.get("strings", {}))
|
|
328
|
+
HELP_TEXT.setdefault(lang, {}).update(data.get("help", {}))
|
|
@@ -57,7 +57,7 @@ def _choose_source(rows, lang: str):
|
|
|
57
57
|
return best
|
|
58
58
|
|
|
59
59
|
while True:
|
|
60
|
-
prompt = "
|
|
60
|
+
prompt = "选择安装源: " if lang == "zh-CN" else "Select source: "
|
|
61
61
|
try:
|
|
62
62
|
choice = input(prompt).strip()
|
|
63
63
|
except EOFError:
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""First-run IP language detection and remote language packs."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
from .config import load_config, save_config
|
|
11
|
+
|
|
12
|
+
PACK_DIR = Path.home() / ".silentstudio" / "lang"
|
|
13
|
+
MARKER = Path.home() / ".silentstudio" / ".language_initialized"
|
|
14
|
+
RAW_BASES = [
|
|
15
|
+
"https://raw.githubusercontent.com/Silent-Studio-CN/SilentStudioCLI/main/lang",
|
|
16
|
+
"https://gh-proxy.com/https://raw.githubusercontent.com/Silent-Studio-CN/SilentStudioCLI/main/lang",
|
|
17
|
+
"https://ghproxy.net/https://raw.githubusercontent.com/Silent-Studio-CN/SilentStudioCLI/main/lang",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
COUNTRY_LANGUAGE = {
|
|
21
|
+
"CN": "zh-CN", "TW": "zh-TW", "HK": "zh-TW", "MO": "zh-TW",
|
|
22
|
+
"JP": "ja", "KR": "ko", "RU": "ru",
|
|
23
|
+
"ES": "es", "MX": "es", "AR": "es", "CO": "es", "CL": "es", "PE": "es",
|
|
24
|
+
"IT": "it",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def detect_country() -> Optional[str]:
|
|
29
|
+
for url in ("https://ipapi.co/country/", "https://ipinfo.io/country"):
|
|
30
|
+
try:
|
|
31
|
+
response = requests.get(url, timeout=3)
|
|
32
|
+
if response.status_code == 200:
|
|
33
|
+
value = response.text.strip().upper()
|
|
34
|
+
if len(value) == 2:
|
|
35
|
+
return value
|
|
36
|
+
except Exception:
|
|
37
|
+
continue
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def language_for_country(country: Optional[str]) -> str:
|
|
42
|
+
if not country:
|
|
43
|
+
return "en"
|
|
44
|
+
return COUNTRY_LANGUAGE.get(country.upper(), "en")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def download_pack(language: str) -> bool:
|
|
48
|
+
PACK_DIR.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
target = PACK_DIR / f"{language}.json"
|
|
50
|
+
for base in RAW_BASES:
|
|
51
|
+
try:
|
|
52
|
+
response = requests.get(f"{base}/{language}.json", timeout=6)
|
|
53
|
+
if response.status_code != 200:
|
|
54
|
+
continue
|
|
55
|
+
data = response.json()
|
|
56
|
+
if not isinstance(data, dict):
|
|
57
|
+
continue
|
|
58
|
+
target.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
59
|
+
return True
|
|
60
|
+
except Exception:
|
|
61
|
+
continue
|
|
62
|
+
return False
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def first_run_language() -> Optional[str]:
|
|
66
|
+
"""Return a language on the first auto run, or None if already initialized."""
|
|
67
|
+
config = load_config()
|
|
68
|
+
if config.get("language", "auto") != "auto" or MARKER.exists():
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
language = language_for_country(detect_country())
|
|
72
|
+
download_pack(language)
|
|
73
|
+
config["language"] = language
|
|
74
|
+
save_config(config)
|
|
75
|
+
MARKER.parent.mkdir(parents=True, exist_ok=True)
|
|
76
|
+
MARKER.write_text(language + "\n", encoding="utf-8")
|
|
77
|
+
return language
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def reset_first_run() -> None:
|
|
81
|
+
if MARKER.exists():
|
|
82
|
+
MARKER.unlink()
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
import itertools
|
|
5
5
|
import re
|
|
6
|
+
import shutil
|
|
6
7
|
import subprocess
|
|
7
8
|
import sys
|
|
8
9
|
import threading
|
|
@@ -71,19 +72,16 @@ def _stream_table(package: str, sources, minimum: float = 1.5):
|
|
|
71
72
|
threads.append(thread)
|
|
72
73
|
|
|
73
74
|
print(f"Package: {package}")
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
width = max(40, shutil.get_terminal_size((80, 24)).columns - 1)
|
|
76
|
+
header = f"{'Source':<12} {'Version':<16} URL"[:width]
|
|
77
|
+
print(header)
|
|
78
|
+
print("-" * min(72, width))
|
|
77
79
|
|
|
78
|
-
def
|
|
79
|
-
|
|
80
|
-
cell = rows[index] or character or ""
|
|
81
|
-
line = f"{name:<12} {cell:<16} {url}"
|
|
82
|
-
print(line.ljust(width))
|
|
80
|
+
def line_for(cell: str, name: str, url: str) -> str:
|
|
81
|
+
return f"{name:<12} {cell:<16} {url}"[:width]
|
|
83
82
|
|
|
84
|
-
for
|
|
85
|
-
|
|
86
|
-
print(f"{name:<12} {'':<16} {url}".ljust(width))
|
|
83
|
+
for index, (name, url) in enumerate(sources):
|
|
84
|
+
print(line_for("", name, url))
|
|
87
85
|
|
|
88
86
|
started = time.monotonic()
|
|
89
87
|
frames = itertools.cycle("|/-\\")
|
|
@@ -97,12 +95,12 @@ def _stream_table(package: str, sources, minimum: float = 1.5):
|
|
|
97
95
|
sys.stdout.write(f"\x1b[{len(sources)}A")
|
|
98
96
|
for index, (name, url) in enumerate(sources):
|
|
99
97
|
cell = rows[index] or next(frames)
|
|
100
|
-
|
|
98
|
+
sys.stdout.write("\r" + line_for(cell, name, url).ljust(width) + "\n")
|
|
101
99
|
sys.stdout.flush()
|
|
102
100
|
time.sleep(0.12)
|
|
103
101
|
sys.stdout.write(f"\x1b[{len(sources)}A")
|
|
104
102
|
for index, (name, url) in enumerate(sources):
|
|
105
|
-
|
|
103
|
+
sys.stdout.write("\r" + line_for(rows[index] or "not found", name, url).ljust(width) + "\n")
|
|
106
104
|
sys.stdout.flush()
|
|
107
105
|
finally:
|
|
108
106
|
sys.stdout.write("\x1b[?25h")
|
|
@@ -15,8 +15,12 @@ def detect_language() -> str:
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def get_system_language(config_lang: str = "auto") -> str:
|
|
18
|
-
"""
|
|
18
|
+
"""获取最终使用的语言;默认英语,首次运行由 language_pack 写入配置。"""
|
|
19
|
+
from .config import load_config
|
|
19
20
|
from .i18n import get_language
|
|
21
|
+
|
|
22
|
+
if config_lang == "auto":
|
|
23
|
+
config_lang = load_config().get("language", "auto")
|
|
20
24
|
return get_language(config_lang)
|
|
21
25
|
|
|
22
26
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|