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
This commit is contained in:
Elisabeth Kulzer
2020-08-29 19:14:17 +02:00
committed by GitHub
parent f05faaa949
commit 4bcb595e5b
6 changed files with 41 additions and 24 deletions

View File

@@ -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
only: unsigned

View File

@@ -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}'

4
package-lock.json generated
View File

@@ -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",

View File

@@ -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 .."
}

6
scripts/pre-commit.sh Normal file → Executable file
View File

@@ -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

14
scripts/precommit/i18n.sh Executable file
View File

@@ -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