#!/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 "${YELLOW} [01/01] Generating .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 "${YELLOW} [01/02] Updating UI-po files (${BSNG_LANGS[@]})."
	for lang in ${BSNG_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "${SMOOTHBLUE}\t[$CUR_NUM/$BSNG_NUM] ${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 "${YELLOW} [02/02] Updating Wizard-po files (${WIZARD_LANGS[@]})."
	for lang in ${WIZARD_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "${SMOOTHBLUE}\t[$CUR_NUM/$WIZARD_NUM] ${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 "${YELLOW} [02/02] Updating NX-po files (${NXRC_LANGS[@]})."
	for lang in ${NXRC_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "${SMOOTHBLUE}\t[$CUR_NUM/$NXRC_NUM] ${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 "${YELLOW} [02/03] Generating UI-mo files (${BSNG_LANGS[@]})."
	for lang in ${BSNG_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "${SMOOTHBLUE}\t[$CUR_NUM/$BSNG_NUM] ${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 "${YELLOW} [02/03] Generating Wizard-mo files (${WIZARD_LANGS[@]})."
	for lang in ${WIZARD_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "${SMOOTHBLUE}\t[$CUR_NUM/$WIZARD_NUM] ${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 "${YELLOW} [03/03] Generating NX-mo files (${NXRC_LANGS[@]})."
	for lang in ${NXRC_LANGS[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			echo -e "${SMOOTHBLUE}\t[$CUR_NUM/$NXRC_NUM] ${lang}"
			local CUR_NUM=$(($CUR_NUM+1))
		fi
		msgfmt --output-file=i18n/${lang}/nx-rc.mo i18n/${lang}/nx-rc.po
	done

}
