Convert doxygen to rst for Cura scripts

This commit is contained in:
Nino van Hooff 2020-05-28 16:25:26 +02:00
parent bb2a176e36
commit fe779d9501
2 changed files with 71 additions and 42 deletions

View file

@ -9,14 +9,16 @@ import os.path #To find files from the source and the destination path.
cura_files = {"cura", "fdmprinter.def.json", "fdmextruder.def.json"}
uranium_files = {"uranium"}
## Imports translation files from Lionbridge.
#
# Lionbridge has a bit of a weird export feature. It exports it to the same
# file type as what we imported, so that's a .pot file. However this .pot file
# only contains the translations, so the header is completely empty. We need
# to merge those translations into our existing files so that the header is
# preserved.
def lionbridge_import(source: str) -> None:
"""Imports translation files from Lionbridge.
Lionbridge has a bit of a weird export feature. It exports it to the same
file type as what we imported, so that's a .pot file. However this .pot file
only contains the translations, so the header is completely empty. We need
to merge those translations into our existing files so that the header is
preserved.
"""
print("Importing from:", source)
print("Importing to Cura:", destination_cura())
print("Importing to Uranium:", destination_uranium())
@ -43,14 +45,20 @@ def lionbridge_import(source: str) -> None:
with io.open(destination_file, "w", encoding = "utf8") as f:
f.write(result)
## Gets the destination path to copy the translations for Cura to.
# \return Destination path for Cura.
def destination_cura() -> str:
"""Gets the destination path to copy the translations for Cura to.
:return: Destination path for Cura.
"""
return os.path.abspath(os.path.join(__file__, "..", "..", "resources", "i18n"))
## Gets the destination path to copy the translations for Uranium to.
# \return Destination path for Uranium.
def destination_uranium() -> str:
"""Gets the destination path to copy the translations for Uranium to.
:return: Destination path for Uranium.
"""
try:
import UM
except ImportError:
@ -64,11 +72,14 @@ def destination_uranium() -> str:
raise Exception("Can't find Uranium. Please put UM on the PYTHONPATH or put the Uranium folder next to the Cura folder. Looked for: " + absolute_path)
return os.path.abspath(os.path.join(UM.__file__, "..", "..", "resources", "i18n"))
## Merges translations from the source file into the destination file if they
# were missing in the destination file.
# \param source The contents of the source .po file.
# \param destination The contents of the destination .po file.
def merge(source: str, destination: str) -> str:
"""Merges translations from the source file into the destination file if they
were missing in the destination file.
:param source: The contents of the source .po file.
:param destination: The contents of the destination .po file.
"""
result_lines = []
last_destination = {
"msgctxt": "\"\"\n",
@ -119,11 +130,14 @@ def merge(source: str, destination: str) -> str:
result_lines.append(line) #This line itself.
return "\n".join(result_lines)
## Finds a translation in the source file.
# \param source The contents of the source .po file.
# \param msgctxt The ctxt of the translation to find.
# \param msgid The id of the translation to find.
def find_translation(source: str, msgctxt: str, msgid: str) -> str:
"""Finds a translation in the source file.
:param source: The contents of the source .po file.
:param msgctxt: The ctxt of the translation to find.
:param msgid: The id of the translation to find.
"""
last_source = {
"msgctxt": "\"\"\n",
"msgid": "\"\"\n",