#!/bin/bash

BSNG_LANGS=( de es it ru )
BSNG_NUM=${#BSNG_LANGS[@]}

WIZARD_LANGS=( de ru )
WIZARD_NUM=${#WIZARD_LANGS[@]}

NXRC_LANGS=( de es ru )
NXRC_NUM=${#NXRC_LANGS[@]}

generate_pot () {

	echo -e "\t${WHITE}+ ${WHITE} .pot files"
	intltool-extract --type=gettext/glade ui/bashstyle7.ui >/dev/null
	xgettext -L python --keyword=_ --keyword=N_ --output=i18n/bs-ng.pot ui/bs-ng.py ui/bashstyle7.ui.h >/dev/null

	xgettext -o i18n/nx-rc.pot -L shell rc/nx-rc rc/settings/*-rc 2>/dev/null

	xgettext -o i18n/bs-ng-wizard.pot -L shell rc/bin/bs-ng-wizard rc/wizard/* 2>/dev/null

}

update_po () {

	local CUR_NUM=1
	echo -e "\t${WHITE}+ ${WHITE} UI .po files${CYAN} (${BSNG_LANGS[@]})"
	for lang in ${BSNG_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "\t${WHITE}  * ${SMOOTHBLUE}[$CUR_NUM/$BSNG_NUM]${WHITE} ${lang}"
			local CUR_NUM=$(($CUR_NUM+1))
		fi
		msgmerge -q -o i18n/${lang}/bs-ng.po i18n/${lang}/bs-ng.po i18n/bs-ng.pot >/dev/null
	done

	local CUR_NUM=1
	echo -e "\t${WHITE}+ ${WHITE} Wizard .po files${CYAN} (${WIZARD_LANGS[@]})"
	for lang in ${WIZARD_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "\t${WHITE}  * ${SMOOTHBLUE}[$CUR_NUM/$WIZARD_NUM]${WHITE} ${lang}"
			local CUR_NUM=$(($CUR_NUM+1))
		fi
		msgmerge -q -o i18n/${lang}/bs-ng-wizard.po i18n/${lang}/bs-ng-wizard.po \
			i18n/bs-ng-wizard.pot >/dev/null
	done

	local CUR_NUM=1
	echo -e "\t${WHITE}+ ${WHITE} NX-RC .po files${CYAN} (${NXRC_LANGS[@]})"
	for lang in ${NXRC_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "\t${WHITE}  * ${SMOOTHBLUE}[$CUR_NUM/$NXRC_NUM]${WHITE} ${lang}"
			local CUR_NUM=$(($CUR_NUM+1))
		fi
		msgmerge -q -o i18n/${lang}/nx-rc.po i18n/${lang}/nx-rc.po i18n/nx-rc.pot >/dev/null
	done

}

generate_mo () {

	local CUR_NUM=1
	echo -e "\t${WHITE}+ ${WHITE} UI .mo files${CYAN} (${BSNG_LANGS[@]})"
	for lang in ${BSNG_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "\t${WHITE}  * ${SMOOTHBLUE}[$CUR_NUM/$BSNG_NUM]${WHITE} ${lang}"
			local CUR_NUM=$(($CUR_NUM+1))
		fi
		msgfmt --output-file=i18n/${lang}/bs-ng.mo i18n/${lang}/bs-ng.po
	done

	local CUR_NUM=1
	echo -e "\t${WHITE}+ ${WHITE} Wizard .mo files${CYAN} (${WIZARD_LANGS[@]})"
	for lang in ${WIZARD_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "\t${WHITE}  * ${SMOOTHBLUE}[$CUR_NUM/$WIZARD_NUM]${WHITE} ${lang}"
			local CUR_NUM=$(($CUR_NUM+1))
		fi
		msgfmt --output-file=i18n/${lang}/bs-ng-wizard.mo i18n/${lang}/bs-ng-wizard.po
	done

	local CUR_NUM=1
	echo -e "\t${WHITE}+ ${WHITE} NX-RC .mo files${CYAN} (${NXRC_LANGS[@]})"
	for lang in ${NXRC_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "\t${WHITE}  * ${SMOOTHBLUE}[$CUR_NUM/$NXRC_NUM]${WHITE} ${lang}"
			local CUR_NUM=$(($CUR_NUM+1))
		fi
		msgfmt --output-file=i18n/${lang}/nx-rc.mo i18n/${lang}/nx-rc.po
	done

}
