#!/bin/sh
#
# Usage:
#   LANGNAME=<value>
#   . languagemap
#
# The calling script should provide the log() function

for list in /etc/languagelist /usr/share/localechooser/languagelist ./languagelist; do
	if [ -f "$list" ]; then
		languages="$list"
		break
	fi
done

log "Language = '$LANGUAGE'"

line=$(grep "^$LANGUAGE;" $languages || true)
log "line=$line"

DEFAULT_COUNTRY=""
DEFAULT_LOCALE=""
LANGUAGELIST=""
CONSOLE=""

if [ "$line" ] ; then
	OLD_IFS="$IFS"
	IFS=';'
	set $line
	IFS="$OLD_IFS"

	if [ "$3" ]; then DEFAULT_COUNTRY="$3"; fi
	if [ "$4" ]; then ENCODING="$4"; fi
	if [ "$5" ]; then DEFAULT_LOCALE="$5"; fi
	if [ "$6" ]; then LANGUAGELIST="$6"; fi
	if [ "$7" ]; then CONSOLE="$7"; fi

	if [ -z "$LANGUAGELIST" ] ; then
		LANGUAGELIST="$LANGUAGE"
	fi
else
	log "error: Unable to locate info for language '$LANGUAGE'"
	LANGUAGE=C
	DEFAULT_COUNTRY=US
	ENCODING=""
	DEFAULT_LOCALE=C
	LANGUAGELIST=en
fi
