有一個大檔案要翻譯。它有需要翻譯的元素。它們被標記為“msgid”。所需的文本包含在“msgid”和“msgstr”之間。問題是我不知道如何決議所需內容位于多行的文本。
我需要決議,以便保留文本的所有空格和縮進。接下來,我想將它們輸入到字典中以輸出到表中。
我試著手動做 - 它沒有用。現在我想我需要正則運算式,但不知道怎么做,請幫忙
#: superset-frontend/src/explore/components/controls/DndColumnSelectControl/Option.tsx:68
#: superset-frontend/src/explore/components/controls/OptionControls/index.tsx:323
msgid ""
"\n"
" This filter was inherited from the dashboard's context.\n"
" It won't be saved when saving the chart.\n"
" "
msgstr ""
"\n"
" Фильтр был наследован из контекста дашборда.\n"
" Это не будет сохранено при сохранении графика.\n"
" "
#: superset/tasks/schedules.py:184
#, python-format
msgid ""
"\n"
" <b><a href=\"%(url)s\">Explore in Superset</a></b><p></p>\n"
" <img src=\"cid:%(msgid)s\">\n"
" "
msgstr ""
"\n"
" <b><a href=“%(url)s”>Исследовать в Superset</a></b><p></p>\n"
" <img src=“cid:%(msgid)s”>\n"
" "
#: superset/reports/notifications/email.py:60
這是我的python代碼
def Parse(file : io.TextIOWrapper):
text = ""
for lines in file:
if lines.startswith("msgid"):
text = f" {lines.strip()}"
elif lines.startswith("msgstr"):
text = f" {lines.strip()}"
else:
text = lines.strip()
text.split()
sourcetxt = {}
for index, word in enumerate(text):
if word = "msgid":
uj5u.com熱心網友回復:
考慮:
pairs = []
for line in ......
line = line.strip()
if not line or line.startswith('#'):
continue
if line.startswith('msgid'):
pairs.append([[], None])
elif line.startswith('msgstr'):
pairs[-1][1] = []
elif pairs[-1][1] is None:
pairs[-1][0].append(line)
else:
pairs[-1][1].append(line)
這將創建一個[msgid, msgstr]對串列,其中每個部分都是行串列。在這種形式中,很容易將其轉換為所需的任何內容。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/512187.html
標籤:Python细绳解析
上一篇:快速決議xml檔案
下一篇:了解正則運算式語法中的“嚴格性”
