////////////////////////////////////////
// WCS - Warcraft:Source              //
// ---------------------------------- //
//  by kRypT0n!Te                     //
//      http://wcs.despo-clan.de      //
// ---------------------------------- //
// Content of this subscript          //
// - language management              //
////////////////////////////////////////
// script commands:
// wcs_getlanguage <var> <id>
////////////////////////////////////////

block load
{
  es_xexists wcs_exists command "wcs_getlanguage"
  es es_xif (server_var(wcs_exists) = "0") then es_xregcmd "wcs_getlanguage" "wcs/WCSlanguage/wcs_getlanguage" "Returns the given ID-text in the current language"
  // load the language DB
  es_xkeygroupload "WCSlanguage" "|wcs/WCSlanguage"
  // check the version
  es_xsetinfo wcs_lng_set "0"
  es_xexists wcs_exists variable "wcs_language"
  es es_xif (server_var(wcs_exists) = "0") then es_xsetinfo wcs_language "en"
  es es_xkeygetvalue wcs_lng_set "WCSlanguage" server_var(wcs_language) "wcs_lng_set"
  es es_xif (server_var(wcs_lng_set) = "1") then echo "[WCS] : Language set to" server_var(wcs_language)
  es es_xif (server_var(wcs_lng_set) = "0") then echo "[WCS] ERROR : Failed loading language" server_var(wcs_language)
  es es_xkeygetvalue wcs_tmp "WCSlanguage" server_var(wcs_language) "wcs_lng_rev"
  es es_xif (server_var(wcs_lng_ver) = server_var(wcs_tmp)) then echo "[WCS] : Language file is version" server_var(wcs_lng_ver)
  es es_xif (server_var(wcs_lng_ver) != server_var(wcs_tmp)) then echo "[WCS] ERROR : Loaded old language file !"
  // load often used stuff as a var
  wcs_getlanguage "wcs_lng_back" "wcs_lng_back"
  wcs_getlanguage "wcs_lng_next" "wcs_lng_next"
  wcs_getlanguage "wcs_lng_exit" "wcs_lng_exit"
  wcs_getlanguage "wcs_lng_page" "wcs_lng_page"
  wcs_getlanguage "wcs_lng_ulti_immunity_a" "wcs_lng_ulti_immunity_a"
  wcs_getlanguage "wcs_lng_ulti_immunity_v" "wcs_lng_ulti_immunity_v"
}

block unload
{
	es_xkeygroupdelete "WCSlanguage"
}

// this block is quick&dirty, so it doesn't waste CPU time
block wcs_getlanguage
{
es es_xif (server_var(wcs_debug) > 1) then profile begin "getlanguage"
	es_xsetinfo wcs_var "0"
	es_xsetinfo wcs_lid "0"
	es_xsetinfo wcs_lexists "0"
	es_xgetargv wcs_var "1"
	es_xgetargv wcs_lid "2"
	es es_xexists wcs_lexists key "WCSlanguage" server_var(wcs_language)
	es es_xif (server_var(wcs_var) != "0") then es_xif (server_var(wcs_lid) != "0") then es_xif (server_var(wcs_lexists) = "1") then es_xsetinfo wcs_lexists "2"
	es es_xif (server_var(wcs_lexists) = "2") do
	{
		es es_xsetinfo server_var(wcs_var) "0"
		es es_xkeygetvalue server_var(wcs_var) "WCSlanguage" server_var(wcs_language) server_var(wcs_lid)
	}
	es es_xif (server_var(wcs_var) = "0") then es_xsetinfo wcs_var "n/a"
es es_xif (server_var(wcs_debug) > 1) then profile end "getlanguage"
}