Update how translation files are built and added (#915)

* Fix wrapping of setup help text
* Fix wrong info in help description in setup
* Drop .pro file and generate lupdate arguments on the fly
* Generate lrelease arguments on the fly
* Update i18n readme file
This commit is contained in:
Veronica Berglyd Olsen
2021-10-24 16:01:26 +02:00
committed by GitHub
parent 9a484193eb
commit da2685131d
3 changed files with 100 additions and 55 deletions
+21 -8
View File
@@ -9,8 +9,8 @@ projects, used by the Build Novel Project tool.
**Note** **Note**
When making a new translation, or updating an existing one, only commit the `nw_XX.ts` you have When making a new translation, or updating an existing one, only commit the `nw_XX.ts` you have
made changes to. The `qtlupdate` command mentioned below will likely modify all `nw_XX.ts` made changes to. The `qtlupdate` command mentioned below may modify all `nw_XX.ts` slightly, but
slightly, but please _don't_ commit those changes to the pull request. please _don't_ commit those changes to the pull request.
## Qt GUI Localisation ## Qt GUI Localisation
@@ -21,18 +21,31 @@ be built with:
python3 setup.py qtlrelease python3 setup.py qtlrelease
``` ```
To add a new translation file, first add a new entry in the `novelWriter.pro` file under the Before adding translations to an existing translation file, you may need to update the file against
`TRANSLATIONS` variable. Please use the underscore syntax for file names as the importer expects the current source code. This is done by running the command:
this format.
After adding the entry in the `.pro` file, run:
```bash ```bash
python3 setup.py qtlupdate python3 setup.py qtlupdate
``` ```
If you want to update specific language files, you can add them as one or more arguments, like so:
```bash
python3 setup.py qtlupdate i18n/nw_fr.ts
```
To add a new language to the translation framework, run the command above with the file name of the
new, and not yet existing, language file. Make sure the file name is in the correct format. All
translation files must be located in the `i18n` folder, start with `nw_` and end with `.ts`. In
between goes the language code. It must be a valid ISO language code, otherwise novelWriter will
not accept the file.
For instance, to add a file for a language with language code "XX", run:
```bash
python3 setup.py qtlupdate i18n/nw_xx.ts
```
This will build a new `i18n/nw_XX.ts` file for the language you just added. The file can then be This will build a new `i18n/nw_XX.ts` file for the language you just added. The file can then be
edited with the Qt 5 Linguist application provided by Qt. This is by far easier than manually edited with the Qt 5 Linguist application provided by Qt. This is by far easier than manually
editing the `.ts` file. Please select "English" and "United Kingdom" as the source langauge when editing the `.ts` file. Please select "English" and "United Kingdom" as the source langauge if
prompted by Qt 5 Linguist. prompted by Qt 5 Linguist.
When you're done editing, you can build the `novelwriter/assets/i18n/nw_XX.qm` file and test it in When you're done editing, you can build the `novelwriter/assets/i18n/nw_XX.qm` file and test it in
-39
View File
@@ -1,39 +0,0 @@
SOURCES += \
i18n/qtbase.py \
novelwriter/core/project.py \
novelwriter/core/tokenizer.py \
novelwriter/dialogs/about.py \
novelwriter/dialogs/docmerge.py \
novelwriter/dialogs/docsplit.py \
novelwriter/dialogs/itemeditor.py \
novelwriter/dialogs/preferences.py \
novelwriter/dialogs/projdetails.py \
novelwriter/dialogs/projload.py \
novelwriter/dialogs/projsettings.py \
novelwriter/dialogs/updates.py \
novelwriter/dialogs/wordlist.py \
novelwriter/gui/custom.py \
novelwriter/gui/doceditor.py \
novelwriter/gui/docviewer.py \
novelwriter/gui/itemdetails.py \
novelwriter/gui/mainmenu.py \
novelwriter/gui/noveltree.py \
novelwriter/gui/outline.py \
novelwriter/gui/outlinedetails.py \
novelwriter/gui/projtree.py \
novelwriter/gui/statusbar.py \
novelwriter/tools/build.py \
novelwriter/tools/projwizard.py \
novelwriter/tools/writingstats.py \
novelwriter/common.py \
novelwriter/constants.py \
novelwriter/error.py \
novelwriter/guimain.py
TRANSLATIONS += \
i18n/nw_en_US.ts \
i18n/nw_fr.ts \
i18n/nw_nb_NO.ts \
i18n/nw_pt.ts \
i18n/nw_zh_CN.ts
+79 -8
View File
@@ -268,10 +268,24 @@ def buildQtI18n():
print("") print("")
print("Building Qt Localisation Files") print("Building Qt Localisation Files")
print("==============================") print("==============================")
print("")
print("TS Files to Build:")
print("")
tsList = []
for aFile in os.listdir("i18n"):
aPath = os.path.join("i18n", aFile)
if os.path.isfile(aPath) and aFile.endswith(".ts"):
tsList.append(aPath)
print(aPath)
print("")
print("Building Translation Files:")
print("") print("")
try: try:
subprocess.call(["lrelease", "-verbose", "novelWriter.pro"]) subprocess.call(["lrelease", "-verbose", *tsList])
except Exception as e: except Exception as e:
print("Qt5 Linguist tools seem to be missing") print("Qt5 Linguist tools seem to be missing")
print("On Debian/Ubuntu, install: qttools5-dev-tools pyqt5-dev-tools") print("On Debian/Ubuntu, install: qttools5-dev-tools pyqt5-dev-tools")
@@ -302,16 +316,71 @@ def buildQtI18n():
# Qt Linguist TS Builder (qtlupdate) # Qt Linguist TS Builder (qtlupdate)
## ##
def buildQtI18nTS(): def buildQtI18nTS(sysArgs):
"""Build the lang.ts files for Qt Linguist. """Build the lang.ts files for Qt Linguist.
""" """
print("") print("")
print("Building Qt Translation Files") print("Building Qt Translation Files")
print("=============================") print("=============================")
print("")
print("Scanning Source Tree:")
print("")
srcList = [os.path.join("i18n", "qtbase.py")]
for nRoot, _, nFiles in os.walk("novelwriter"):
if os.path.isdir(nRoot):
for aFile in nFiles:
aPath = os.path.join(nRoot, aFile)
if os.path.isfile(aPath) and aFile.endswith(".py"):
srcList.append(aPath)
for aSource in srcList:
print(aSource)
print("")
print("TS Files to Update:")
print("")
tsList = []
if len(sysArgs) >= 2:
for anArg in sysArgs[1:]:
if not (anArg.startswith("i18n") and anArg.endswith(".ts")):
continue
fName = os.path.basename(anArg)
if not fName.startswith("nw_") and len(fName) > 6:
print("Skipping non-novelWriter TS file %s" % fName)
continue
if os.path.isfile(anArg):
tsList.append(anArg)
elif os.path.exists(anArg):
pass
else: # Create an empty new language file
lCode = fName[3:-3]
writeFile(anArg, (
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<!DOCTYPE TS>\n"
f"<TS version=\"2.0\" language=\"{lCode}\" sourcelanguage=\"en_GB\"/>\n"
))
tsList.append(anArg)
else:
for aFile in os.listdir("i18n"):
aPath = os.path.join("i18n", aFile)
if os.path.isfile(aPath) and aFile.endswith(".ts"):
tsList.append(aPath)
for aTS in tsList:
print(aTS)
print("")
print("Updating Language Files:")
print("") print("")
try: try:
subprocess.call(["pylupdate5", "-verbose", "-noobsolete", "novelWriter.pro"]) subprocess.call(["pylupdate5", "-verbose", "-noobsolete", *srcList, "-ts", *tsList])
except Exception as e: except Exception as e:
print("PyQt5 Linguist tools seem to be missing") print("PyQt5 Linguist tools seem to be missing")
print("On Debian/Ubuntu, install: qttools5-dev-tools pyqt5-dev-tools") print("On Debian/Ubuntu, install: qttools5-dev-tools pyqt5-dev-tools")
@@ -1435,14 +1504,15 @@ if __name__ == "__main__":
"", "",
" help Print the help message.", " help Print the help message.",
" pip Install all package dependencies for novelWriter using pip.", " pip Install all package dependencies for novelWriter using pip.",
" clean Will attempt to delete the 'build' and 'dist' folders.", " build-clean Will attempt to delete 'build' and 'dist' folders.",
"", "",
"Additional Builds:", "Additional Builds:",
"", "",
" manual Build the help documentation as PDF (requires LaTeX).", " manual Build the help documentation as PDF (requires LaTeX).",
" qtlupdate Update the translation files for internationalisation.",
" qtlrelease Build the language files for internationalisation.",
" sample Build the sample project zip file and add it to assets.", " sample Build the sample project zip file and add it to assets.",
" qtlupdate Update the translation files for internationalisation.",
" To update specific TS files, list them after the command.",
" qtlrelease Build the language files for internationalisation.",
"", "",
"Python Packaging:", "Python Packaging:",
"", "",
@@ -1454,7 +1524,7 @@ if __name__ == "__main__":
" sign package.", " sign package.",
" build-ubuntu Build a .deb packages Launchpad. Add --sign to ", " build-ubuntu Build a .deb packages Launchpad. Add --sign to ",
" sign package. Add --first to set build number to 0.", " sign package. Add --first to set build number to 0.",
" Add --snapshot to make a snapshot package." " Add --snapshot to make a snapshot package.",
" build-pyz Build a .pyz package in a folder with all dependencies", " build-pyz Build a .pyz package in a folder with all dependencies",
" using the zipapp tool. On Windows, python embeddable is", " using the zipapp tool. On Windows, python embeddable is",
" added to the folder.", " added to the folder.",
@@ -1519,7 +1589,8 @@ if __name__ == "__main__":
if "qtlupdate" in sys.argv: if "qtlupdate" in sys.argv:
sys.argv.remove("qtlupdate") sys.argv.remove("qtlupdate")
buildQtI18nTS() buildQtI18nTS(sys.argv)
sys.exit(0) # Don't continue execution
if "sample" in sys.argv: if "sample" in sys.argv:
sys.argv.remove("sample") sys.argv.remove("sample")