4 if [ "$#" -eq 0 ]; then
5 echo $0 "adds i18n catalogue(s) in po/ folders (luci-app-*, luci-mod-*, etc) for each LUCI_LANG.* in luci.mk"
6 echo "Hint: run in the root of the luci repo or in your luci-app-* folder."
8 # get existing language codes from luci.mk
9 language_codes
=$
(grep -o 'LUCI_LANG\.[a-zA-Z]*' $
(dirname "$0")/..
/luci.mk | cut
-d '.' -f 2 |
sort -u)
13 for LANG
in $LANGS; do
15 [a-z
][a-z
]|
[a-z
][a-z
][_-
][A-Za-z
][A-Za-z
]*) : ;;
17 echo $0 "adds i18n catalogues in each folder (luci-app-*, luci-mod-*, etc)."
18 echo "Usage: $0 <ISO_CODE> [<ISO_CODE> <ISO_CODE> ...]" >&2
27 for podir
in $
(find .
-type d
-name "po"); do
28 [ -d "$podir/templates" ] ||
continue
29 for LANG
in $LANGS; do
30 # if "$podir/$LANG" doesn't exist, mkdir
31 [ -d "$podir/$LANG" ] || mkdir
"$podir/$LANG"
32 for catalog
in $
(cd "$podir/templates"; echo *.pot
); do
33 if [ -f "$podir/templates/$catalog" -a ! -f "$podir/$LANG/${catalog%.pot}.po" ]; then
34 msginit
--no-translator -l "$LANG" -i "$podir/templates/$catalog" -o "$podir/$LANG/${catalog%.pot}.po"
35 git add
"$podir/$LANG/${catalog%.pot}.po"
42 start_marker
="^#LUCI_LANG_START$"
43 end_marker
="^#LUCI_LANG_END$"
46 for LANG
in $LANGS; do
47 if [[ $language_codes != *"$LANG"* ]]; then
49 # Read the contents of the luci.mk file
50 file_content
=$
(cat "$(dirname "$0")/../luci.mk")
52 # Extract the section between start and end markers
53 section
=$
(awk -v start
="$start_marker" -v end
="$end_marker" '
54 $0 ~ start {RS="\n"; printf ""; flag=1; next}
55 $0 ~ end {flag=0} flag' <<< "$file_content")
57 # Add the new language code to the section
58 section
+="\nLUCI_LANG.$LANG=New language"
59 # Sort the section and remove duplicates
60 updated_content
=$
(echo -e "$section" |
sort -u |
sed -E "/$start_marker/,/$end_marker/{ /$start_marker/{p; r /dev/stdin
62 }" $
(dirname "$0")/..
/luci.mk
)
64 # Write the updated content back to the .mk file
65 echo "$updated_content" > $
(dirname "$0")/..
/luci.mk
67 echo "Be sure to update the new language name in $(dirname "$0")/../luci.mk"