#!/bin/bash

if [ "`uname`" == "FreeBSD" ]; then
  SED=gsed
else
  SED=sed
fi

doLang() {
  xml=res/values-$1/strings.xml
  dir=assets/$2
  basedir=../$2

  version=`cat res/values/strings.xml | egrep 'name="version"' | $SED "s/^.*\">//;s/<.string>.*$//"`
  sha=`git rev-parse --short HEAD`

  cmd=`cat $xml | egrep 'name="about_[A-Z_]*"' | $SED "s/^.*about_//;s/\">/\n/;s/<.string>.*$//" |
    ( cmd=""
      separator=""
      while read name; do
        read value
        name=\`echo $name | $SED "s/_/-/g"\`
        value=\`echo $value | $SED "s/\\//\\\\\\\\\\\\\\\\\\//g"\`
        cmd="$cmd${separator}s/\\[$name\\]/$value/g"
        separator=";"
      done
      echo $cmd )`
  for file in about.htm version-android.htm; do
    rm -f $dir/$file
    $SED "s/\\[VERSION\\]/$version ($sha)/g;$cmd" <$basedir/$file >$dir/$file
  done
}

doLang sk include
doLang cs include_cz
doLang cs include_czop
doLang hu include_hu
