Last active
April 25, 2026 16:25
-
-
Save mingsai/51a7a067efeeda51951c5f744a50a4a7 to your computer and use it in GitHub Desktop.
Flutter String Extraction 1 - First pass extraction from flutter app (use in project root with diagnostics folder)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # extract_hardcoded_strings.sh | |
| # Extracts hardcoded UI strings from Dart widget files and writes a | |
| # draft ARB file to diagnostics/l10n_tmp/extracted_hardcoded_en.arb. | |
| # | |
| # Usage: | |
| # bash scripts/extract_hardcoded_strings.sh | |
| # | |
| # Output: | |
| # diagnostics/l10n_tmp/extracted_hardcoded_en.arb | |
| # | |
| # Notes: | |
| # - Skips interpolated strings (those containing $) | |
| # - Deduplicates; keys are camelCase-safe snake_case derived from value | |
| # - Does NOT modify lib/ — output is for review and manual merge only | |
| set -euo pipefail | |
| OUT="diagnostics/l10n_tmp/extracted_hardcoded_en.arb" | |
| mkdir -p diagnostics/l10n_tmp | |
| { | |
| # Pass 1: Text('...') single-quoted, no interpolation | |
| rg --no-filename --no-heading -o "Text\(\s*'[^'\$\n]*'\s*\)" lib/ -g '*.dart' \ | |
| | sed -E "s/^(const )?Text\( *'(.+)' *\)$/\2/" | |
| # Pass 2: Text("...") double-quoted, no interpolation | |
| rg --no-filename --no-heading -o 'Text\(\s*"[^"$\n]*"\s*\)' lib/ -g '*.dart' \ | |
| | sed -E 's/^(const )?Text\( *"(.+)" *\)$/\2/' | |
| # Pass 3: named params — title/subtitle/label/header/middle/hintText/helperText/errorText/tooltip | |
| rg --no-filename --no-heading -o "(title|subtitle|label|header|middle|hintText|helperText|errorText|tooltip)\s*:\s*'[^'\$\n]*'" lib/ -g '*.dart' \ | |
| | sed -E "s/^[a-zA-Z]+\s*:\s*'(.+)'$/\1/" | |
| } \ | |
| | grep -v '^\s*$' \ | |
| | grep -v '\$' \ | |
| | sed -E 's/^[[:space:]]+|[[:space:]]+$//g' \ | |
| | sort -u \ | |
| | awk ' | |
| BEGIN { OFS="\t" } | |
| { | |
| v=$0 | |
| k=tolower(v) | |
| gsub(/[^a-z0-9]+/, "_", k) | |
| gsub(/^_+|_+$/, "", k) | |
| if (length(k)==0 || length(k)>60) next | |
| base=k | |
| if (seen[base] && seen[base] != v) { | |
| n[base]++ | |
| k=base "_" n[base] | |
| } else if (!seen[base]) { | |
| seen[base]=v | |
| n[base]=1 | |
| } | |
| print k "\t" v | |
| }' \ | |
| | jq -Rn ' | |
| {"@@locale":"en"} + | |
| (reduce inputs as $line | |
| ({}; | |
| ($line | split("\t")) as $p | |
| | if ($p|length)==2 then . + {($p[0]): $p[1]} else . end)) | |
| ' > "$OUT" | |
| echo "Wrote: $OUT" | |
| echo "Total keys: $(jq 'keys | length' "$OUT")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment