#!/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 DEFAULT_LOCALE="$4"; fi
	if [ "$5" ]; then LANGUAGELIST="$5"; fi
	if [ "$6" ]; then CONSOLE="$6"; fi

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