From 4bcb595e5b4807e469ce1a7a45ba018fd45a5922 Mon Sep 17 00:00:00 2001 From: Elisabeth Kulzer Date: Sat, 29 Aug 2020 19:14:17 +0200 Subject: [PATCH] Add check for empty translation strings. (#4718) * Add check for empty translation strings. * Test * Update mmjstools * Resolve conflicts * Revert translation test. * Also use fake dir * Also use fake dir * Add translation checks to precommit hook. Remove from Makefile. Add to circleci. * Fix script to keep it consistent. * Keep consistent --- .circleci/config.yml | 16 ++++++++++++++-- Makefile | 21 ++++----------------- package-lock.json | 4 ++-- package.json | 4 +++- scripts/pre-commit.sh | 6 ++++-- scripts/precommit/i18n.sh | 14 ++++++++++++++ 6 files changed, 41 insertions(+), 24 deletions(-) mode change 100644 => 100755 scripts/pre-commit.sh create mode 100755 scripts/precommit/i18n.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index ccb055f4f..fafcd8c77 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -225,7 +225,19 @@ jobs: command: npm test - run: name: Check i18n - command: make i18n-extract-ci + command: | + mkdir -p tmp + cp assets/base/i18n/en.json tmp/en.json + mkdir -p tmp/fake-webapp-dir/i18n/ + echo '{}' > tmp/fake-webapp-dir/i18n/en.json + + npm run mmjstool -- i18n extract-mobile --webapp-dir tmp/fake-webapp-dir --mobile-dir . + diff tmp/en.json assets/base/i18n/en.json + # Address weblate behavior which does not remove whole translation item when translation string is set to empty + npm run mmjstool -- i18n clean-empty --webapp-dir tmp/fake-webapp-dir --mobile-dir . --check + + rm -rf tmp + check-deps: parameters: @@ -593,4 +605,4 @@ workflows: tags: only: /^v(\d+\.)(\d+\.)(\d+)(.*)?$/ branches: - only: unsigned \ No newline at end of file + only: unsigned diff --git a/Makefile b/Makefile index e5c156e35..86ded9dbf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ .PHONY: pre-run pre-build clean .PHONY: check-style -.PHONY: i18n-extract-ci .PHONY: start stop .PHONY: run run-ios run-android .PHONY: build build-ios build-android unsigned-ios unsigned-android ios-sim-x86_64 @@ -161,20 +160,20 @@ run-android: | check-device-android pre-run prepare-android-build ## Runs the ap fi; \ fi -build: | stop pre-build check-style i18n-extract-ci ## Builds the app for Android & iOS +build: | stop pre-build check-style ## Builds the app for Android & iOS $(call start_packager) @echo "Building App" @cd fastlane && BABEL_ENV=production NODE_ENV=production bundle exec fastlane build $(call stop_packager) -build-ios: | stop pre-build check-style i18n-extract-ci ## Builds the iOS app +build-ios: | stop pre-build check-style ## Builds the iOS app $(call start_packager) @echo "Building iOS app" @cd fastlane && BABEL_ENV=production NODE_ENV=production bundle exec fastlane ios build $(call stop_packager) -build-android: | stop pre-build check-style i18n-extract-ci prepare-android-build ## Build the Android app +build-android: | stop pre-build check-style prepare-android-build ## Build the Android app $(call start_packager) @echo "Building Android app" @cd fastlane && BABEL_ENV=production NODE_ENV=production bundle exec fastlane android build @@ -197,7 +196,7 @@ unsigned-android: stop pre-build check-style prepare-android-build ## Build an u test: | pre-run check-style ## Runs tests @npm test -build-pr: | can-build-pr stop pre-build check-style i18n-extract-ci ## Build a PR from the mattermost-mobile repo +build-pr: | can-build-pr stop pre-build check-style ## Build a PR from the mattermost-mobile repo $(call start_packager) @echo "Building App from PR ${PR_ID}" @cd fastlane && BABEL_ENV=production NODE_ENV=production bundle exec fastlane build_pr pr:PR-${PR_ID} @@ -209,18 +208,6 @@ can-build-pr: exit 1; \ fi -i18n-extract: ## Extract strings for translation from the source code - npm run mmjstool -- i18n extract-mobile - -i18n-extract-ci: - mkdir -p tmp - cp assets/base/i18n/en.json tmp/en.json - mkdir -p tmp/fake-webapp-dir/i18n/ - echo '{}' > tmp/fake-webapp-dir/i18n/en.json - npm run mmjstool -- i18n extract-mobile --webapp-dir tmp/fake-webapp-dir --mobile-dir . - diff tmp/en.json assets/base/i18n/en.json - rm -rf tmp - ## Help documentation https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/package-lock.json b/package-lock.json index 43b9ccb09..5e95640e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16761,8 +16761,8 @@ } }, "mmjstool": { - "version": "github:mattermost/mattermost-utilities#086f4ffdca4e31a0be22f6bcdfa093ed83fb29e8", - "from": "github:mattermost/mattermost-utilities#086f4ffdca4e31a0be22f6bcdfa093ed83fb29e", + "version": "github:mattermost/mattermost-utilities#519b99a4e51e6c67a0dbd46a6efdff27dc835aaa", + "from": "github:mattermost/mattermost-utilities#519b99a4e51e6c67a0dbd46a6efdff27dc835aaa", "dev": true, "requires": { "estree-walk": "2.2.0", diff --git a/package.json b/package.json index 23051a2ff..79e9000f4 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "jetifier": "1.6.6", "jsdom-global": "3.0.2", "metro-react-native-babel-preset": "0.63.0", - "mmjstool": "github:mattermost/mattermost-utilities#086f4ffdca4e31a0be22f6bcdfa093ed83fb29e", + "mmjstool": "github:mattermost/mattermost-utilities#519b99a4e51e6c67a0dbd46a6efdff27dc835aaa", "mock-async-storage": "2.2.0", "mock-socket": "9.0.3", "nock": "13.0.4", @@ -162,6 +162,8 @@ "test:coverage": "jest --coverage", "updatesnapshot": "jest --updateSnapshot", "mmjstool": "mmjstool", + "i18n-extract": "npm run mmjstool -- i18n extract-mobile", + "i18n-clean-empty": "npm run mmjstool -- i18n clean-empty --mobile-dir .", "e2e:android": "cd detox && npm run e2e:android-build && npm run e2e:android-test && cd ..", "e2e:ios": "cd detox && npm run e2e:ios-test && cd .." } diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh old mode 100644 new mode 100755 index ddd0e7377..6e451be29 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -11,7 +11,7 @@ if [ -n "$jsfiles" ]; then for js in $jsfiles; do echo "$js" e=$(node_modules/.bin/eslint --quiet --fix $js) - if [[ -n "$e" ]]; then + if [ -n "$e" ]; then echo "ERROR: Check eslint hints." echo "$e" exit 1 # reject @@ -20,11 +20,13 @@ if [ -n "$jsfiles" ]; then echo "Checking for TSC" tsc=$(node_modules/.bin/tsc --noEmit) - if [[ -n "$tsc" ]]; then + if [ -n "$tsc" ]; then echo "ERROR: Check TSC hints." echo "$tsc" exit 1 # reject fi fi +scripts/precommit/i18n.sh + exit 0 diff --git a/scripts/precommit/i18n.sh b/scripts/precommit/i18n.sh new file mode 100755 index 000000000..49d83b819 --- /dev/null +++ b/scripts/precommit/i18n.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +mkdir -p tmp +cp assets/base/i18n/en.json tmp/en.json +mkdir -p tmp/fake-webapp-dir/i18n/ +echo '{}' > tmp/fake-webapp-dir/i18n/en.json + +npm run mmjstool -- i18n extract-mobile --webapp-dir tmp/fake-webapp-dir --mobile-dir . +diff tmp/en.json assets/base/i18n/en.json +# Address weblate behavior which does not remove whole translation item when translation string is set to empty +npm run mmjstool -- i18n clean-empty --webapp-dir tmp/fake-webapp-dir --mobile-dir . --check + +rm -rf tmp +