Mega Code Archive

 
Categories / Delphi / Strings
 

How to convert a locale ID (LCID) into a ISO 3166639 string value

Title: How to convert a locale ID (LCID) into a ISO 3166/639 string value Question: Ever wondered how Delphi gets a correct LCID from the strings in the XML file exported from the Translation Repository? This information will help you if you are about to write an XML editor to translate strings exported from the translation repository Here comes some code for converting an LCID into a string that can be put in the Borlands translation string XML files 'BASE-LOCALE' and 'TARGET-LOCALE' element text. Answer: I was about to write an XML editor that could edit the XML files exported from the Translation Repository in Delphi 5 Ent. I found out that Borland uses the ISO 3166 and ISO 639 string for the language to identify languages. XML example: US en DE de FR fr 1.0 1999.12.6 Borland Integrated Translation Environment " Completed" " Durchgefhrt" " Termin" How can I convert the "US en", "DE de", "FR fr" and so on to a LCID that can be used with the TLanguages object in Delphi? Below is some code for doing such a thing: function GetISO639FromLCID(LCID : integer) : string; var Lang : PChar; Ctry : PChar; begin result := ''; Lang := StrAlloc(255); Ctry := StrAlloc(255); try fillchar(Lang^,255,0); fillchar(Ctry^,255,0); GetLocaleInfo(LCID,LOCALE_SISO639LANGNAME,Lang,255); GetLocaleInfo(LCID,LOCALE_SISO3166CTRYNAME,Ctry,255); result := Ctry + #32 + Lang; finally StrDispose(Lang); StrDispose(Ctry); end; end; function GetLCIDFromISO639(Str : string) : integer; var lp0 : integer; begin result := 0; for lp0 := 0 to Languages.Count-1 do begin if (GetISO639FromLCID(Languages.LocaleID[lp0]) = Str) then begin result := Languages.LocaleID[lp0]; break; end; end; end; if anyone has a better solution for "GetLCIDFromISO639", please drop a comment.. I will continue to update this article with more stuff that is needed to write an XML editor for files from the Borland Translation Repository