tools/po2lua.sh
author sheepluva
Sat, 12 Sep 2015 21:53:53 +0200
branchgettext
changeset 11170 f878b2f71b40
permissions -rwxr-xr-x
conversion script
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11170
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     1
#!/bin/bash
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     2
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     3
if [ -d share ]; then
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     4
    cd share/hedgewars/Data/Locale
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     5
else
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     6
    cd ../share/hedgewars/Data/Locale
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     7
fi
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     8
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
     9
if [[ "$1" -eq '--reverse' ]]; then
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    10
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    11
    # .po to .lua
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    12
    for pofile in *.po; do outfile=$(echo $pofile | sed -r 's/^(.*_)?([^_]+)\.po/\2.lua/'); echo "Generating $outfile ..."; echo 'locale = {' > $outfile; sed -r 's/\\/\\\\/g;s/\r//;/^msg(id|str) /!d;s/r? / /' $pofile | while read line; do data="${line:6}"; if [ ${line:3:1} = i ]; then echo -n "[${data}]="; else echo "$data"; fi; done | sed '$!s/$/,/' >> $outfile ; echo '}' >> $outfile; done
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    13
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    14
else
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    15
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    16
    for file in *.lua; do echo "Updating $file.po ..."; sed -nr 's/--.*$//;/\[ *".*" *\]/{s/^.*\[ *("([^"]*(\\")?)*") *\]\ *= *("[^"]+").*$/msgid \1\nmsgstr \4\n/gp}' "$file" > "$file.tmp"; sleep 1; head -n19 "messages.pot" > "$file.po"; msgmerge --update "$file.po" "$file.tmp"; rename -f 's/\.lua\././' "$file.po"; done
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    17
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    18
fi
f878b2f71b40 conversion script
sheepluva
parents:
diff changeset
    19