#!/bin/bash

#Translation
export TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAIN=bigocrpdf

mkdir -p ~/.config/bigocrpdf

if [ "${LANG:0:2}" = "pt" ] && [ "$(tesseract --list-langs | grep por)" != "" ]
then
    OCR_LANG="por"
    
elif [ "${LANG:0:2}" = "es" ] && [ "$(tesseract --list-langs | grep spa)" != "" ]
then
    OCR_LANG="spa"
    
elif [ "${LANG:0:2}" = "en" ] && [ "$(tesseract --list-langs | grep eng)" != "" ]
then
    OCR_LANG="eng"
else
    OCR_LANG="osd"
fi


tesseract -l $OCR_LANG "$*" "$HOME/.config/bigocrpdf/text"

xdg-open "$HOME/.config/bigocrpdf/text.txt"
