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