1#!/bin/bash
2set -e
3
4# This script verifies the set of translatable string.xml fields against
5# those listed in the localization exports file.
6
7cd "$(dirname "$0")/../.."
8
9exports='../../vendor/google/tools/localization/exports'
10if [ ! -e "$exports" ]; then
11  echo 'Missing localization exports file, skipping verification...'
12  exit 0
13fi
14
15tempdir=$(mktemp -d "${OUT_DIR:-/tmp/}$(basename "$0").XXXXXXXXXXXX")
16trap 'rm -rf "$tempdir"' EXIT
17
18# Find string.xml files that need translation
19expect="$tempdir/expect.txt"
20find . \
21    \( \
22      -iname '*sample*' \
23      -o -iname '*demo*' \
24      -o -iname '*donottranslate*' \
25      -o -iname '*debug*' \
26      -o -iname '*test*' \
27    \) \
28    -prune -o \
29    -path '*/res/values/*strings.xml' \
30    -print \
31  | sed -n 's/.\///p' \
32  | sort \
33  > "$expect"
34
35# Scrape string.xml files for platform branch
36actual="$tempdir/actual.txt"
37grep 'androidx-platform-dev' "$exports" \
38  | grep -Eo '[^ ]+strings\.xml' \
39  | sort \
40  > "$actual"
41
42# Compare and report
43diff=$(diff "${expect}" "${actual}" | { grep '<' || true; })
44if [ -n "$diff" ]; then
45  echo "Missing files in $exports:" >&2
46  diff "$expect" "$actual" | grep strings.xml | sed -n 's/< //p' >&2
47  echo >&2
48  echo 'See go/androidx/playbook#translations for more information' >&2
49  exit 1
50fi
51