Add support for external translation tools (#968)
* Make some minor translation fixes * Remove crowdin file and add import function for crowdin zip file * Rename fallback project lang file to en_GB * Update all i18n files from crowdin exports * Fix tests * Update docs
This commit is contained in:
committed by
GitHub
parent
537bf921d2
commit
25038e6cbb
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import zipfile
|
||||
import datetime
|
||||
import subprocess
|
||||
import email.utils
|
||||
@@ -435,6 +436,47 @@ def buildSampleZip():
|
||||
# Python Packaging
|
||||
# =============================================================================================== #
|
||||
|
||||
##
|
||||
# Import Translations (import-i18n)
|
||||
##
|
||||
|
||||
def importI18nUpdates(sysArgs):
|
||||
"""Import new translation files from a zip file.
|
||||
"""
|
||||
print("")
|
||||
print("Import Updated Translations")
|
||||
print("===========================")
|
||||
print("")
|
||||
|
||||
fileName = None
|
||||
if len(sysArgs) >= 2:
|
||||
if os.path.isfile(sysArgs[1]):
|
||||
fileName = sysArgs[1]
|
||||
|
||||
if fileName is None:
|
||||
print("File not found ...")
|
||||
sys.exit(1)
|
||||
|
||||
projPath = os.path.join("novelwriter", "assets", "i18n")
|
||||
mainPath = "i18n"
|
||||
|
||||
print("Loading file: %s" % fileName)
|
||||
with zipfile.ZipFile(fileName) as zipObj:
|
||||
for archFile in zipObj.namelist():
|
||||
if archFile.startswith("nw_") and archFile.endswith(".ts"):
|
||||
zipObj.extract(archFile, mainPath)
|
||||
print("Extracted: %s > %s" % (archFile, os.path.join(mainPath, archFile)))
|
||||
elif archFile.startswith("project_") and archFile.endswith(".json"):
|
||||
zipObj.extract(archFile, projPath)
|
||||
print("Extracted: %s > %s" % (archFile, os.path.join(projPath, archFile)))
|
||||
else:
|
||||
print("Skipped: %s" % archFile)
|
||||
|
||||
print("")
|
||||
|
||||
return
|
||||
|
||||
|
||||
##
|
||||
# Make Minimal Package (minimal-zip)
|
||||
##
|
||||
@@ -1514,6 +1556,7 @@ if __name__ == "__main__":
|
||||
"",
|
||||
"Python Packaging:",
|
||||
"",
|
||||
" import-i18n Import updated i18n files from a zip file.",
|
||||
" minimal-zip Creates a minimal zip file of the core application without",
|
||||
" all the other source files. Defaults to tailor the zip file",
|
||||
" for the current OS, but accepts a target OS flag to build",
|
||||
@@ -1597,6 +1640,11 @@ if __name__ == "__main__":
|
||||
# Python Packaging
|
||||
# ================
|
||||
|
||||
if "import-i18n" in sys.argv:
|
||||
sys.argv.remove("import-i18n")
|
||||
importI18nUpdates(sys.argv)
|
||||
sys.exit(0) # Don't continue execution
|
||||
|
||||
if "minimal-zip" in sys.argv:
|
||||
sys.argv.remove("minimal-zip")
|
||||
makeMinimalPackage(targetOS)
|
||||
|
||||
Reference in New Issue
Block a user