-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30-sync-basic.sh
More file actions
executable file
·185 lines (156 loc) · 5.07 KB
/
30-sync-basic.sh
File metadata and controls
executable file
·185 lines (156 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# Example 30: Sync — Basic Usage
# Demonstrates scanning, diffing, and syncing i18n locale files
set -e # Exit on error
echo "=== DeepL CLI Example 30: Sync — Basic Usage ==="
echo
# Check if API key is configured
if ! deepl auth show &>/dev/null; then
echo "Error: API key not configured"
echo "Run: deepl auth set-key YOUR_API_KEY"
exit 1
fi
echo "API key configured"
echo
# Setup: Create a test project with i18n files
PROJECT_DIR="/tmp/deepl-sync-demo"
rm -rf "$PROJECT_DIR"
mkdir -p "$PROJECT_DIR/locales"
cleanup() {
rm -rf "$PROJECT_DIR"
}
trap cleanup EXIT
echo "Created test project: $PROJECT_DIR"
echo
# Example 1: Create source locale files
echo "1. Create source locale files"
cat > "$PROJECT_DIR/locales/en.json" << 'EOF'
{
"greeting": "Hello, world!",
"farewell": "Goodbye!",
"welcome": "Welcome to our application, {name}.",
"items_count": "You have {count} items in your cart.",
"error": {
"not_found": "The requested page was not found.",
"unauthorized": "You must be logged in to access this resource."
}
}
EOF
echo " Created locales/en.json with 6 strings"
echo
# Example 2: Initialize sync configuration
echo "2. Initialize sync configuration"
cd "$PROJECT_DIR"
deepl sync init \
--source-locale en \
--target-locales de,fr,es \
--file-format json \
--path "locales/en.json"
echo
echo " Created .deepl-sync.yaml"
echo " Contents:"
cat "$PROJECT_DIR/.deepl-sync.yaml"
echo
# Example 3: Dry-run to preview changes
echo "3. Preview what would be translated (dry-run)"
deepl sync --dry-run
echo
# Example 4: Run the sync
echo "4. Sync translations"
deepl sync
echo
echo " Generated target files:"
ls -la "$PROJECT_DIR/locales/"
echo
# Example 5: Check translation status
echo "5. Check translation status"
deepl sync status
echo
# Example 6: Validate translations
echo "6. Validate translation integrity"
if ! deepl sync validate; then
echo " (Validation found issues — e.g. placeholder mismatches from translation)"
fi
echo
# Example 7: Add a new string and re-sync
echo "7. Add a new string and re-sync (incremental)"
cat > "$PROJECT_DIR/locales/en.json" << 'EOF'
{
"greeting": "Hello, world!",
"farewell": "Goodbye!",
"welcome": "Welcome to our application, {name}.",
"items_count": "You have {count} items in your cart.",
"new_feature": "Check out our brand new feature!",
"error": {
"not_found": "The requested page was not found.",
"unauthorized": "You must be logged in to access this resource."
}
}
EOF
echo " Added 'new_feature' key to en.json"
echo " Running incremental sync (only new/changed strings)..."
deepl sync
echo
# Example 8: Sync a specific locale
echo "8. Sync a specific locale"
deepl sync --locale de
echo
# Example 9: Force re-translate all strings
echo "9. Force re-translate (ignores lockfile)"
deepl sync --force --yes --locale fr
echo
# Example 10: JSON output for scripting
echo "10. JSON output for scripting"
deepl sync status --format json
echo
# Example 11: Export source strings to XLIFF
echo "11. Export source strings to XLIFF for CAT tool handoff"
deepl sync export --output "$PROJECT_DIR/handoff.xlf"
echo " Wrote $PROJECT_DIR/handoff.xlf"
# Re-running requires --overwrite:
# deepl sync export --output "$PROJECT_DIR/handoff.xlf" --overwrite
echo
echo "=== Sync Features ==="
echo
echo "File scanning:"
echo " - Detects i18n files from .deepl-sync.yaml bucket patterns"
echo " - Supports JSON, YAML, PO, Android XML, iOS Strings, ARB, XLIFF"
echo " - Multiple buckets for mixed-format projects"
echo
echo "Incremental sync:"
echo " - Lockfile (.deepl-sync.lock) tracks content hashes"
echo " - Only new and changed strings are sent to the API"
echo " - Deleted keys are removed from target files"
echo
echo "Translation quality:"
echo " - Formality control (--formality)"
echo " - Glossary support (--glossary)"
echo " - Auto-context extraction from source code"
echo " - Model type selection (--model-type)"
echo " - Translation memory (translation.translation_memory in .deepl-sync.yaml)"
echo
cat <<'EOF'
Translation memory (YAML config shape; no CLI override on sync):
translation:
model_type: quality_optimized # required when using translation memory
translation_memory: my-tm # name or UUID; resolved once per run
translation_memory_threshold: 80 # optional; 0-100 integer, default 75
locale_overrides:
de:
translation_memory: de-specific-tm # per-locale override wins over top-level
fr:
translation_memory_threshold: 90 # threshold-only override; inherits top-level TM
EOF
echo "Validation:"
echo " - Placeholder integrity checks ({name}, %d, etc.)"
echo " - Format string consistency"
echo " - HTML/XML tag balance"
echo " - ICU message syntax validation"
echo
echo "Use cases:"
echo " - Local development with real-time localization updates"
echo " - CI/CD pipelines with --frozen mode (exit code 10 for drift)"
echo " - Multi-platform projects (web + mobile in one config)"
echo " - Incremental translation for large projects"
echo
echo "=== All examples completed successfully! ==="