tools/po2lua.sh
branchgettext
changeset 11170 f878b2f71b40
equal deleted inserted replaced
11169:01074868ff4f 11170:f878b2f71b40
       
     1 #!/bin/bash
       
     2 
       
     3 if [ -d share ]; then
       
     4     cd share/hedgewars/Data/Locale
       
     5 else
       
     6     cd ../share/hedgewars/Data/Locale
       
     7 fi
       
     8 
       
     9 if [[ "$1" -eq '--reverse' ]]; then
       
    10 
       
    11     # .po to .lua
       
    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
       
    13 
       
    14 else
       
    15 
       
    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
       
    17 
       
    18 fi
       
    19