conversion script gettext
authorsheepluva
Sat, 12 Sep 2015 21:53:53 +0200
branchgettext
changeset 11170 f878b2f71b40
parent 11169 01074868ff4f
child 11172 db1d14179b6c
conversion script
tools/po2lua.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/po2lua.sh	Sat Sep 12 21:53:53 2015 +0200
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+if [ -d share ]; then
+    cd share/hedgewars/Data/Locale
+else
+    cd ../share/hedgewars/Data/Locale
+fi
+
+if [[ "$1" -eq '--reverse' ]]; then
+
+    # .po to .lua
+    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
+
+else
+
+    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
+
+fi
+