1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Tools Added support for translation validation in CI, and added support for plural translations

This commit is contained in:
Laurent Cozic 2019-12-10 21:10:47 +00:00
parent 554c46182a
commit b5d5d02a9c
4 changed files with 56 additions and 1 deletions

View File

@ -50,6 +50,7 @@ before_install:
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update || true
sudo apt-get install -y yarn
sudo apt-get install -y gettext
fi
script:
@ -84,6 +85,19 @@ script:
fi
fi
# Validate translations - this is needed as some users manually
# edit .po files (and often make mistakes) instead of using a proper
# tool like poedit. Doing it for Linux only is sufficient.
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
if [ "$TRAVIS_OS_NAME" != "osx" ]; then
node Tools/validate-translation.js
testResult=$?
if [ $testResult -ne 0 ]; then
exit $testResult
fi
fi
fi
# Find out if we should run the build or not. Electron-builder gets stuck when
# builing PRs so we disable it in this case. The Linux build should provide
# enough info if the app builds or not.

View File

@ -317,4 +317,9 @@ function _(s, ...args) {
}
}
module.exports = { _, supportedLocales, countryDisplayName, localeStrings, setLocale, supportedLocalesToLanguages, defaultLocale, closestSupportedLocale, languageCode, countryCodeOnly };
function _n(singular, plural, n, ...args) {
if (n > 1) return _(plural, ...args);
return _(singular, ...args);
}
module.exports = { _, _n, supportedLocales, countryDisplayName, localeStrings, setLocale, supportedLocalesToLanguages, defaultLocale, closestSupportedLocale, languageCode, countryCodeOnly };

View File

@ -88,6 +88,7 @@ async function createPotFile(potFilePath, sources) {
baseArgs.push('--package-name=Joplin-CLI');
baseArgs.push('--package-version=1.0.0');
baseArgs.push('--no-location');
baseArgs.push('--keyword=_n:1,2');
for (let i = 0; i < sources.length; i++) {
let args = baseArgs.slice();

View File

@ -0,0 +1,35 @@
'use strict';
// Dependencies:
//
// sudo apt install gettext
require('app-module-path').addPath(`${__dirname}/../ReactNativeClient`);
const rootDir = `${__dirname}/..`;
const fs = require('fs-extra');
const cliLocalesDir = `${rootDir}/CliClient/locales`;
const { execCommand } = require('./tool-utils.js');
async function main() {
const files = fs.readdirSync(cliLocalesDir);
let hasErrors = false;
for (const file of files) {
if (!file.endsWith('.po')) continue;
const fullPath = `${cliLocalesDir}/${file}`;
try {
await execCommand(`msgfmt -v "${fullPath}"`);
} catch (error) {
hasErrors = true;
console.error(error);
}
}
if (hasErrors) throw new Error('Some .po files could not be validated');
}
main().catch((error) => {
console.error(error);
process.exit(1);
});