From a1011e06684fa1d474403e974dcd24035b003efb Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Sat, 11 Nov 2023 10:44:31 +0100 Subject: [PATCH] Support translating Catima app name in feature graphic (#1623) * Support translating Catima app name in feature graphic Co-authored-by: FC (Fay) Stegerman --- .../workflows/generate-feature-graphic.yml | 34 +------------- .../generate_feature_graphic.sh | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 .scripts/generate_feature_graphic/generate_feature_graphic.sh diff --git a/.github/workflows/generate-feature-graphic.yml b/.github/workflows/generate-feature-graphic.yml index 0e3c7670d8..5d173a2257 100644 --- a/.github/workflows/generate-feature-graphic.yml +++ b/.github/workflows/generate-feature-graphic.yml @@ -36,39 +36,7 @@ jobs: find .scripts/generate_feature_graphic/fonts -name '*.ttf' -exec cp {} "$HOME/.fonts" \; fc-cache - name: Generate featureGraphic.png for each language - run: | - for lang in fastlane/metadata/android/*; do - pushd "$lang" - # Place temporary copy for editing if needed - cp ../../../../.scripts/generate_feature_graphic/featureGraphic.svg featureGraphic.svg - # Extract text after 'Catima - ' - export subtext="$(grep -oP '(?<=Catima \S ).*' title.txt || true)" - # If there is subtext, change the .svg accordingly - if [ -n "$subtext" ]; then - perl -pi -e 's/Loyalty Card Wallet/$ENV{subtext}/' featureGraphic.svg - # Set correct font for language if needed (Lexend Deca has limited support) - # We specifically need the Serif version because of the 200 weight - case "$(basename "$lang")" in - bg|el-GR|ru-RU|uk) sed -i "s/Lexend Deca/Noto Serif/" featureGraphic.svg ;; - ja-JP) sed -i "s/Lexend Deca/Noto Serif CJK JP/" featureGraphic.svg ;; - ko) sed -i "s/Lexend Deca/Noto Serif CJK KR/" featureGraphic.svg ;; - zh-CN) sed -i "s/Lexend Deca/Noto Serif CJK SC/" featureGraphic.svg ;; - zh-TW) sed -i "s/Lexend Deca/Noto Serif CJK TC/" featureGraphic.svg ;; - *) ;; - esac - fi - # Ensure images directory exists - mkdir -p images - # Generate .png - convert featureGraphic.svg images/featureGraphic.png - # Optimize .png - optipng images/featureGraphic.png - # Remove metadata (timestamps) from .png - mat2 --inplace images/featureGraphic.png - # Remove temporary .svg - rm featureGraphic.svg - popd - done + run: .scripts/generate_feature_graphic/generate_feature_graphic.sh - name: Create Pull Request uses: peter-evans/create-pull-request@v5.0.2 with: diff --git a/.scripts/generate_feature_graphic/generate_feature_graphic.sh b/.scripts/generate_feature_graphic/generate_feature_graphic.sh new file mode 100644 index 0000000000..e11b57e8d4 --- /dev/null +++ b/.scripts/generate_feature_graphic/generate_feature_graphic.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -euo pipefail + +script_location="$(dirname "$(readlink -f "$0")")" + +for lang in "$script_location/../../fastlane/metadata/android/"*; do + pushd "$lang" || exit 1 + # Place temporary copy for editing if needed + cp "$script_location/featureGraphic.svg" featureGraphic.svg + if grep -q — title.txt; then + # Try splitting title.txt on — (em dash) + IFS='—' read -r appname subtext < title.txt + else + # No result, try splitting on - (dash) + IFS='-' read -r appname subtext < title.txt + fi + export appname=${appname%% } + export subtext=${subtext## } + # If there is subtext, change the .svg accordingly + if [ -n "$subtext" ]; then + perl -pi -e 's/Catima/$ENV{appname}/' featureGraphic.svg + perl -pi -e 's/Loyalty Card Wallet/$ENV{subtext}/' featureGraphic.svg + # Set correct font or font size for language if needed + # (Lexend Deca has limited support and some characters are big) + # We specifically need the Serif version because of the 200 weight + case "$(basename "$lang")" in + bg|el-GR|ru-RU|uk) sed -i "s/Lexend Deca/Noto Serif/" featureGraphic.svg ;; + ja-JP) sed -i "s/Lexend Deca/Noto Serif CJK JP/" featureGraphic.svg ;; + ko) sed -i "s/Lexend Deca/Noto Serif CJK KR/" featureGraphic.svg ;; + kn-IN) sed -i -e 's/font-size="150"/font-size="100"/' -e 's/y="285.511"/y="235.511"/' featureGraphic.svg ;; + zh-CN) sed -i "s/Lexend Deca/Noto Serif CJK SC/" featureGraphic.svg ;; + zh-TW) sed -i "s/Lexend Deca/Noto Serif CJK TC/" featureGraphic.svg ;; + *) ;; + esac + fi + # Ensure images directory exists + mkdir -p images + # Generate .png + convert featureGraphic.svg images/featureGraphic.png + # Optimize .png + optipng images/featureGraphic.png + # Remove metadata (timestamps) from .png + mat2 --inplace images/featureGraphic.png + # Remove temporary .svg + rm featureGraphic.svg + popd || exit 1 +done