Skip to content

Commit c987532

Browse files
ovitrifclaude
andcommitted
feat: add push script for regional locales
Handles directory naming conversion between Android format and Transifex format: - values-es-rES <-> values-es_ES - values-pt-rBR <-> values-pt_BR - values-b+es+419 <-> values-es_419 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 7d0b1d3 commit c987532

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

scripts/push-translations.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
# Script to push translations to Transifex
4+
# Handles directory naming conversion between Android format and Transifex format
5+
6+
set -e
7+
8+
# Validate script is run from project root
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
11+
RES_DIR="$PROJECT_ROOT/app/src/main/res"
12+
13+
if [ ! -d "$RES_DIR" ]; then
14+
echo "Error: Resource directory not found: $RES_DIR"
15+
echo "Please run this script from the project root directory."
16+
exit 1
17+
fi
18+
19+
if [ ! -f "$PROJECT_ROOT/.tx/config" ]; then
20+
echo "Error: Transifex config not found: $PROJECT_ROOT/.tx/config"
21+
echo "Please ensure Transifex is configured for this project."
22+
exit 1
23+
fi
24+
25+
# Check if tx command is available
26+
if ! command -v tx &> /dev/null; then
27+
echo "Error: Transifex CLI (tx) is not installed or not in PATH"
28+
echo "Please install it: https://developers.transifex.com/docs/cli"
29+
exit 1
30+
fi
31+
32+
# Check if TX_TOKEN is set
33+
if [ -z "$TX_TOKEN" ]; then
34+
echo "Error: TX_TOKEN environment variable is not set"
35+
echo "Please set it with your Transifex API token: export TX_TOKEN=\"your-token\""
36+
exit 1
37+
fi
38+
39+
# Track renamed directories for cleanup
40+
RENAMED_ES_ES=false
41+
RENAMED_PT_BR=false
42+
RENAMED_ES_419=false
43+
44+
# Cleanup function to restore Android directory names
45+
cleanup() {
46+
echo ""
47+
echo "Restoring Android directory names..."
48+
49+
if [ "$RENAMED_ES_ES" = true ] && [ -d "$RES_DIR/values-es_ES" ]; then
50+
echo " Restoring: values-es_ES -> values-es-rES"
51+
mv "$RES_DIR/values-es_ES" "$RES_DIR/values-es-rES"
52+
fi
53+
54+
if [ "$RENAMED_PT_BR" = true ] && [ -d "$RES_DIR/values-pt_BR" ]; then
55+
echo " Restoring: values-pt_BR -> values-pt-rBR"
56+
mv "$RES_DIR/values-pt_BR" "$RES_DIR/values-pt-rBR"
57+
fi
58+
59+
if [ "$RENAMED_ES_419" = true ] && [ -d "$RES_DIR/values-es_419" ]; then
60+
echo " Restoring: values-es_419 -> values-b+es+419"
61+
mv "$RES_DIR/values-es_419" "$RES_DIR/values-b+es+419"
62+
fi
63+
64+
echo "Cleanup complete."
65+
}
66+
67+
# Set trap to ensure cleanup runs even if script fails
68+
trap cleanup EXIT
69+
70+
echo "Pushing translations to Transifex..."
71+
echo ""
72+
73+
# Step 1: Rename Android directories to Transifex format
74+
echo "Converting directory names to Transifex format..."
75+
76+
if [ -d "$RES_DIR/values-es-rES" ]; then
77+
echo " Renaming: values-es-rES -> values-es_ES"
78+
mv "$RES_DIR/values-es-rES" "$RES_DIR/values-es_ES"
79+
RENAMED_ES_ES=true
80+
fi
81+
82+
if [ -d "$RES_DIR/values-pt-rBR" ]; then
83+
echo " Renaming: values-pt-rBR -> values-pt_BR"
84+
mv "$RES_DIR/values-pt-rBR" "$RES_DIR/values-pt_BR"
85+
RENAMED_PT_BR=true
86+
fi
87+
88+
if [ -d "$RES_DIR/values-b+es+419" ]; then
89+
echo " Renaming: values-b+es+419 -> values-es_419"
90+
mv "$RES_DIR/values-b+es+419" "$RES_DIR/values-es_419"
91+
RENAMED_ES_419=true
92+
fi
93+
94+
echo ""
95+
echo "Running tx push..."
96+
97+
# Step 2: Push translations to Transifex
98+
cd "$PROJECT_ROOT"
99+
tx push --translation --all --skip --force
100+
101+
echo ""
102+
echo "Push complete!"

0 commit comments

Comments
 (0)