#!/usr/bin/env bash set -euo pipefail # Validates that .xcstrings keys follow key-only convention: # lower_snake segments separated by dots # e.g. "settings.display.section_title" # # Usage: # scripts/validate-localization-keys.sh # scripts/validate-localization-keys.sh path/to/Localizable.xcstrings [...] if ! command -v jq >/dev/null 2>&1; then echo "error: 'jq' is required but not installed." >&2 exit 2 fi repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" if [[ $# -gt 0 ]]; then files=("$@") else files=("$repo_root/TheNoiseClock/Localizable.xcstrings") fi key_regex='^[a-z0-9_]+(\.[a-z0-9_]+)+$' had_error=0 for file in "${files[@]}"; do if [[ ! -f "$file" ]]; then echo "error: file not found: $file" >&2 had_error=1 continue fi invalid_keys="$( jq -r '.strings | keys[]' "$file" | rg -v "$key_regex" || true )" if [[ -n "$invalid_keys" ]]; then echo "error: invalid localization keys in $file" >&2 echo "$invalid_keys" | sed 's/^/ - /' >&2 had_error=1 else echo "ok: $file" fi done if [[ $had_error -ne 0 ]]; then exit 1 fi