-
Notifications
You must be signed in to change notification settings - Fork 41
/
i18n.sh
executable file
·54 lines (46 loc) · 1.4 KB
/
i18n.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
50
51
52
53
54
#!/bin/bash
# Usage:
# Initial catalog creation (lang is the language identifier):
# ./i18n.sh lang
# Updating translation and compile catalog:
# ./i18n.sh
# configuration
DOMAIN="deformdemo"
SEARCH_PATH="$DOMAIN/"
LOCALES_PATH="$DOMAIN/locale"
# end configuration
export LANG=en_US.utf8
# create locales folder if not exists
if [ ! -d "$LOCALES_PATH" ]; then
echo "Locales directory not exists, create"
mkdir -p "$LOCALES_PATH"
fi
# create pot if not exists
if [ ! -f "$LOCALES_PATH"/$DOMAIN.pot ]; then
echo "Create pot file"
touch "$LOCALES_PATH"/$DOMAIN.pot
fi
# no arguments, extract and update
if [ $# -eq 0 ]; then
echo "Extract messages"
pot-create "$SEARCH_PATH" -o "$LOCALES_PATH"/$DOMAIN.pot
echo "Update translations"
for po in "$LOCALES_PATH"/*/LC_MESSAGES/$DOMAIN.po; do
lg=${po##$LOCALES_PATH/}
lg=${lg%%/LC_MESSAGES/*}
echo -n "$lg: "
msgmerge -o "$po" "$po" "$LOCALES_PATH"/$DOMAIN.pot
done
echo "Compile message catalogs"
for po in "$LOCALES_PATH"/*/LC_MESSAGES/*.po; do
lg=${po##$LOCALES_PATH/}
lg=${lg%%/LC_MESSAGES/*}
echo -n "$lg: "
msgfmt --statistics -o "${po%.*}.mo" "$po"
done
# first argument represents language identifier, create catalog
else
cd "$LOCALES_PATH"
mkdir -p $1/LC_MESSAGES
msginit -i $DOMAIN.pot -o $1/LC_MESSAGES/$DOMAIN.po -l $1
fi