-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmerge_messages.sh
executable file
·49 lines (37 loc) · 1.14 KB
/
merge_messages.sh
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
#!/bin/bash
set -euo pipefail
# Check required commands
for cmd in msgmerge msgen msgcat; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: '$cmd' command not found"
exit 1
fi
done
LOCALE_DIR="../locale"
TEMPLATE="i18n-template-php.pot"
# Check if locale directory exists
if [ ! -d "$LOCALE_DIR" ]; then
echo "Error: Locale directory not found: $LOCALE_DIR"
exit 1
fi
# Check if template file exists
if [ ! -f "$LOCALE_DIR/$TEMPLATE" ]; then
echo "Error: Template file not found: $LOCALE_DIR/$TEMPLATE"
exit 1
fi
# Get list of available locales, excluding template
dirs=$(ls "$LOCALE_DIR" | grep -v pot)
# Update every messages.mo for every locale
for locale in $dirs; do
echo "Updating $locale locale"
cd "$LOCALE_DIR/$locale/LC_MESSAGES" || {
echo "Error: Failed to change directory to $LOCALE_DIR/$locale/LC_MESSAGES"
exit 1
}
msgmerge --backup=none -N -U messages.po "../../$TEMPLATE"
msgen "../../$TEMPLATE" > default.po
msgcat --use-first messages.po default.po -o messages.po
# Clean up temporary file
rm -f default.po
cd "../../" || exit 1
done