diff --git a/i18n/README.md b/i18n/README.md index cb89e870..3cfd56fc 100644 --- a/i18n/README.md +++ b/i18n/README.md @@ -9,8 +9,8 @@ projects, used by the Build Novel Project tool. **Note** 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` -slightly, but please _don't_ commit those changes to the pull request. +made changes to. The `qtlupdate` command mentioned below may modify all `nw_XX.ts` slightly, but +please _don't_ commit those changes to the pull request. ## Qt GUI Localisation @@ -21,18 +21,31 @@ be built with: python3 setup.py qtlrelease ``` -To add a new translation file, first add a new entry in the `novelWriter.pro` file under the -`TRANSLATIONS` variable. Please use the underscore syntax for file names as the importer expects -this format. - -After adding the entry in the `.pro` file, run: +Before adding translations to an existing translation file, you may need to update the file against +the current source code. This is done by running the command: ```bash 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 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. When you're done editing, you can build the `novelwriter/assets/i18n/nw_XX.qm` file and test it in diff --git a/novelWriter.pro b/novelWriter.pro deleted file mode 100644 index d9f87985..00000000 --- a/novelWriter.pro +++ /dev/null @@ -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 - diff --git a/setup.py b/setup.py index 5c2943be..8f29f133 100755 --- a/setup.py +++ b/setup.py @@ -268,10 +268,24 @@ def buildQtI18n(): print("") print("Building Qt Localisation Files") 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("") try: - subprocess.call(["lrelease", "-verbose", "novelWriter.pro"]) + subprocess.call(["lrelease", "-verbose", *tsList]) except Exception as e: print("Qt5 Linguist tools seem to be missing") print("On Debian/Ubuntu, install: qttools5-dev-tools pyqt5-dev-tools") @@ -302,16 +316,71 @@ def buildQtI18n(): # Qt Linguist TS Builder (qtlupdate) ## -def buildQtI18nTS(): +def buildQtI18nTS(sysArgs): """Build the lang.ts files for Qt Linguist. """ print("") print("Building Qt Translation Files") 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, ( + "\n" + "\n" + f"\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("") try: - subprocess.call(["pylupdate5", "-verbose", "-noobsolete", "novelWriter.pro"]) + subprocess.call(["pylupdate5", "-verbose", "-noobsolete", *srcList, "-ts", *tsList]) except Exception as e: print("PyQt5 Linguist tools seem to be missing") print("On Debian/Ubuntu, install: qttools5-dev-tools pyqt5-dev-tools") @@ -1435,14 +1504,15 @@ if __name__ == "__main__": "", " help Print the help message.", " 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:", "", " 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.", + " 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:", "", @@ -1454,7 +1524,7 @@ if __name__ == "__main__": " sign package.", " build-ubuntu Build a .deb packages Launchpad. Add --sign to ", " 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", " using the zipapp tool. On Windows, python embeddable is", " added to the folder.", @@ -1519,7 +1589,8 @@ if __name__ == "__main__": if "qtlupdate" in sys.argv: sys.argv.remove("qtlupdate") - buildQtI18nTS() + buildQtI18nTS(sys.argv) + sys.exit(0) # Don't continue execution if "sample" in sys.argv: sys.argv.remove("sample")