Skip to content

Commit

Permalink
<feature> support replace special symbols in html export and import
Browse files Browse the repository at this point in the history
update version to v2.0.8
  • Loading branch information
anonymousException committed Apr 6, 2024
1 parent c7f3e01 commit 4dc5445
Show file tree
Hide file tree
Showing 31 changed files with 1,086 additions and 874 deletions.
150 changes: 117 additions & 33 deletions src/editor_form.py

Large diffs are not rendered by default.

45 changes: 38 additions & 7 deletions src/html_util.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import json
import os.path

from bs4 import BeautifulSoup, NavigableString

from my_log import log_print
from renpy_translate import get_translated

last_write_html = None
last_translated_dic = None


def write_html_with_strings(p, strings):
def write_html_with_strings(p, strings, data):
if strings is None:
return
soup = BeautifulSoup('<html><body></body></html>', 'html.parser')
for s in strings:
p_tag = soup.new_tag("p")
p_tag.string = s
soup.body.append(p_tag)

if data is not None:
data_div = soup.new_tag("div", id="data", style="display: none;")
data_div.string = data
soup.body.append(data_div)
with open(p, "w", encoding='utf-8') as f:
f.write(str(soup))
global last_write_html
Expand All @@ -29,8 +34,12 @@ def read_strings_from_html(p):
with open(p, "r", encoding="utf-8") as f:
soup = BeautifulSoup(f, 'html.parser')
p_tags = soup.find_all('p')
data_div = soup.find(id='data')
data = None
if data_div is not None:
data = data_div.string
strings = [tag.get_text() for tag in p_tags]
return strings
return strings, data


def read_strings_from_translated(p):
Expand All @@ -48,7 +57,9 @@ def read_strings_from_translated(p):

def get_translated_dic(html_path, translated_path):
dic = dict()
ori_strings = read_strings_from_html(html_path)
ori_strings, data = read_strings_from_html(html_path)
if data is not None:
data = json.loads(data)
global last_translated_dic
if ori_strings is None or len(ori_strings) == 0:
last_translated_dic = None
Expand All @@ -61,7 +72,27 @@ def get_translated_dic(html_path, translated_path):
log_print('Error:translated file does not match the html file')
last_translated_dic = None
return None
for i, e in enumerate(ori_strings):
dic[e] = translated_strings[i]
if data is not None:
for i, e in enumerate(data):
translated_dic = dict()
target = e['target']
line = e['line']
if 'd' not in e:
dic[ori_strings[i]] = translated_strings[i]
continue
d = e['d']
translated = translated_strings[i]
translated_dic[target] = translated
translated = get_translated(translated_dic, d)
if translated is None:
translated = ''
encoded = d['encoded'].strip('"')
if encoded in translated_dic:
translated = translated_dic[encoded]
log_print(f'{translated_path} Error in line:{str(i + 1)} row:{line}\n{target}\n{encoded}\n{translated}\nError')
dic[ori_strings[i]] = translated
else:
for i, e in enumerate(ori_strings):
dic[e] = translated_strings[i]
last_translated_dic = dic
return dic
return dic, data is not None
4 changes: 3 additions & 1 deletion src/import_html_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, parent=None):
self.selectTranslatedFileBtn.clicked.connect(self.select_translated_file)
self.importBtn.clicked.connect(self.on_import_button_clicked)
self.dic = None
self.is_replace_special_symbols = True

def on_import_button_clicked(self):
self.dic = None
Expand All @@ -25,8 +26,9 @@ def on_import_button_clicked(self):
translated_file = translated_file.replace('file:///', '')
if len(translated_file) == 0:
return
dic = html_util.get_translated_dic(html_file, translated_file)
dic, is_replace_special_symbols = html_util.get_translated_dic(html_file, translated_file)
self.dic = dic
self.is_replace_special_symbols = is_replace_special_symbols
if self.dic is None:
msg_box = QMessageBox()
msg_box.setWindowTitle('o(≧口≦)o')
Expand Down
4 changes: 4 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def retranslate_ui(self):
self.retranslateUi(self)
if self.editor_form is not None:
self.editor_form.retranslateUi(self.editor_form)
if self.editor_form.myImportHtmlForm is not None:
self.editor_form.myImportHtmlForm.retranslateUi(self.editor_form.myImportHtmlForm)
if self.editor_form.myExportXlsxSettingForm is not None:
self.editor_form.myExportXlsxSettingForm.retranslateUi(self.editor_form.myExportXlsxSettingForm)
if self.myGameUnpackerForm is not None:
self.myGameUnpackerForm.retranslateUi(self.myGameUnpackerForm)
if self.local_glossary_form is not None:
Expand Down
Binary file modified src/qm/arabic.qm
Binary file not shown.
Binary file modified src/qm/bengali.qm
Binary file not shown.
Binary file modified src/qm/chinese.qm
Binary file not shown.
Binary file modified src/qm/french.qm
Binary file not shown.
Binary file modified src/qm/german.qm
Binary file not shown.
Binary file modified src/qm/hindi.qm
Binary file not shown.
Binary file modified src/qm/japanese.qm
Binary file not shown.
Binary file modified src/qm/korean.qm
Binary file not shown.
Binary file modified src/qm/portuguese.qm
Binary file not shown.
Binary file modified src/qm/russian.qm
Binary file not shown.
Binary file modified src/qm/spanish.qm
Binary file not shown.
Binary file modified src/qm/urdu.qm
Binary file not shown.
135 changes: 71 additions & 64 deletions src/ts/arabic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,180 +239,187 @@
<name>EditorDialog</name>
<message>
<location filename="../editor_form.py" line="122"/>
<location filename="../editor_form.py" line="247"/>
<location filename="../editor_form.py" line="248"/>
<source>Path</source>
<translation>طريق</translation>
</message>
<message>
<location filename="../editor_form.py" line="126"/>
<location filename="../editor_form.py" line="248"/>
<location filename="../editor_form.py" line="249"/>
<source>Units</source>
<translation>الوحدات</translation>
</message>
<message>
<location filename="../editor_form.py" line="130"/>
<location filename="../editor_form.py" line="197"/>
<location filename="../editor_form.py" line="249"/>
<location filename="../editor_form.py" line="283"/>
<location filename="../editor_form.py" line="696"/>
<location filename="../editor_form.py" line="198"/>
<location filename="../editor_form.py" line="250"/>
<location filename="../editor_form.py" line="284"/>
<location filename="../editor_form.py" line="730"/>
<location filename="../editor.ui" line="454"/>
<source>Translated</source>
<translation>مترجم</translation>
</message>
<message>
<location filename="../editor_form.py" line="178"/>
<location filename="../editor_form.py" line="332"/>
<location filename="../editor_form.py" line="474"/>
<location filename="../editor_form.py" line="502"/>
<location filename="../editor_form.py" line="513"/>
<location filename="../editor_form.py" line="846"/>
<location filename="../editor_form.py" line="892"/>
<location filename="../editor_form.py" line="179"/>
<location filename="../editor_form.py" line="333"/>
<location filename="../editor_form.py" line="479"/>
<location filename="../editor_form.py" line="527"/>
<location filename="../editor_form.py" line="538"/>
<location filename="../editor_form.py" line="880"/>
<location filename="../editor_form.py" line="932"/>
<source>Export to html file</source>
<translation>تصدير إلى ملف HTML</translation>
</message>
<message>
<location filename="../editor_form.py" line="181"/>
<location filename="../editor_form.py" line="336"/>
<location filename="../editor_form.py" line="848"/>
<location filename="../editor_form.py" line="182"/>
<location filename="../editor_form.py" line="337"/>
<location filename="../editor_form.py" line="882"/>
<source>Import html and relative translated contents</source>
<translation>استيراد HTML والمحتويات المترجمة النسبية</translation>
</message>
<message>
<location filename="../editor_form.py" line="191"/>
<location filename="../editor_form.py" line="279"/>
<location filename="../editor_form.py" line="692"/>
<location filename="../editor_form.py" line="192"/>
<location filename="../editor_form.py" line="280"/>
<location filename="../editor_form.py" line="726"/>
<source>line</source>
<translation>خط</translation>
</message>
<message>
<location filename="../editor_form.py" line="192"/>
<location filename="../editor_form.py" line="280"/>
<location filename="../editor_form.py" line="693"/>
<location filename="../editor_form.py" line="193"/>
<location filename="../editor_form.py" line="281"/>
<location filename="../editor_form.py" line="727"/>
<source>refer</source>
<translation>يشير إلى</translation>
</message>
<message>
<location filename="../editor_form.py" line="194"/>
<location filename="../editor_form.py" line="281"/>
<location filename="../editor_form.py" line="549"/>
<location filename="../editor_form.py" line="694"/>
<location filename="../editor_form.py" line="1409"/>
<location filename="../editor_form.py" line="195"/>
<location filename="../editor_form.py" line="282"/>
<location filename="../editor_form.py" line="583"/>
<location filename="../editor_form.py" line="728"/>
<location filename="../editor_form.py" line="1477"/>
<location filename="../editor.ui" line="334"/>
<location filename="../editor.ui" line="413"/>
<source>Original</source>
<translation>إبداعي</translation>
</message>
<message>
<location filename="../editor_form.py" line="195"/>
<location filename="../editor_form.py" line="282"/>
<location filename="../editor_form.py" line="550"/>
<location filename="../editor_form.py" line="695"/>
<location filename="../editor_form.py" line="1410"/>
<location filename="../editor_form.py" line="196"/>
<location filename="../editor_form.py" line="283"/>
<location filename="../editor_form.py" line="584"/>
<location filename="../editor_form.py" line="729"/>
<location filename="../editor_form.py" line="1478"/>
<location filename="../editor.ui" line="255"/>
<location filename="../editor.ui" line="432"/>
<source>Current</source>
<translation>حاضِر</translation>
</message>
<message>
<location filename="../editor_form.py" line="320"/>
<location filename="../editor_form.py" line="321"/>
<source>Remove</source>
<translation>يزيل</translation>
</message>
<message>
<location filename="../editor_form.py" line="451"/>
<location filename="../editor_form.py" line="456"/>
<source>Import to files</source>
<translation>الاستيراد إلى الملفات</translation>
</message>
<message>
<location filename="../editor_form.py" line="454"/>
<location filename="../editor_form.py" line="459"/>
<source>Do you want to make advanced settings (the default setting is to import to all files in the directory)</source>
<translation>هل تريد إجراء إعدادات متقدمة (الإعداد الافتراضي هو الاستيراد إلى كافة الملفات الموجودة في الدليل)</translation>
</message>
<message>
<location filename="../editor_form.py" line="516"/>
<location filename="../editor_form.py" line="577"/>
<location filename="../editor_form.py" line="496"/>
<location filename="../editor_form.py" line="546"/>
<location filename="../editor_form.py" line="942"/>
<source>Do you want to replace special symbols?</source>
<translation>هل تريد استبدال الرموز الخاصة؟</translation>
</message>
<message>
<location filename="../editor_form.py" line="541"/>
<location filename="../editor_form.py" line="611"/>
<source>Do you want to make advanced settings (the default setting is to export all files in the directory)</source>
<translation>هل تريد عمل إعدادات متقدمة (الإعداد الافتراضي هو تصدير جميع الملفات الموجودة في الدليل)</translation>
</message>
<message>
<location filename="../editor_form.py" line="626"/>
<location filename="../editor_form.py" line="660"/>
<source>Case Sensitive</source>
<translation>حساسية الموضوع</translation>
</message>
<message>
<location filename="../editor_form.py" line="629"/>
<location filename="../editor_form.py" line="663"/>
<source>Search refer column</source>
<translation>البحث في العمود المرجعي</translation>
</message>
<message>
<location filename="../editor_form.py" line="632"/>
<location filename="../editor_form.py" line="666"/>
<source>Search Original column</source>
<translation>البحث في العمود الأصلي</translation>
</message>
<message>
<location filename="../editor_form.py" line="635"/>
<location filename="../editor_form.py" line="669"/>
<source>Search Current column</source>
<translation>البحث في العمود الحالي</translation>
</message>
<message>
<location filename="../editor_form.py" line="638"/>
<location filename="../editor_form.py" line="672"/>
<source>Search Translated column</source>
<translation>البحث في العمود المترجم</translation>
</message>
<message>
<location filename="../editor_form.py" line="733"/>
<location filename="../editor_form.py" line="745"/>
<location filename="../editor_form.py" line="767"/>
<location filename="../editor_form.py" line="779"/>
<source>Input Dialog</source>
<translation>حوار الإدخال</translation>
</message>
<message>
<location filename="../editor_form.py" line="735"/>
<location filename="../editor_form.py" line="769"/>
<source>Please Input the line number you want to jump</source>
<translation>الرجاء إدخال رقم السطر الذي تريد القفز عليه</translation>
</message>
<message>
<location filename="../editor_form.py" line="747"/>
<location filename="../editor_form.py" line="781"/>
<source>Please Input the content you want to search</source>
<translation>الرجاء إدخال المحتوى الذي تريد البحث فيه</translation>
</message>
<message>
<location filename="../editor_form.py" line="834"/>
<location filename="../editor_form.py" line="868"/>
<source>Translate Translation Source to Translated</source>
<translation>ترجمة مصدر الترجمة إلى مترجم</translation>
</message>
<message>
<location filename="../editor_form.py" line="837"/>
<location filename="../editor_form.py" line="871"/>
<source>Copy Original to Current</source>
<translation>انسخ الأصل إلى الحالي</translation>
</message>
<message>
<location filename="../editor_form.py" line="839"/>
<location filename="../editor_form.py" line="873"/>
<source>Copy Translated to Current</source>
<translation>نسخة مترجمة إلى الحالية</translation>
</message>
<message>
<location filename="../editor_form.py" line="842"/>
<location filename="../editor_form.py" line="876"/>
<source>Rollback Current to First Load</source>
<translation>التراجع الحالي إلى التحميل الأول</translation>
</message>
<message>
<location filename="../editor_form.py" line="1295"/>
<location filename="../editor_form.py" line="1359"/>
<source>select the directory you want to edit</source>
<translation>حدد الدليل الذي تريد تحريره</translation>
</message>
<message>
<location filename="../editor_form.py" line="1302"/>
<location filename="../editor_form.py" line="1366"/>
<source>select the file(s) you want to edit</source>
<translation>حدد الملف (الملفات) الذي تريد تحريره</translation>
</message>
<message>
<location filename="../editor_form.py" line="176"/>
<location filename="../editor_form.py" line="329"/>
<location filename="../editor_form.py" line="536"/>
<location filename="../editor_form.py" line="565"/>
<location filename="../editor_form.py" line="574"/>
<location filename="../editor_form.py" line="844"/>
<location filename="../editor_form.py" line="918"/>
<location filename="../editor_form.py" line="177"/>
<location filename="../editor_form.py" line="330"/>
<location filename="../editor_form.py" line="570"/>
<location filename="../editor_form.py" line="599"/>
<location filename="../editor_form.py" line="608"/>
<location filename="../editor_form.py" line="878"/>
<location filename="../editor_form.py" line="982"/>
<source>Export to xlsx file</source>
<translation>تصدير إلى ملف XLSX</translation>
</message>
Expand Down Expand Up @@ -884,17 +891,17 @@
<context>
<name>ImportHtmlDialog</name>
<message>
<location filename="../import_html_form.py" line="34"/>
<location filename="../import_html_form.py" line="36"/>
<source>The html file does not match the translated file , please check the input files</source>
<translation>ملف html لا يتطابق مع الملف المترجم، يرجى التحقق من ملفات الإدخال</translation>
</message>
<message>
<location filename="../import_html_form.py" line="43"/>
<location filename="../import_html_form.py" line="45"/>
<source>select the relative translated file</source>
<translation>حدد الملف المترجم النسبي</translation>
</message>
<message>
<location filename="../import_html_form.py" line="54"/>
<location filename="../import_html_form.py" line="56"/>
<source>select the html file exported before</source>
<translation>حدد ملف html الذي تم تصديره من قبل</translation>
</message>
Expand Down Expand Up @@ -1072,8 +1079,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.0.7</source>
<translation>الإصدار2.0.7</translation>
<source>Version 2.0.8</source>
<translation>الإصدار2.0.8</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
Loading

0 comments on commit 4dc5445

Please sign in to comment.