# Maintainer: Luke Shumaker <lukeshu@sbcglobal.net>
# Contributor: fauno <fauno@kiwwwi.com.ar>
# Contributor: Figue <ffigue@gmail.com>
# Maintainer: Márcio Silva <coadde@lavabit.com>
# Maintainer: André Silva <emulatorman@lavabit.com>
# Based on icecat-i18n package, which is in turn based on firefox-i18n

# When updating to a newer upstream release:
# - Edit variables in in Makefile.
# - (optionally) edit PKGBUILD.in
# - Run 'make'. It will take care of everything else for you.

_debname=iceape
_debver=2.7.12
_debrel=1
_debrepo=http://ftp.debian.org/debian/pool/main/
debfile() { echo $@|sed -r 's@(.).*@\1/&/&@'; }

_langpacks=(be ca cs de en-GB es-AR es-ES fi fr gl hu it ja lt nb-NO nl pl pt-PT ru sk sv-SE tr zh-CN)

pkgbase=iceape-l10n
pkgname=($(for lang in ${_langpacks[@]}
        do echo $pkgbase-$lang | tr A-Z a-z
        done))
pkgver=${_debver}.${_debrel}
pkgrel=1

pkgdesc="Language packs for Debian Iceape."
arch=('i686' 'x86_64' 'mips64el')
url="http://packages.debian.org/source/sid/iceape"
license=('MPL')
depends=("iceape-libre>=$pkgver")
makedepends=('unzip' 'zip')
source=('region.properties')
for lang in ${_langpacks[@]}
do
    source+=("${_debrepo}/`debfile ${_debname}`-l10n-$(echo $lang | tr A-Z a-z)_${_debver}-${_debrel}_all.deb")
done

_path="/usr/lib/iceape/extensions"

build() {
  cd "${srcdir}"
  for f in *.deb
  do
      bsdtar xf $f
      bsdtar xf data.tar.gz
  done

  cd $srcdir/$_path

  for i in ${_langpacks[@]}
  do
    cd $srcdir/$_path
    unzip -q langpack-$i@iceape.mozilla.org.xpi -d $i
    rm langpack-$i@iceape.mozilla.org.xpi
    install -Dm644 $srcdir/region.properties $i/chrome/$i/locale/browser-region
    cd $i
    zip -q -r $srcdir/$_path/langpack-$i@iceape.mozilla.org.xpi .
  done

  cd $srcdir
}

for lang in ${_langpacks[@]}
do
    eval "
package_iceape-l10n-$(echo $lang | tr A-Z a-z)() {
  replaces=(iceape-i18n-$(echo $lang | tr A-Z a-z))
  conflicts=(iceape-i18n-$(echo $lang | tr A-Z a-z))
  provides=(iceape-i18n-$(echo $lang | tr A-Z a-z))
  install -Dm644 \"\$srcdir$_path/langpack-$lang@iceape.mozilla.org.xpi\" \"\$pkgdir$_path/langpack-$lang@iceape.mozilla.org.xpi\"
}
"
done

md5sums=('428246ef3fb64103ff2cf5eaae2a92ca'
         '22a14a6a2f03d0004a1fa990892094ef'
         'af2379ea50672fe37ff8550d5c9e20a0'
         'e5975c3b1ffaa5fcb3f5203cdfe8e0fb'
         '21fcbd011acc382f5ec7a32aa04562ef'
         '8fbf821c811c55514a100ae5d5e9e844'
         'bd8f18e0d0f233e0a1c1a518537798a5'
         '037cbb6fe0576f7f5bbbf956928f01e1'
         '56964b577fcb077a9b81d07c59cc5af3'
         'd2fb622717114a921efb37f028f31c6c'
         '6abe2dbab7fcbdaf43e77290ca6853c9'
         '558a2d29be749f6506f774703c58952f'
         '7abdc6eb4154b88509a6c4f119c943a7'
         '5a4fad9c23c8d19833ac5c76ad9aca4a'
         '8d45110acc90f388923f01fb9cfca947'
         'd1acbe2ef1120e70d5365476aa8679f9'
         '604de00ea6ee06565212804b0d499df3'
         'ceee78a29bd2f947558f04489ee50f54'
         'afc6e343f0635a3ee5b7a22af947e8b8'
         '455bab7a596cb43ac4ad80cb89a78b25'
         '92a985b40aec8b3726ba22f45667994d'
         'bc8c98f0518617ed2220fb3bfb03e165'
         '449c91720751538f09ad3d555dbe2fce'
         '8843be8937963d094d4272ac33019082')