Mega Code Archive

 
Categories / Delphi / Examples
 

Getting the locale ID an application was made for

Title: Getting the locale ID an application was made for Question: When making multiple language applications it can often be useful, in code, to know what locale the application was made for.. This can be done by reading the \VarFileInfo\Translation block of the files resource data. Answer: Here is a function for getting the base language an application was made for. Make sure that "windows" is in your uses clause. --- type TLANGANDCODEPAGE = record wLanguage : word; wCodePage : word; end; function GetDefaultLCID(filename : string) : LCID; var InfoSize,puLen : DWord; Pt,InfoPtr : Pointer; LngBlk : TLANGANDCODEPAGE; begin result := $0400; InfoSize := GetFileVersionInfoSize(PChar(filename),puLen); if InfoSize 0 then begin GetMem(Pt,InfoSize); try fillchar(LngBlk,sizeof(TLANGANDCODEPAGE),0); GetFileVersionInfo(PChar(filename),0,InfoSize,Pt); VerQueryValue(Pt,'\VarFileInfo\Translation',InfoPtr,puLen); move(InfoPtr^,LngBlk,sizeof(TLANGANDCODEPAGE)); result := LngBlk.wLanguage; finally FreeMem(Pt); end; end; end; --- You can use the Languages object to get the name of the language.. Like: --- procedure TForm1.Button1Click(Sender: TObject); var lp0 : integer; BaseLng : LCID; begin BaseLng := GetDefaultLCID(Application.ExeName); for lp0 := 0 to Languages.count-1 do begin if (Languages.LocaleID[lp0] = BaseLng) then begin Label1.Caption := Languages.Name[lp0]; break; end; end; end; ---