d8460fc2b861e89926b9c758d6536d3c734d14fb
[project/luci.git] / build / i18n-sync.sh
1 #!/bin/sh
2
3 print_help() {
4 echo "Execute as ./build/i18n-sync.sh [-b]" >&2
5 echo "Or run as: ./build/i18n-sync.sh [-b] [module folder e.g. applications/luci-app-example]" >&2
6 echo "Options:"
7 echo " -b: Generate the base .pot file ( invokes ./build/mkbasepot.sh )"
8 }
9
10 [ -d ./build ] || {
11 print_help
12 exit 1
13 }
14
15 case $1 in
16 -h | --help )
17 print_help
18 exit 0
19 ;;
20 -b )
21 ./build/mkbasepot.sh
22 shift
23 ;;
24 esac
25
26 [ -n "$1" ] && set -- "${1%/}"
27
28
29 # Absent a [folder] parameter, use the current path
30 find "${1:-.}" -name '*.pot' -and -not -name base.pot | sort | \
31 xargs -P 10 -I{} sh -c '
32 dir="${1%/po/templates/*}"
33 echo "Updating ${1#./} ... "
34 ./build/i18n-scan.pl "$dir" > "$1"
35 echo "done"
36 ' sh {}
37
38 # while read path; do
39 # dir="${path%/po/templates/*}"
40 # echo "Updating ${path#./} ... "
41 # # Scan for strings in a directory and stash them in the .pot file:
42 # ./build/i18n-scan.pl "$dir" > "$path"
43 # echo "done"
44 # done
45
46
47 if [ -n "$1" ]; then
48 if [ "$(uname)" = "Darwin" ] || [ "$(uname)" = "FreeBSD" ]; then
49 # macOS-specific commands
50 find "$1" -path '*/templates/*.pot' -print0 | xargs -0r stat -f '%N' | \
51 xargs -r -n 1 dirname | \
52 xargs -r -n 1 dirname | sort | \
53 xargs -r -n 1 -P 40 ./build/i18n-update.pl
54 elif [ "$(uname)" = "Linux" ]; then
55 # Linux-specific commands
56 find "$1" -path '*/templates/*.pot' -printf '%h ' | \
57 xargs -r -n 1 dirname | \
58 xargs -r -n 1 -P 40 ./build/i18n-update.pl
59 # elif [ "$(uname)" = "SunOS" ]; then
60 # # Solaris-specific commands
61 else
62 # GNU specific commands can go here:
63 find "$1" -path '*/templates/*.pot' -printf '%h ' | \
64 xargs -r -n 1 dirname | \
65 xargs -r -n 1 -P 40 ./build/i18n-update.pl
66 fi
67 else
68 # this performs operations on all .po files
69 ./build/i18n-update.pl
70 fi