4

Some Windows computers have multiple display languages installed.

I can get the current user's UI language in that language using the function:

function GetUsersWindowsLanguage: string;
var
  WinLanguage: array [0..50] of char;
begin
  VerLanguageName(GetUserDefaultUILanguage, WinLanguage, 50);
  Result := WinLanguage;
end;

This function outputs something like this:

Espagnol (Espagne)

The output is not in English. All I need is "Spanish". Is there any way to get the display language in English?

I'm using Delphi 10.3.3 (VCL application).

Xel Naga
  • 826
  • 11
  • 28
  • 1
    Could be impossible if the system doesn't have English at all. Why not going with the ID that `GetUserDefaultUILanguage()` gives you? "Spanish (Spain)" would equal `$0c0a` (or more generic `$0A`) as per https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f – AmigoJack Jun 05 '20 at 20:09
  • @AmigoJack Apparently LOCALE_SENGLISHDISPLAYNAME provides in English. Problem solved. – Xel Naga Jun 05 '20 at 20:50

1 Answers1

7
function GetUsersWindowsLanguage: string;
var
  WinLanguage: array [0..50] of char;
begin
  GetLocaleInfoW(GetUserDefaultUILanguage, LOCALE_SENGLISHDISPLAYNAME, WinLanguage, 50);
  Result := WinLanguage;
end;
Peter
  • 86
  • 1