# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>

# The traineddata and related files for all languages should be placed in tessdata directory
# Creates separate traineddata packages for each language
# osd.traineddata (Orientation and script detection) is included with tesseract-ocr

_langs=(afr amh ara asm aze aze_cyrl bel ben bod bos bre bul cat ceb ces
chi_sim chi_sim_vert chi_tra chi_tra_vert chr cos cym dan deu div dzo
ell eng enm epo equ est eus fao fas fil fin fra frk frm fry gla gle glg
grc guj hat heb hin hrv hun hye iku ind isl ita ita_old jav jpn jpn_vert
kan kat kat_old kaz khm kir kmr kor kor_vert lao lat lav lit ltz mal mar
mkd mlt mon mri msa mya nep nld nor oci ori osd pan pol por pus que ron
rus san sin slk slv snd spa spa_old sqi srp srp_latn sun swa swe syr
tam tat tel tgk tha tir ton tur uig ukr urd uzb uzb_cyrl vie yid yor)

_langs_deva=(hin mar nep san) 

_realname=tesseract-data
pkgbase=mingw-w64-${_realname}
pkgname=($(for l in ${_langs[@]}; do echo ${MINGW_PACKAGE_PREFIX}-${_realname}-${l}; done) )
pkgver=4.1.0
pkgrel=3
pkgdesc="Language tessdata for Tesseract OCR engine (mingw-w64)"
groups=("${MINGW_PACKAGE_PREFIX}-${_realname}")
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/tesseract-ocr/tessdata_fast"
license=("spdx:Apache-2.0")
depends=()
source=(https://github.com/tesseract-ocr/tessdata_fast/archive/${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('d0e3bb6f3b4e75748680524a1d116f2bfb145618f8ceed55b279d15098a530f9')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  cd "${srcdir}"

  tar -xzf "${srcdir}/${_realname}-${pkgver}.tar.gz" || true
}

build() {
  true
}

# Declare the package functions for tessdata
for l in ${_langs[@]}; do
    eval "
package_${MINGW_PACKAGE_PREFIX}-${_realname}-${l}(){
    pkgdesc=\"($l) Language tessdata for Tesseract OCR engine (mingw-w64)\"

    mkdir -p \${pkgdir}${MINGW_PREFIX}/share/tessdata
    cp \${srcdir}/tessdata_fast-${pkgver}/${l}.* \${pkgdir}${MINGW_PREFIX}/share/tessdata/
    find \${pkgdir}${MINGW_PREFIX}/share/tessdata -type f -exec chmod 0644 {} \;
}
    "
done
