You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, I tried to write a Python script to merge a new version new.po file into an old version old.po file. That is, if there exists an existing msgid in the old.po exatly the same with the corresponding msgid in the new.po, then it should copy the translated msgstr of the entry from new.po into a old_updated.po directly. And in fact, I already implemented a simple merge.py.
Click to expand
importargparseimportpolibimportos# Add a parserparser=argparse.ArgumentParser(description='Sync PO files.')
# Add argumentsparser.add_argument('old_po', type=str, help='Path to the old PO file')
parser.add_argument('new_po', type=str, help='Path to the new PO file')
# Parse argumentsargs=parser.parse_args()
print("Old PO file path:", args.old_po)
print("New PO file path:", args.new_po)
po_old=polib.pofile(args.old_po)
po_new=polib.pofile(args.new_po)
# Create a dictionary of the new translationsnew_translations= {entry.msgid: entry.msgstrforentryinpo_new}
# Update the old translationsforentryinpo_old:
ifentry.msgidinnew_translations:
entry.msgstr=new_translations[entry.msgid]
# Split the filename and extension of old_poold_po_name, old_po_ext=os.path.splitext(args.old_po)
# Create a new file pathold_po_updated=old_po_name+"_updated"+old_po_ext# Save the old PO file with the updated translationspo_old.save(old_po_updated)
However, there is another problem bothering me. That is, the updated old_updated.po doesn't have the same "wrap at" format for the copied msgstr. Take the following results for reference:
The following is the format of an entry in the new.po, which is wrapped at 79 location by Poedit:
#:../../index.rst:6msgid ""
"CMake is a tool to manage building of source code. Originally, CMake was "
"designed as a generator for various dialects of ``Makefile``, today CMake "
"generates modern buildsystems such as ``Ninja`` as well as project files for "
"IDEs such as Visual Studio and Xcode."
msgstr ""
"CMake 是一款用來管理來源碼建置的工具。原本,CMake 是被設計做為不同 dialect "
"的 ``Makefile`` 的產生器。如今,CMake 可以產生像是 ``Ninja`` 這樣的現代建置系"
"統,以及像是 Visual Studio 和 Xcode 這樣的 IDE 專案檔。"
The following is the format of the corresponding entry in the old.po, which is empty in msgstr:
#:../../../index.rst:6msgid ""
"CMake is a tool to manage building of source code. Originally, CMake was "
"designed as a generator for various dialects of ``Makefile``, today CMake "
"generates modern buildsystems such as ``Ninja`` as well as project files for "
"IDEs such as Visual Studio and Xcode."
msgstr ""
The following is the format of the corresponding entry in the old_updated.po after runnnig python merge.py old.po new.po:
#:../../../index.rst:6msgid ""
"CMake is a tool to manage building of source code. Originally, CMake was "
"designed as a generator for various dialects of ``Makefile``, today CMake "
"generates modern buildsystems such as ``Ninja`` as well as project files for"
" IDEs such as Visual Studio and Xcode."
msgstr ""
"CMake 是一款用來管理來源碼建置的工具。原本,CMake 是被設計做為不同 dialect 的 ``Makefile`` 的產生器。如今,CMake"
" 可以產生像是 ``Ninja`` 這樣的現代建置系統,以及像是 Visual Studio 和 Xcode 這樣的 IDE 專案檔。"
As we can see, the old_updated.po file doesn't have the same "wrap at" format as the new.po file.
How should I modify this merge.py Python script in order to do the same format provided by Poedit?
Problem Description
Recently, I tried to write a Python script to merge a new version
new.po
file into an old versionold.po
file. That is, if there exists an existingmsgid
in theold.po
exatly the same with the correspondingmsgid
in thenew.po
, then it should copy the translatedmsgstr
of the entry fromnew.po
into aold_updated.po
directly. And in fact, I already implemented a simplemerge.py
.Click to expand
However, there is another problem bothering me. That is, the updated
old_updated.po
doesn't have the same "wrap at" format for the copiedmsgstr
. Take the following results for reference:The following is the format of an entry in the
new.po
, which is wrapped at 79 location by Poedit:The following is the format of the corresponding entry in the
old.po
, which is empty inmsgstr
:The following is the format of the corresponding entry in the
old_updated.po
after runnnigpython merge.py old.po new.po
:As we can see, the
old_updated.po
file doesn't have the same "wrap at" format as thenew.po
file.How should I modify this
merge.py
Python script in order to do the same format provided by Poedit?cc: @izimobil
Demonstration
merge.zip
The text was updated successfully, but these errors were encountered: