Skip to content

Commit

Permalink
Tools: Detect missing translation strings on CI (laurent22#5688)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 authored Nov 8, 2021
1 parent 7525661 commit 0ab2352
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
32 changes: 26 additions & 6 deletions .github/scripts/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fi
# release randomly fail.
# =============================================================================

if [ "$IS_PULL_REQUEST" == "1" ]; then
if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then
echo "Step: Running linter..."

npm run linter-ci ./
Expand Down Expand Up @@ -109,6 +109,27 @@ if [ "$IS_PULL_REQUEST" == "1" ]; then
fi
fi

# =============================================================================
# Check that we didn't lose any string due to gettext not being able to parse
# newly modified or added scripts. This is convenient to quickly view on GitHub
# what commit may have broken translation building. We run this on macOS because
# we need the latest version of gettext (and stable Ubuntu doesn't have it).
# =============================================================================

if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then
if [ "$IS_MACOS" == "1" ]; then
echo "Step: Checking for lost translation strings..."

xgettext --version

node packages/tools/build-translation.js --missing-strings-check-only
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
# building PRs so we disable it in this case. The Linux build should provide
Expand All @@ -124,13 +145,12 @@ if [ "$IS_PULL_REQUEST" == "1" ]; then
fi

# =============================================================================
# Prepare the Electron app and build it
# Build the Electron app or Docker image depending on the current tag.
#
# If the current tag is a desktop release tag (starts with "v", such as
# "v1.4.7"), we build and publish to github
#
# Otherwise we only build but don't publish to GitHub. It helps finding
# out any issue in pull requests and dev branch.
# "v1.4.7"), we build and publish to GitHub. Otherwise we only build but don't
# publish to GitHub. It helps finding out any issue in pull requests and dev
# branch.
# =============================================================================

cd "$ROOT_DIR/packages/app-desktop"
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/github-actions-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ jobs:
sudo apt-get update || true
sudo apt-get install -y gettext
sudo apt-get install -y libsecret-1-dev
sudo apt-get install -y translate-toolkit
- name: Install macOS dependencies
if: runner.os == 'macOS'
run: |
brew update
brew install gettext
brew install translate-toolkit
- name: Install Docker Engine
if: runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/server-v')
Expand Down
17 changes: 16 additions & 1 deletion packages/tools/build-translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,18 @@ function deletedStrings(oldStrings, newStrings) {
async function main() {
const argv = require('yargs').argv;

const potFilePath = `${localesDir}/joplin.pot`;
const missingStringsCheckOnly = !!argv['missing-strings-check-only'];

let potFilePath = `${localesDir}/joplin.pot`;

let tempPotFilePath = '';

if (missingStringsCheckOnly) {
tempPotFilePath = `${localesDir}/joplin-temp-${Math.floor(Math.random() * 10000000)}.pot`;
await fs.copy(potFilePath, tempPotFilePath);
potFilePath = tempPotFilePath;
}

const jsonLocalesDir = `${libDir}/locales`;
const defaultLocale = 'en_GB';

Expand All @@ -360,6 +371,8 @@ async function main() {

console.info(`Updated pot file. Total strings: ${oldPotStatus.untranslatedCount} => ${newPotStatus.untranslatedCount}`);

if (tempPotFilePath) await fs.remove(tempPotFilePath);

const deletedCount = oldPotStatus.untranslatedCount - newPotStatus.untranslatedCount;
if (deletedCount >= 5) {
if (argv['skip-missing-strings-check']) {
Expand All @@ -374,6 +387,8 @@ async function main() {
}
}

if (missingStringsCheckOnly) return;

await execCommand(`cp "${potFilePath}" ` + `"${localesDir}/${defaultLocale}.po"`);

fs.mkdirpSync(jsonLocalesDir, 0o755);
Expand Down

0 comments on commit 0ab2352

Please sign in to comment.