#!/bin/sh
# $Id$
# *===========================================================================*
# |                 Copyright (c) 2008 Applaud Solutions UK Ltd               |
# |                             All rights reserved                           |
# *===========================================================================*

header_string="$Id$"
prog_version=`echo "$header_string" | awk '{print $3}'`
program=`basename $0 .sh`

usage="\t$program"

$XXAS_LOG "Starting nls apply:"
#
# Set the applyfile script
#
nsl_ver=$1
import_dir=$2
applyfile=$XXAS_PATCH_BIN/xxas_com_applyfile.sh

#
# Verify that the applyfile exists
#
if test ! -f "$applyfile" ; then
  printf "\nERROR: The following file cannot be found:\n"
  printf "$applyfile\n\n"
  exit 1;
fi

#
# Apply wrapper function
#
apply () {
  $XXAS_LOG "Applying: $1..."
  $applyfile $1
  exit_code=$?
  if [ $exit_code -ne 0 ];
  then
    exit 1;
  fi
  $XXAS_LOG "Finished applying: $1"
}

con_string () {
if test -d $XXAS_PATCH_PROD/${import_dir}/nls/${1}; then
	if [ `find $XXAS_PATCH_PROD/${import_dir}/nls/${1} -name "*menu_${1}.ldt" | wc -l` -ge 1 ]; then
		for i in `ls $XXAS_PATCH_PROD/${import_dir}/nls/${1}/*menu_${1}.ldt`;
		do
			menu_file=`echo $i | awk -F"/" '{print $NF}'`
			apply "file:XXAS_TOP:${import_dir}/nls/${1}:$menu_file:$nsl_ver:dat_menu"
		done
	fi
	if [ `find $XXAS_PATCH_PROD/${import_dir}/nls/${1} -name "*messages_${1}.ldt" | wc -l` -ge 1 ]; then
		for j in `ls $XXAS_PATCH_PROD/${import_dir}/nls/${1}/*messages_${1}.ldt`;
		do
			msg_file=`echo $j | awk -F"/" '{print $NF}'`
			apply "file:XXAS_TOP:${import_dir}/nls/${1}:$msg_file:$nsl_ver:dat_msg"
		done
	fi
	if [ `find $XXAS_PATCH_PROD/${import_dir}/nls/${1} -name "*lookup_${1}.ldt" | wc -l` -ge 1 ]; then
		for k in `ls $XXAS_PATCH_PROD/${import_dir}/nls/${1}/*lookup_${1}.ldt`;
		do
			lkp_file=`echo $k | awk -F"/" '{print $NF}'`
			apply "file:XXAS_TOP:${import_dir}/nls/${1}:$lkp_file:$nsl_ver:dat_lkp"
		done
	fi
fi
}	

for i in `cat installed_lang.txt`
do
	case $i in
	AR)
		NLS_LANG="ARABIC_UNITED ARAB EMIRATES.AR8ISO8859P6"
		export NLS_LANG
		con_string ar
	;;
	PTB)
		NLS_LANG="BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1"
		export NLS_LANG
		con_string ptb
	;;
	F)
		NLS_LANG="FRENCH_FRANCE.WE8ISO8859P1"
		export NLS_LANG
		con_string f
	;;
	ESA)
		NLS_LANG="LATIN AMERICAN SPANISH_AMERICA.WE8ISO8859P1"
		export NLS_LANG
		con_string esa
	;;
	FRC)
		NLS_LANG="CANADIAN FRENCH_CANADA.WE8ISO8859P1"
		export NLS_LANG
		con_string frc
	;;
	E)
		NLS_LANG="SPANISH_SPAIN.WE8ISO8859P1"
		export NLS_LANG 
		con_string e
	;;
	IN)
		NLS_LANG="INDONESIAN_INDONESIA.WE8ISO8859P1"
		export NLS_LANG 
		con_string in
	;;
	JA)
		NLS_LANG="JAPANESE_JAPAN.JA16EUC"
		export NLS_LANG 
		con_string ja
	;;
	KO)
		NLS_LANG="KOREAN_KOREA.KO16KSC5601"
		export NLS_LANG 
		con_string ko
	;;
	TH)
		NLS_LANG="THAI_THAILAND.TH8TISASCII"
		export NLS_LANG 
		con_string th
	;;
	VN)
		NLS_LANG="VIETNAMESE_VIETNAM.AL32UTF8"
		export NLS_LANG 
		con_string vn
	;;
	ZHS)
		NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16CGB231280"
		export NLS_LANG 
		con_string zhs
	;;
	ZHT)
		NLS_LANG="TRADITIONAL CHINESE_TAIWAN.ZHT16BIG5"
		export NLS_LANG 
		con_string zht
	;;
	NL)
		NLS_LANG="DUTCH_THE NETHERLANDS.WE8ISO8859P1"
		export NLS_LANG 
		con_string nl
	;;
	D)
		NLS_LANG="GERMAN_GERMANY.WE8ISO8859P1"
		export NLS_LANG 
		con_string d
	;;
	EL)
		NLS_LANG="GREEK_GREECE.EL8ISO8859P7"
		export NLS_LANG 
		con_string el
	;;
	HU)
		NLS_LANG="HUNGARIAN_HUNGARY.EE8ISO8859P2"
		export NLS_LANG 
		con_string hu
	;;
	I)
		NLS_LANG="ITALIAN_ITALY.WE8ISO8859P1"
		export NLS_LANG 
		con_string i
	;;
	PL)
		NLS_LANG="POLISH_POLAND.EE8ISO8859P2"
		export NLS_LANG 
		con_string pl
	;;
	TR)
		NLS_LANG="TURKISH_TURKEY.WE8ISO8859P9"
		export NLS_LANG 
		con_string tr
	;;
	IW)
		NLS_LANG="HEBREW_ISRAEL.IW8ISO8859P8"
		export NLS_LANG 
		con_string iw
	;;
	esac
done
$XXAS_LOG "Finished nls apply."

exit 0


