3

On input I have a language ID. On output I do expect full localized name of the language.

I use GetLocaleInfo(..., LOCALE_SLANGUAGE, ... ) to populate the string. Everyting worked fine until I received 0 on input and GetLocaleInfo filled the string with user default language instead of indicating neutral language (expected). To my knowledge, no special LOCALE_XXX_DEFAULT constants equals to 0.

Here is a testcase:

procedure TForm1.FormCreate(Sender: TObject);
var
  wIDLanguage: WORD;
  lpLCData: string;
  cchData: Integer;
begin
  wIDLanguage := 0;
  Assert(wIDLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));

  cchData := GetLocaleInfo(MAKELCID(wIDLanguage, SORT_DEFAULT), LOCALE_SLANGUAGE, nil, 0);
  Win32Check(cchData <> 0);
  //Win32Check(GetLastError = ERROR_INSUFFICIENT_BUFFER);
  SetLength(lpLCData, cchData);
  Win32Check(GetLocaleInfo(MAKELCID(wIDLanguage, SORT_DEFAULT), LOCALE_SLANGUAGE, PChar(lpLCData), Length(lpLCData)) <> 0);
  SetLength(lpLCData, Length(lpLCData) - 1);

  Caption := '"' + lpLCData + '"';
end;
  • What am I doing wrong here?
  • How to retrieve language name properly?
OnTheFly
  • 2,059
  • 5
  • 26
  • 61

0 Answers0