# $Id$
# Maintainer: Jan de Groot <jgc@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Thomas Baechler <thomas@archlinux.org>
# Contributor: Alessandro Menti <alessandro.menti@alessandromenti.it>

pkgbase=thunderbird-i18n
pkgver=52.2.1
_pkgmajorver=52
_lightningtag=THUNDERBIRD_52_2_1_RELEASE
pkgrel=2
pkgdesc="Language pack for Thunderbird"
arch=('any')
url="http://www.mozilla.com/"
license=('MPL' 'GPL')

_languages=(
  'ar     "Arabic"'
  'ast    "Asturian"'
  'be     "Belarusian"'
  'bg     "Bulgarian"'
  'bn-BD  "Bengali (Bangladesh)"'
  'br     "Breton"'
  'ca     "Catalan"'
  'cs     "Czech"'
  'cy     "Welsh"'
  'da     "Danish"'
  'de     "German"'
  'dsb    "Lower Sorbian"'
  'el     "Greek"'
  'en-GB  "English (British)"'
  'en-US  "English (US)"'
  'es-AR  "Spanish (Argentina)"'
  'es-ES  "Spanish (Spain)"'
  'et     "Estonian"'
  'eu     "Basque"'
  'fi     "Finnish"'
  'fr     "French"'
  'fy-NL  "Frisian"'
  'ga-IE  "Irish"'
  'gd     "Gaelic (Scotland)"'
  'gl     "Galician"'
  'he     "Hebrew"'
  'hr     "Croatian"'
  'hsb    "Upper Sorbian"'
  'hu     "Hungarian"'
  'hy-AM  "Armenian"'
  'id     "Indonesian"'
  'is     "Icelandic"'
  'it     "Italian"'
  'ja     "Japanese"'
  'ko     "Korean"'
  'lt     "Lithuanian"'
  'nb-NO  "Norwegian (Bokmål)"'
  'nl     "Dutch"'
  'nn-NO  "Norwegian (Nynorsk)"'
  'pa-IN  "Punjabi (India)"'
  'pl     "Polish"'
  'pt-BR  "Portuguese (Brazilian)"'
  'pt-PT  "Portuguese (Portugal)"'
  'rm     "Romansh"'
  'ro     "Romanian"'
  'ru     "Russian"'
  'si     "Sinhala"'
  'sk     "Slovak"'
  'sl     "Slovenian"'
  'sq     "Albanian"'
  'sr     "Serbian"'
  'sv-SE  "Swedish"'
  'ta-LK  "Tamil (Sri Lanka)"'
  'tr     "Turkish"'
  'uk     "Ukrainian"'
  'vi     "Vietnamese"'
  'zh-CN  "Chinese (Simplified)"'
  'zh-TW  "Chinese (Traditional)"'
)

pkgname=()
source=()
makedepends=('mercurial' 'zip')
_url=https://ftp.mozilla.org/pub/mozilla.org/thunderbird/releases/$pkgver/linux-i686/xpi
_lightningurl=https://hg.mozilla.org/releases/l10n/mozilla-release

for _lang in "${_languages[@]}"; do
  _locale=${_lang%% *}
  _pkgname=thunderbird-i18n-${_locale,,}

  pkgname+=($_pkgname)
  source+=("thunderbird-i18n-$pkgver-$_locale.xpi::$_url/$_locale.xpi"
           "lightning-i18n-$pkgver-$_locale::hg+$_lightningurl/$_locale#tag=$_lightningtag")
  eval "package_$_pkgname() {
    _package $_lang
  }"
done

# Don't extract anything
noextract=(${source[@]%%::*})

_package() {
  pkgdesc="$2 language pack for Thunderbird"
  depends=("thunderbird>=$pkgver")
  mkdir -p lightning-i18n-$pkgver-$1-package
  cp -r lightning-i18n-$pkgver-$1/calendar/chrome lightning-i18n-$pkgver-$1-package/chrome
  cat >lightning-i18n-$pkgver-$1-package/install.rdf <<EOF
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest"
               em:id="lightning-langpack-$1@thunderbird.archlinux.org"
               em:name="$1 Lightning Language Pack (Arch Linux)"
               em:description="$1 Lightning/Calendar Language Pack, repackaged for Arch Linux"
               em:version="$pkgver"
               em:type="8"
               em:creator="mozilla.org">

    <em:targetApplication>
      <Description>
        <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
        <em:minVersion>$pkgver</em:minVersion>
        <em:maxVersion>$_pkgmajorver.*</em:maxVersion>
      </Description>
    </em:targetApplication>
  </Description>
</RDF>
EOF
  cat >lightning-i18n-$pkgver-$1-package/chrome.manifest <<EOF
manifest chrome/chrome.manifest
EOF
  cat >lightning-i18n-$pkgver-$1-package/chrome/chrome.manifest <<EOF
locale calendar $1 calendar/
locale lightning $1 lightning/
EOF
  cd lightning-i18n-$pkgver-$1-package
  zip -9 -r ../lightning-i18n-$pkgver-$1.xpi *
  cd ..
  install -Dm644 thunderbird-i18n-$pkgver-$1.xpi \
    "$pkgdir/usr/lib/thunderbird/extensions/langpack-$1@thunderbird.mozilla.org.xpi"
  install -Dm644 lightning-i18n-$pkgver-$1.xpi \
    "$pkgdir/usr/lib/thunderbird/extensions/lightning-langpack-$1@thunderbird.archlinux.org.xpi"
}

# Since official language packs source lines are interleaved with Lightning
# language packs downloaded from the Mozilla source repository, alternate
# SHA256 checksums with 'SKIP' lines
sha256sums=('22dcd3e9f50ba3defcf53f182f86005bba5ebd828449a875017fc053d7c756cd'
            'SKIP'
            '22cc9023901ca23806d6c481deb14666d0bb226292d1b5429b75dbccf38ad4a5'
            'SKIP'
            'f48ae00c57d88a255d98c0fe75d918666e6018c07664f5572b9b446638989230'
            'SKIP'
            '3f501d2929ba3993ac26ef0987b8906d2f829dcf490547465622ab1165662787'
            'SKIP'
            '57e97e4bec110fb91c06f0ec547e56f3ef206dee6c72bcd0d247ad90bfd9f7ae'
            'SKIP'
            '52275f916bf5aac503fcb318ab5b7ada2a9c8bbdbf1e0a51255c1f56d14c3971'
            'SKIP'
            'fbfb9924784cdd0fb447701bcd24901d982ce540f5b962c8200ded9247fffca0'
            'SKIP'
            '238e9bac5c4d380e0776d042f6748b6913a9144601b0bad2e876b034be021227'
            'SKIP'
            '1f1cc60b8f7b54663fabc2ce548ad054ef7ecc9827430897ac999fbf2d41d90e'
            'SKIP'
            'bfe1f5791408a9b547c06800245f8517ecb3e13a2274e641eca56a9755af26c0'
            'SKIP'
            '3969772d76c2ca21f4c10c485c8fcbc5fad915659c9caa57a192130bb5eb54ce'
            'SKIP'
            '3bbb66c4ce25ea950362612d5947f335205063b27b2410751d8b31da5a3e04a3'
            'SKIP'
            'd51574ad11023b9f67ee3312ccf21899af65bbcdfe27bed19195ac601a20aeed'
            'SKIP'
            'f5f3d2e933290af5a3b02c9a22ad5ae9ab6d00fa359bd57395cbfdbc1d09beb1'
            'SKIP'
            '935e3e388e2d32ae364755e3611103eb82c7096253e9624e3a6bd1cab2e5bd88'
            'SKIP'
            '768e99b9103fd2ff64a9fe124d40250559b14e279091e0b092ebcc4d0b11c450'
            'SKIP'
            '6b912064fd85bb45af5ef0197a7643666839b3007928df69fc42ae23b447cd90'
            'SKIP'
            '5dfbc14d1cd32243fe763cd48bc98dbafcf592f9ed5dcaff4fe39998b745aae6'
            'SKIP'
            '44d7e61ceeac53a923f84e06807aec44080c36d2a6d676a527db76efb4011349'
            'SKIP'
            'dcc53c8de93779ecca4a4591ce24bfccffbea8d9323ae8121928ebcd1eb26378'
            'SKIP'
            '8bd2d255398ea7f4c64d506edccf7466f8a730604a4ee52343aa423faad5ffc3'
            'SKIP'
            'a3501bfdc368011e05bc1a3453a1970fd3f8a1d0c21ac45bf1588352c70eb5b4'
            'SKIP'
            '3dc2f7b8ce9bd9441517a7972216f7cee5c490d20dbef3e7b393298f59dfce20'
            'SKIP'
            '3c9bbc6e543caa0bca0585d5eaf1d4ea600bda07b2ba4446c5df8d8158bb168c'
            'SKIP'
            '68ede5ad952e2fd2f8dae3820c252c163955dd278a81e277cb74c1db6da14e66'
            'SKIP'
            '324a1922900e6344a61ffd174063a027c261795e571eb839043d3c41f1c0504b'
            'SKIP'
            '7e437a6f7bfaf6e156cd4280630595ae02b4fd91b6cecdecf7fa59d73f498056'
            'SKIP'
            '9104b228eaa26cf8bd7406da01c518886a444ac4b7eb0440a683b1c51209e0db'
            'SKIP'
            '2f50db9573f031a6e91c5f7221c97857d561e781f97bfc15dcd4eb5c466624f9'
            'SKIP'
            '49dd57063086b8c51b212ce38833ca458843b3b4176dbf232db31f9ed0225f1f'
            'SKIP'
            '07b0bb412779ba5a6a2da009247519d3fd6c6ccae3b17cd01cf37b74cb289af7'
            'SKIP'
            '6ff308e59bf9e6728e9343bfa7fe54161c16fc98c5b675b48f500c5dd7dcd4b7'
            'SKIP'
            'dc6fc7d3f3e9f90b92c50e3eb55d2b4484c61778e3c87207e4da273e8935abfa'
            'SKIP'
            'a0a623c874b16b6aac4c10d5ee6017c8542549aa1c843b448e0372ca432a6095'
            'SKIP'
            '027327ac1b6b41c719ffe63118e53101ea44d89e66e865c2ff35d74ed8cd260c'
            'SKIP'
            'f14380b74c91e07677d5f7a79c8da55602ea9609c61eb5558000d31cf3cdf55e'
            'SKIP'
            '207bdd8e6845c0b440264b60daeaa9a177114ceefe004876b4b4dc1e7b3b5dc6'
            'SKIP'
            '4b23e0699b73a43a9dba2914d5b30265f0c80ef9912114afca73b10be84d4e37'
            'SKIP'
            'd4829c4fc544b29d09ae7ec908d6036fb2fa74d6705023d5a5bd69bbdf29089a'
            'SKIP'
            'a3205a13e40f975de5f741b00d74a12ca5165719b0c627a4307024521efb5d7b'
            'SKIP'
            '41593d6ed0e2a90f40bcb3e52fd1e44b9f9177f4c8fdb069a38d7e9612e5c44e'
            'SKIP'
            '3436a3b5c304134490501d9aec86803e9d2a19c8d417e546bea4e79e0c580fce'
            'SKIP'
            'f50616dcf2608c7221a83dc1a9736b87b82e2d20e807b31e0fa52267838a01f9'
            'SKIP'
            '5436ec4567d8f9a3f456ed1dad8d5e99b20e17478d452f481b94d86951a4a962'
            'SKIP'
            '7da7e3e2ec1fa3e7df8b2b1d8a886f25f642299b2b48acfd286c14b286d9238f'
            'SKIP'
            '2ec8ee1cc3f4b9467a6252ee9b0b07e21d73c570f4df32da3398ef145969e713'
            'SKIP'
            '528d8810eec40fd7bf7d7f8963177f510498401518f6152ba0d9954d768deb62'
            'SKIP'
            '4d4ed62d2eb370bae612e91387374c96abb45bb753d25a8af2ada2317daedb3b'
            'SKIP'
            'a24004dac5fd3dbfe888b7946392b3a362725fbeb202f70ed05a525dc8ff3f40'
            'SKIP'
            '5bcee7dd135c22f288066df7550f6bebca7fd84ddaf9c0c7fab8cb421b17cbab'
            'SKIP'
            'd91e167f296c877bc0f0dd5fbd608050fb4875e11b7a69728998b0af4dce57e9'
            'SKIP'
            '1b8585d1c6204272c628944b7ec753256dc929a61cb915ca666feed4b8f4f985'
            'SKIP'
            'f0338196052609f2fd24ca5c68c4845993760683b77932a8995c3045d55dcc31'
            'SKIP'
            '984bb440a6d6fa3846badf719a45d0f07e3bb48717debed90cf039b1265702b1'
            'SKIP'
            '11d0136bf683349c56e1eab3fe9a023be6b0057d48a63a5e7cebce1d818e6b92'
            'SKIP'
            'aee7710f39671f1265170641090064cb42ed1f1591298624c7e16ef14640e5c2'
            'SKIP'
            'acc4de2e34fe171f6bb2d1d798c29fb90d841fc1034b80cb9cbdb2c4a58237eb'
            'SKIP'
            'e1a8319aa85f8488b509742e5856d4455ebf1379a6bd3f5a2936636b5124ed7e'
            'SKIP')