Skip to content

Commit 80b8adf

Browse files
committed
Add some translations
1 parent 88b43d4 commit 80b8adf

16 files changed

+2166
-243
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 为support文件夹中的文件配置翻译
2+
3+
## 目标
4+
为support文件夹中所有未配置翻译的文件创建对应的翻译函数,每个文件对应一个翻译函数。
5+
6+
## 已完成的翻译函数
7+
- arguements.py → arguements()
8+
- defaults.py → defaults()
9+
- generate_smbios.py → generate_smbios()
10+
- global_settings.py → global_settings()
11+
- install.py → install()
12+
- integrity_verification.py → integrity_verification()
13+
- kdk_handler.py → kdk_handler()
14+
15+
## 需要添加的翻译函数
16+
1. analytics_handler.py → analytics_handler()
17+
2. commit_info.py → commit_info()
18+
3. logging_handler.py → logging_handler()
19+
4. macos_installer_handler.py → macos_installer_handler()
20+
5. metallib_handler.py → metallib_handler()
21+
6. network_handler.py → network_handler()
22+
7. private.py → private()
23+
8. reroute_payloads.py → reroute_payloads()
24+
9. subprocess_wrapper.py → subprocess_wrapper()
25+
10. updates.py → updates()
26+
11. utilities.py → utilities()
27+
12. validation.py → validation()
28+
29+
## 实现步骤
30+
1. 为每个需要翻译的文件创建一个对应的翻译函数
31+
2. 每个翻译函数包含英文和中文两种语言的翻译字典
32+
3. 翻译字典包含该文件中所有需要翻译的文本
33+
4. 保持与现有翻译函数相同的格式和结构
34+
35+
## 注意事项
36+
- 每个翻译函数的命名格式为:`def 文件名():`
37+
- 翻译字典中键为英文文本,值为对应语言的翻译
38+
- 对于中文语言点(language_point==0),提供中文翻译
39+
- 对于英文语言点(language_point==1),保持英文原文
40+
- 确保所有需要翻译的文本都被包含在翻译字典中
41+
- 保持代码格式一致,使用相同的缩进和换行格式

oclp_r/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def __init__(self) -> None:
252252
self.apfs_trim_timeout: bool = True # Set APFS Trim timeout
253253
self.custom_sip_value: int = None # Set custom SIP value
254254
self.allow_apfs_aligned_patch: bool = True
255+
self.language_choose: int = 1 #1:en 0:zh
255256

256257
## Non-Metal OS support
257258
self.legacy_accel_support = [

oclp_r/support/arguments.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from . import (
2929
utilities,
3030
defaults,
31-
validation
31+
validation,
32+
translate_language
3233
)
3334

3435

@@ -38,6 +39,7 @@ class arguments:
3839

3940
def __init__(self, global_constants: constants.Constants) -> None:
4041
self.constants: constants.Constants = global_constants
42+
self.trans = translate_language.TranslateLanguage(self.constants).arguements()
4143

4244
self.args = utilities.check_cli_args()
4345

@@ -82,7 +84,7 @@ def _validation_handler(self) -> None:
8284
"""
8385
Enter validation mode
8486
"""
85-
logging.info("Set Validation Mode")
87+
logging.info(self.trans["Set Validation Mode"])
8688
validation.PatcherValidation(self.constants)
8789

8890

@@ -91,9 +93,9 @@ def _sys_patch_handler(self) -> None:
9193
Start root volume patching
9294
"""
9395

94-
logging.info("Set System Volume patching")
96+
logging.info(self.trans["Set System Volume patching"])
9597
if "Library/InstallerSandboxes/" in str(self.constants.payload_path):
96-
logging.info("- Running from Installer Sandbox, blocking OS updaters")
98+
logging.info(self.trans["- Running from Installer Sandbox, blocking OS updaters"])
9799
thread = threading.Thread(target=sys_patch.PatchSysVolume(self.constants.custom_model or self.constants.computer.real_model, self.constants, None).start_patch)
98100
thread.start()
99101
while thread.is_alive():
@@ -107,7 +109,7 @@ def _sys_unpatch_handler(self) -> None:
107109
"""
108110
Start root volume unpatching
109111
"""
110-
logging.info("Set System Volume unpatching")
112+
logging.info(self.trans["Set System Volume unpatching"])
111113
sys_patch.PatchSysVolume(self.constants.custom_model or self.constants.computer.real_model, self.constants, None).start_unpatch()
112114

113115

@@ -116,25 +118,25 @@ def _sys_patch_auto_handler(self) -> None:
116118
Start root volume auto patching
117119
"""
118120

119-
logging.info("Set Auto patching")
121+
logging.info(self.trans["Set Auto patching"])
120122
StartAutomaticPatching(self.constants).start_auto_patch()
121123

122124

123125
def _prepare_for_update_handler(self) -> None:
124126
"""
125127
Prepare host for macOS update
126128
"""
127-
logging.info("Preparing host for macOS update")
129+
logging.info(self.trans["Preparing host for macOS update"])
128130

129131
os_data = utilities.fetch_staged_update(variant="Update")
130132
if os_data[0] is None:
131-
logging.info("No update staged, skipping")
133+
logging.info(self.trans["No update staged, skipping"])
132134
return
133135

134136
os_version = os_data[0]
135137
os_build = os_data[1]
136138

137-
logging.info(f"Preparing for update to {os_version} ({os_build})")
139+
logging.info(f"{self.trans['Preparing for update to']} {os_version} ({os_build})")
138140

139141
self._clean_le_handler()
140142

@@ -145,7 +147,7 @@ def _cache_os_handler(self) -> None:
145147
"""
146148
results = subprocess.run(["/bin/ps", "-ax"], stdout=subprocess.PIPE)
147149
if results.stdout.decode("utf-8").count("OCLP-R --cache_os") > 1:
148-
logging.info("Another instance of OS caching is running, exiting")
150+
logging.info(self.trans["Another instance of OS caching is running, exiting"])
149151
return
150152

151153
gui_entry.EntryPoint(self.constants).start(entry=gui_entry.SupportedEntryPoints.OS_CACHE)
@@ -160,100 +162,100 @@ def _clean_le_handler(self) -> None:
160162
if self.constants.detected_os < os_data.os_data.sonoma:
161163
return
162164

163-
logging.info("Cleaning /Library/Extensions")
165+
logging.info(self.trans["Cleaning /Library/Extensions"])
164166

165167
for kext in Path("/Library/Extensions").glob("*.kext"):
166168
if not Path(f"{kext}/Contents/Info.plist").exists():
167169
continue
168170
try:
169171
kext_plist = plistlib.load(open(f"{kext}/Contents/Info.plist", "rb"))
170172
except Exception as e:
171-
logging.info(f" - Failed to load plist for {kext.name}: {e}")
173+
logging.info(f" {self.trans['- Failed to load plist for']} {kext.name}: {e}")
172174
continue
173175
if "GPUCompanionBundles" not in kext_plist:
174176
continue
175-
logging.info(f" - Removing {kext.name}")
177+
logging.info(f" {self.trans['- Removing']} {kext.name}")
176178
subprocess_wrapper.run_as_root(["/bin/rm", "-rf", kext])
177179

178180

179181
def _build_handler(self) -> None:
180182
"""
181183
Start config building process
182184
"""
183-
logging.info("Set OpenCore Build")
185+
logging.info(self.trans["Set OpenCore Build"])
184186

185187
if self.args.model:
186188
if self.args.model:
187-
logging.info(f"- Using custom model: {self.args.model}")
189+
logging.info(f"{self.trans['- Using custom model:']} {self.args.model}")
188190
self.constants.custom_model = self.args.model
189191
defaults.GenerateDefaults(self.constants.custom_model, False, self.constants)
190192
elif self.constants.computer.real_model not in model_array.SupportedSMBIOS and self.constants.allow_oc_everywhere is False:
191193
logging.info(
192-
"""Your model is not supported by this patcher for running unsupported OSes!"
194+
self.trans["""Your model is not supported by this patcher for running unsupported OSes!
193195
194-
If you plan to create the USB for another machine, please select the "Change Model" option in the menu."""
196+
If you plan to create the USB for another machine, please select the "Change Model" option in the menu."""]
195197
)
196198
sys.exit(1)
197199
else:
198-
logging.info(f"- Using detected model: {self.constants.computer.real_model}")
200+
logging.info(f"{self.trans['- Using detected model:']} {self.constants.computer.real_model}")
199201
defaults.GenerateDefaults(self.constants.custom_model, True, self.constants)
200202

201203
if self.args.verbose:
202-
logging.info("- Set verbose configuration")
204+
logging.info(self.trans["- Set verbose configuration"])
203205
self.constants.verbose_debug = True
204206
else:
205207
self.constants.verbose_debug = False # Override Defaults detected
206208

207209
if self.args.debug_oc:
208-
logging.info("- Set OpenCore DEBUG configuration")
210+
logging.info(self.trans["- Set OpenCore DEBUG configuration"])
209211
self.constants.opencore_debug = True
210212

211213
if self.args.debug_kext:
212-
logging.info("- Set kext DEBUG configuration")
214+
logging.info(self.trans["- Set kext DEBUG configuration"])
213215
self.constants.kext_debug = True
214216

215217
if self.args.hide_picker:
216-
logging.info("- Set HidePicker configuration")
218+
logging.info(self.trans["- Set HidePicker configuration"])
217219
self.constants.showpicker = False
218220

219221
if self.args.disable_sip:
220-
logging.info("- Set Disable SIP configuration")
222+
logging.info(self.trans["- Set Disable SIP configuration"])
221223
self.constants.sip_status = False
222224
else:
223225
self.constants.sip_status = True # Override Defaults detected
224226

225227
if self.args.disable_smb:
226-
logging.info("- Set Disable SecureBootModel configuration")
228+
logging.info(self.trans["- Set Disable SecureBootModel configuration"])
227229
self.constants.secure_status = False
228230
else:
229231
self.constants.secure_status = True # Override Defaults detected
230232

231233
if self.args.vault:
232-
logging.info("- Set Vault configuration")
234+
logging.info(self.trans["- Set Vault configuration"])
233235
self.constants.vault = True
234236

235237
if self.args.firewire:
236-
logging.info("- Set FireWire Boot configuration")
238+
logging.info(self.trans["- Set FireWire Boot configuration"])
237239
self.constants.firewire_boot = True
238240

239241
if self.args.nvme:
240-
logging.info("- Set NVMe Boot configuration")
242+
logging.info(self.trans["- Set NVMe Boot configuration"])
241243
self.constants.nvme_boot = True
242244

243245
if self.args.wlan:
244-
logging.info("- Set Wake on WLAN configuration")
246+
logging.info(self.trans["- Set Wake on WLAN configuration"])
245247
self.constants.enable_wake_on_wlan = True
246248

247249
if self.args.disable_tb:
248-
logging.info("- Set Disable Thunderbolt configuration")
250+
logging.info(self.trans["- Set Disable Thunderbolt configuration"])
249251
self.constants.disable_tb = True
250252

251253
if self.args.force_surplus:
252-
logging.info("- Forcing SurPlus override configuration")
254+
logging.info(self.trans["- Forcing SurPlus override configuration"])
253255
self.constants.force_surplus = True
254256

255257
if self.args.moderate_smbios:
256-
logging.info("- Set Moderate SMBIOS Patching configuration")
258+
logging.info(self.trans["- Set Moderate SMBIOS Patching configuration"])
257259
self.constants.serial_settings = "Moderate"
258260

259261
if self.args.smbios_spoof:
@@ -264,10 +266,10 @@ def _build_handler(self) -> None:
264266
elif self.args.smbios_spoof == "Advanced":
265267
self.constants.serial_settings = "Advanced"
266268
else:
267-
logging.info(f"- Unknown SMBIOS arg passed: {self.args.smbios_spoof}")
269+
logging.info(f"{self.trans['- Unknown SMBIOS arg passed:']} {self.args.smbios_spoof}")
268270

269271
if self.args.support_all:
270-
logging.info("- Building for natively supported model")
272+
logging.info(self.trans["- Building for natively supported model"])
271273
self.constants.allow_oc_everywhere = True
272274
self.constants.serial_settings = "None"
273275

oclp_r/support/defaults.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from . import (
1616
utilities,
1717
generate_smbios,
18-
global_settings
18+
global_settings,
19+
translate_language
1920
)
2021
from ..datasets import (
2122
smbios_data,
@@ -28,7 +29,7 @@ class GenerateDefaults:
2829

2930
def __init__(self, model: str, host_is_target: bool, global_constants: constants.Constants, ignore_settings_file: bool = False) -> None:
3031
self.constants: constants.Constants = global_constants
31-
32+
self.trans=translate_language.TranslateLanguage(global_constants=global_constants).defaults()
3233
self.model: str = model
3334

3435
self.host_is_target: bool = host_is_target
@@ -421,7 +422,7 @@ def _load_gui_defaults(self) -> None:
421422
try:
422423
plist = plistlib.load(Path(settings_plist).open("rb"))
423424
except Exception as e:
424-
logging.error("Error: Unable to read global settings file")
425+
logging.error(self.trans["Error: Unable to read global settings file"])
425426
logging.error(e)
426427
return
427428

@@ -439,10 +440,10 @@ def _load_gui_defaults(self) -> None:
439440
original_type = type(getattr(self.constants, constants_key))
440441
new_type = type(plist[key])
441442
if original_type != new_type:
442-
logging.error(f"Global settings type mismatch for {constants_key}: {original_type} vs {new_type}")
443-
logging.error(f"Removing {key} from global settings")
443+
logging.error(f"{self.trans['Global settings type mismatch for']} {constants_key}: {original_type} {self.trans['vs']} {new_type}")
444+
logging.error(f"{self.trans['Removing']} {key} {self.trans['from global settings']}")
444445
global_settings.GlobalEnviromentSettings().delete_property(key)
445446
continue
446447

447-
logging.info(f"Setting {constants_key} to {plist[key]}")
448+
logging.info(f"{self.trans['Setting']} {constants_key} {self.trans['to']} {plist[key]}")
448449
setattr(self.constants, constants_key, plist[key])

oclp_r/support/generate_smbios.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
cpu_data
1313
)
1414

15-
1615
def set_smbios_model_spoof(model):
1716
try:
1817
smbios_data.smbios_dictionary[model]["Screen Size"]

oclp_r/support/global_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _generate_settings_file(self) -> None:
8686
if Path(self.global_settings_plist).exists():
8787
return
8888
try:
89-
plistlib.dump({"Developed by Hackdoc and Hackdoc": True,}, Path(self.global_settings_plist).open("wb"))
89+
plistlib.dump({"Developed by Dortania and Hackdoc": True,}, Path(self.global_settings_plist).open("wb"))
9090
except PermissionError:
9191
logging.info("Permission error: Unable to write to global settings file")
9292

0 commit comments

Comments
 (0)