Skip to content

Commit 875e90e

Browse files
rishabmamgaiProgramminCatTheLastProject
authored
Basic (incomplete) app_name consistency check script
Co-authored-by: ProgramminCat <[email protected]> Co-authored-by: Sylvia van Os <[email protected]>
1 parent 5ebd23a commit 875e90e

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

.github/workflows/android.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ jobs:
3333
flavor: [Foss, Gplay]
3434
steps:
3535
- uses: actions/checkout@v5
36-
- name: Fail on bad translations
37-
run: if grep -ri "&lt;xliff" app/src/main/res/values*/strings.xml; then echo "Invalidly escaped translations found"; exit 1; fi
3836
- uses: gradle/actions/wrapper-validation@v5
3937
- name: set up OpenJDK 21
4038
run: |

.github/workflows/i18n-check.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: i18n check
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
- staging
8+
- trying
9+
pull_request:
10+
branches:
11+
- main
12+
permissions:
13+
actions: none
14+
checks: none
15+
contents: read
16+
deployments: none
17+
discussions: none
18+
id-token: none
19+
issues: none
20+
packages: none
21+
pages: none
22+
pull-requests: none
23+
repository-projects: none
24+
security-events: none
25+
statuses: none
26+
jobs:
27+
build:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v5
31+
- name: Fail on bad translations
32+
run: if grep -ri "&lt;xliff" app/src/main/res/values*/strings.xml; then echo "Invalidly escaped translations found"; exit 1; fi
33+
- name: Check app_name consistency
34+
run: bash .scripts/check_app_name.sh

.scripts/check_app_name.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
set -e
4+
shopt -s lastpipe # Run last command in a pipeline in the current shell.
5+
6+
# Colors
7+
LIGHTCYAN='\033[1;36m'
8+
GREEN='\033[0;32m'
9+
RED='\033[0;31m'
10+
NC='\033[0m' # No Color
11+
12+
# Vars
13+
SUCCESS=1
14+
CANONICAL_TITLE="Catima"
15+
ALLOWLIST=("ar" "bn" "fa" "fa-IR" "he-IL" "hi" "hi-IN" "kn" "kn-IN" "ml" "mr" "ta" "ta-IN" "zh-rTW" "zh-TW") # TODO: Link values and fastlane with different codes together
16+
17+
function get_lang() {
18+
LANG_DIRNAME=$(dirname "$FILE" | xargs basename)
19+
LANG=${LANG_DIRNAME#values-} # Fetch lang name
20+
LANG=${LANG#values} # Handle "app/src/main/res/values"
21+
LANG=${LANG:-en} # Default to en
22+
}
23+
24+
# FIXME: This function should use its own variables and return a success/fail status, instead of working on global variables
25+
function check() {
26+
# FIXME: This allows inconsistency between values and fastlane if the app name is not Catima
27+
# When the app name is not Catima, it should still check if title.txt and strings.xml use the same app name (or start)
28+
if echo "${ALLOWLIST[*]}" | grep -w -q "${LANG}" || [[ -z ${APP_NAME} ]]; then
29+
return 0
30+
fi
31+
32+
if [[ ${FILE} == *"title.txt" ]]; then
33+
if [[ ! ${APP_NAME} =~ ^${CANONICAL_TITLE} ]]; then
34+
echo -e "${RED}Error: ${LIGHTCYAN}title in $FILE ($LANG) is ${RED}'$APP_NAME'${LIGHTCYAN}, expected to start with ${GREEN}'$CANONICAL_TITLE'. ${NC}"
35+
SUCCESS=0
36+
fi
37+
else
38+
if [[ ${APP_NAME} != "${CANONICAL_TITLE}" ]]; then
39+
echo -e "${RED}Error: ${LIGHTCYAN}app_name in $FILE ($LANG) is ${RED}'$APP_NAME'${LIGHTCYAN}, expected ${GREEN}'$CANONICAL_TITLE'. ${NC}"
40+
SUCCESS=0
41+
fi
42+
fi
43+
}
44+
45+
# FIXME: This checks all title.txt and strings.xml files separately, but it needs to check if the title.txt and strings.xml match for a language as well
46+
echo -e "${LIGHTCYAN}Checking title.txt's. ${NC}"
47+
48+
find fastlane/metadata/android/* -maxdepth 1 -type f -name "title.txt" | while read -r FILE; do
49+
APP_NAME=$(head -n 1 "$FILE")
50+
51+
get_lang
52+
check
53+
done
54+
55+
echo -e "${LIGHTCYAN}Checking string.xml's. ${NC}"
56+
57+
find app/src/main/res/values* -maxdepth 1 -type f -name "strings.xml" | while read -r FILE; do
58+
# FIXME: This only checks app_name, but there are more strings with Catima inside it
59+
# It should check the original English text for all strings that contain Catima and ensure they use the correct app_name for consistency
60+
APP_NAME=$(grep -oP '<string name="app_name">\K[^<]+' "$FILE" | head -n1)
61+
62+
get_lang
63+
check
64+
done
65+
66+
if [[ $SUCCESS -eq 1 ]]; then
67+
echo -e "\n${GREEN}Success!! All app_name values match the canonical title. ${NC}"
68+
else
69+
echo -e "\n${RED}Unsuccessful!! Some app_name values did not match the canonical titles. ${NC}"
70+
exit 1
71+
fi

0 commit comments

Comments
 (0)