#!/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