From 0edb7cf31e3176b731230132124913d957da0d08 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Fri, 10 Mar 2023 13:30:41 +0800 Subject: [PATCH] add possibility to test locales locally https://github.com/mifi/lossless-cut/issues/1500#issuecomment-1461780597 --- README.md | 2 +- developer-notes.md | 39 +++++++++++++++++++++++++++++++++++++-- public/electron.js | 5 +++++ public/i18n-common.js | 19 +++++++++++++++++-- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index debab475..4f926f66 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ Unsupported files can still be converted to a supported format/codec from the `F ## [Command line interface (CLI)](cli.md) -## [Developer notes](developer-notes.md) +## [Contributing](developer-notes.md) ## [Known issues, limitations, troubleshooting, FAQ](issues.md) diff --git a/developer-notes.md b/developer-notes.md index 23fbe090..d4152d33 100644 --- a/developer-notes.md +++ b/developer-notes.md @@ -1,7 +1,41 @@ -## Development +# Contributing + +## Translators + +You are welcome to help translate the app at [Weblate](https://hosted.weblate.org/projects/losslesscut/losslesscut/). Weblate will automatically push translations as a Pull Request in this repo, but this PR is not merged immediately by maintainers. + +Master language is english. + +### Testing translations locally + +To test new weblate translations you made in the app itself, you need to: +1. Download the translation for your language from Weblate: **Files -> Download translation** +2. Rename the downloaded `.json` file to: `translation.json` +3. Create a [folder structure](https://github.com/mifi/lossless-cut/tree/master/public/locales) somewhere on your computer that looks like this: +``` +translations/locales/localeCode +``` +You can find a list of the available [`localeCode`s here](https://github.com/mifi/lossless-cut/tree/master/public/locales). In our example we will use `nb_NO` (Norwegian) with this path: +``` +/Users/mifi/Desktop/translations/locales/nb_NO +``` + +4. Now move your `translation.json` file into the folder: +``` +/Users/mifi/Desktop/translations/locales/nb_NO/translation.json +``` + +5. Now run LosslessCut from the [command line](cli.md), with the special command line argument `--locales-path`. Use the path to the **folder containing the locales folder**, e.g.: +```bash +./LosslessCut --locales-path /Users/mifi/Desktop/translations +``` + +Now LosslessCut will use your language file. + +## Development setup This app is built using Electron. -Make sure you have at least Node v14. The app uses ffmpeg from PATH when developing. +Make sure you have at least Node v16. The app uses ffmpeg from PATH when developing. ```bash npm install -g yarn @@ -12,6 +46,7 @@ git clone https://github.com/mifi/lossless-cut.git cd lossless-cut yarn ``` + Note: `yarn` may take some time to complete. ### Installing `ffmpeg` diff --git a/public/electron.js b/public/electron.js index baf42e48..4965209d 100644 --- a/public/electron.js +++ b/public/electron.js @@ -18,6 +18,8 @@ const { frontendBuildDir } = require('./util'); const { checkNewVersion } = require('./update-checker'); +const i18nCommon = require('./i18n-common'); + require('./i18n'); const { app, ipcMain, shell, BrowserWindow, nativeTheme } = electron; @@ -156,6 +158,9 @@ function parseCliArgs(rawArgv = process.argv) { const argv = parseCliArgs(); +if (argv.localesPath != null) i18nCommon.setCustomLocalesPath(argv.localesPath); + + function safeRequestSingleInstanceLock(additionalData) { if (process.mas) return true; // todo remove when fixed https://github.com/electron/electron/issues/35540 diff --git a/public/i18n-common.js b/public/i18n-common.js index 3b1ca4ba..917d43f1 100644 --- a/public/i18n-common.js +++ b/public/i18n-common.js @@ -6,7 +6,16 @@ const { join } = require('path'); const { frontendBuildDir } = require('./util'); -const getLangPath = (subPath) => (isDev ? join('public', subPath) : join(app.getAppPath(), frontendBuildDir, subPath)); +let customLocalesPath; +function setCustomLocalesPath(p) { + customLocalesPath = p; +} + +function getLangPath(subPath) { + if (customLocalesPath != null) return join(customLocalesPath, subPath); + if (isDev) return join('public', subPath); + return join(app.getAppPath(), frontendBuildDir, subPath); +} // Weblate hardcodes different lang codes than electron // https://www.electronjs.org/docs/api/app#appgetlocale @@ -47,4 +56,10 @@ const commonI18nOptions = { const loadPath = (lng, ns) => getLangPath(`locales/${mapLang(lng)}/${ns}.json`); const addPath = (lng, ns) => getLangPath(`locales/${mapLang(lng)}/${ns}.missing.json`); -module.exports = { fallbackLng, loadPath, addPath, commonI18nOptions }; +module.exports = { + fallbackLng, + loadPath, + addPath, + commonI18nOptions, + setCustomLocalesPath, +};