From bcfb614ccdfb75609a709a44201a725f8e84b339 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 5 Aug 2020 11:49:50 +0700 Subject: [PATCH] chore(android): Add script to find unused strings. Manually remove them Similar to #3412 1. Adds a similar script from Windows to identify unused Android strings (from KMAPro and KMEA strings.xml) 2. Remove the unused strings from strings.xml As part of the manual cleanup, consolidated the strings `missing_metadata` and `invalid_metadata`. Also changed string name `model` to a more specific `model_label` --- .../kMAPro/src/main/res/values/strings.xml | 4 +- .../kmea/LanguageSettingsActivity.java | 2 +- .../KMEA/app/src/main/res/values/strings.xml | 5 +- android/utility/.gitignore | 3 + android/utility/i18n-check-unused-strings.sh | 67 +++++++++++++++++++ 5 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 android/utility/.gitignore create mode 100755 android/utility/i18n-check-unused-strings.sh diff --git a/android/KMAPro/kMAPro/src/main/res/values/strings.xml b/android/KMAPro/kMAPro/src/main/res/values/strings.xml index caddaa42f9..7461a0b4d6 100644 --- a/android/KMAPro/kMAPro/src/main/res/values/strings.xml +++ b/android/KMAPro/kMAPro/src/main/res/values/strings.xml @@ -82,9 +82,7 @@ Install Predictive Text Package %1$s No new touch-optimized keyboards to install No new predictive text to install - No valid touch-optimized keyboards to install No keyboards or predictive text to install - kmp.json does not exist - Invalid metadata in package + Invalid/Missing metadata in package diff --git a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/LanguageSettingsActivity.java b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/LanguageSettingsActivity.java index 0270eaeb00..552d6069a0 100644 --- a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/LanguageSettingsActivity.java +++ b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/LanguageSettingsActivity.java @@ -166,7 +166,7 @@ public final class LanguageSettingsActivity extends AppCompatActivity { layout = (RelativeLayout)findViewById(R.id.model_picker); textView = (TextView) layout.findViewById(R.id.text1); - textView.setText(getString(R.string.model)); + textView.setText(getString(R.string.model_label)); lexicalModelTextView = layout.findViewById(R.id.text2); diff --git a/android/KMEA/app/src/main/res/values/strings.xml b/android/KMEA/app/src/main/res/values/strings.xml index 188ab190b7..d1a2390bbc 100644 --- a/android/KMEA/app/src/main/res/values/strings.xml +++ b/android/KMEA/app/src/main/res/values/strings.xml @@ -33,9 +33,6 @@ Would you like to delete this keyboard? Would you like to download the latest version of this keyboard? Would you like to update keyboards and dictionaries now? - Custom Keyboard - Warning: Font failed to download - Error: Keyboard failed to download Resource Updates Resource Updates Available %1$s (Update Available) @@ -79,7 +76,7 @@ Enable corrections Enable predictions - Dictionary + Dictionary Dictionary: %1$s %1$s dictionaries Manage dictionary diff --git a/android/utility/.gitignore b/android/utility/.gitignore new file mode 100644 index 0000000000..7cc5fc0c85 --- /dev/null +++ b/android/utility/.gitignore @@ -0,0 +1,3 @@ +detail.md +summary.md +strings.txt diff --git a/android/utility/i18n-check-unused-strings.sh b/android/utility/i18n-check-unused-strings.sh new file mode 100755 index 0000000000..114bb1b854 --- /dev/null +++ b/android/utility/i18n-check-unused-strings.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# +# This script finds all references to strings in strings.xml in order to make sure that old +# strings do not proliferate over time. The script generates the following files: +# +# * strings.txt: A plain-text list of all string identifiers found in strings.xml. +# * summary.md: A summary of number of matches for each string found. +# * details.md: List of every reference to each string found +# +# Note that you should review the results with care; some strings may not ever be found, +# because they may be metadata such as "author of translation", or they may have been +# added as part of upcoming functionality; they may also be found in temporary files and +# build artifacts. Because of this, and because the script takes a little while to run, +# I'm not adding the script to the standard build at this time. +# +# Note: strings that aren't expected to be found generally should have `translateable="false"`` so they don't get +# translated in crowdin. +# + +set -e # die on non-zero exit code +set -u # die on undefined variables + +## START STANDARD BUILD SCRIPT INCLUDE +# adjust relative paths as necessary +THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")" +. "$(dirname "$THIS_SCRIPT")/../../resources/build/build-utils.sh" +## END STANDARD BUILD SCRIPT INCLUDE + +# Preparation + +echo "# List of localized string usage" > detail.md +echo "Collected at: $(date)" >> detail.md +echo >> detail.md + +echo "# Summary of localized string usage" | tee summary.md +echo "Collected at: $(date)" | tee -a summary.md +echo | tee -a summary.md +echo " Count | String | Flag" | tee -a summary.md +echo "-------|--------|------" | tee -a summary.md + +# Lazy extract all identifiers from strings.xml into local strings.txt +# Note that this relies on the XML following a single line per string pattern +# (up to the name attribute, anyway) but this is good enough for now. + +grep -oP ' strings.txt + +while IFS= read -r string; do + echo "## $string" >> detail.md + count=$(grep -Inr \ + --exclude=strings.xml \ + --exclude-dir=utility \ + --exclude-dir=__history \ + "$string" \ + "$KEYMAN_ROOT/android/KMAPro/kMAPro/src/main/res/layout" "$KEYMAN_ROOT/android/KMAPro/kMAPro/src/main/res/menu" "$KEYMAN_ROOT/android/KMAPro/kMAPro/src/main/java" \ + "$KEYMAN_ROOT/android/KMEA/app/src/main/res/layout" "$KEYMAN_ROOT/android/KMEA/app/src/main/java" | tee -a detail.md | wc -l) + echo >> detail.md + + # Write summary + if [ $count -eq 0 ]; then + echo "**0** | **$string** | **Not found**" | tee -a summary.md + else + echo "$count | $string" | tee -a summary.md + fi + +done < strings.txt