Skip to content

Commit 410495a

Browse files
committed
Update translate files and status.htm
1 parent 23afed8 commit 410495a

3 files changed

Lines changed: 131 additions & 63 deletions

File tree

.github/workflows/translate.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Translate Chinese to English
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
translate:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Setup Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: 3.x
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install deep-translator
26+
27+
- name: Find and Translate Files
28+
run: |
29+
python translate_files.py
30+
31+
- name: Commit and Push Changes
32+
run: |
33+
git config --global user.name "GitHub Actions"
34+
git config --global user.email "actions@github.com"
35+
git add .
36+
git commit -m "Translate Chinese content to English"
37+
git push
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

luci-app-passwall/luasrc/view/passwall/global/status.htm

Lines changed: 48 additions & 63 deletions
Large diffs are not rendered by default.

translate_files.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import re
3+
import time
4+
from deep_translator import GoogleTranslator
5+
from multiprocessing import Pool, cpu_count
6+
7+
target_folder = "luci-app-passwall/root/usr/share/passwall"
8+
9+
translator = GoogleTranslator(source='zh-CN', target='en')
10+
11+
chinese_pattern = re.compile(r'[\u4e00-\u9fff]+')
12+
13+
def translate_file(file_path):
14+
print(f"Translating file: {file_path}")
15+
with open(file_path, "r", encoding="utf-8") as f:
16+
content = f.read()
17+
18+
def translate_match(match):
19+
try:
20+
return translator.translate(match.group(0))
21+
except Exception as e:
22+
print(f"Error translating text: {match.group(0)}. Skipping...")
23+
return match.group(0)
24+
25+
translated_content = chinese_pattern.sub(translate_match, content)
26+
27+
with open(file_path, "w", encoding="utf-8") as f:
28+
f.write(translated_content)
29+
30+
def process_files(files):
31+
with Pool(cpu_count()) as pool:
32+
pool.map(translate_file, files)
33+
34+
if __name__ == "__main__":
35+
files_to_translate = []
36+
for root, _, files in os.walk(target_folder):
37+
for file_name in files:
38+
file_path = os.path.join(root, file_name)
39+
if file_path.endswith((".txt", ".log", ".json", ".lua", ".sh")):
40+
files_to_translate.append(file_path)
41+
42+
print(f"Found {len(files_to_translate)} files to translate.")
43+
process_files(files_to_translate)
44+
print("Translation completed.")

0 commit comments

Comments
 (0)