;Language change applet for Winbatch

IntControl(29, @TAB, 0, 0, 0)     ; standardize on tab delimters
;Change to WinBatch home dir to find WWWDLANG.* files
a=FileLocate("wwwdlang.enu")
if a==""
   Message("Could not locate WWWDLANG.ENU")
   exit
endif
DirChange(FilePath(a))

MyDialogFormat=`WWWDLGED,5.0`

MyDialogCaption=`WIL Language Selector`
MyDialogX=60
MyDialogY=79
MyDialogWidth=289
MyDialogHeight=146
MyDialogNumControls=6

MyDialog01=`2,66,278,56,ITEMBOX,Choice,DEFAULT`
MyDialog02=`20,22,270,DEFAULT,VARYTEXT,current,""`
MyDialog03=`54,126,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Ok",1`
MyDialog04=`148,126,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",0`
MyDialog05=`10,6,114,DEFAULT,STATICTEXT,DEFAULT,"Current Language is:"`
MyDialog06=`10,46,272,DEFAULT,STATICTEXT,DEFAULT,"Select desired language"`


;Determine current language

Current=inireadpvt("Main","Language","NONE","WWWBATCH.INI")
if Current=="NONE"
   current="English"
else
   if strlen(Current)!=3 then current="enu"
   current=IniReadPvt("Main","Description","Unknown",strcat(DirGet(),"WWWDLANG.",current))
endif   

LangFiles=strupper(FileItemize("WWWDLANG.*"))
a=ItemLocate("WWWDLANG.DLL",LangFiles,@TAB)
if a!=0 then LangFiles=ItemRemove(a,LangFiles,@TAB)
LangFiles=ItemSort(LangFiles,@TAB)

LangCount=ItemCount(LangFiles,@TAB)
if LangCount==0
   Message("Language","No WWWDLANG.* Language files found.  Using English")
   return
endif

LangList=""
for i=1 to LangCount
   lfile=ItemExtract(i,LangFiles,@TAB)
   Lang=IniReadPvt("Main","Description","NONE",strcat(DirGet(),lfile))
   if Lang=="NONE" then Lang=FileExtension (lfile)
   if i<LangCount then LangList=strcat(LangList,Lang,@tab)
   else LangList=strcat(LangList,Lang)
next 


:tryagain
choice=LangList
Dialog("MyDialog")
  
if Choice=="" then return
if ItemCount(Choice,@tab)>1 
   Display(4,"Language","You may only select one language")
   goto tryagain
endif

a=ItemLocate(choice,LangList,@tab)
lfile=ItemExtract(a,LangFiles,@TAB)
ext=FileExtension(lfile)

if ext=="ENU"
   IniDeletePvt("Main","Language","WWWBATCH.INI")
   Message("English chosen as langauge","DLL Will use internal strings instead of language file")
else
   IniWritePvt("Main","Language",ext,"WWWBATCH.INI")
   Message("Language","Language set to %Choice%")
endif

IntControl(26,0,0,0,0)   ;Tell DLL to reset language strings

return



