Reputation: 7390
I need to extract the user's Windows language, and i'm using the function below. However i tested in my current machine (it's op english), but the function return is "Portuguese (Brazil)".
Actually my machine was in this language originally, but after i installed a new language pack and it's now in English, not Portuguese ; so i assume the function below is not working properly. Is there another alternative ?
Thanks
function GetWindowsLanguage: string;
var
WinLanguage: array [0..50] of char;
begin
VerLanguageName(GetSystemDefaultLangID, WinLanguage, 50);
Result := StrPas(WinLanguage);
end;
Upvotes: 1
Views: 1425
Reputation: 8331
In order to get the information about which language is being used for Windows UI by current user you should use GetUserDefaultUILanguage function instead of GetSystemDefaultLangID
If the current user has not set any language then System Default UI Language is returned.
For Delphi 2007, you'll need to declare the function, as it didn't exist at the time that version was released. Note that doing so statically as shown here will mean your app will no longer run on versions of Windows prior to Windows 2000.
function GetUserDefaultUILanguage: LANGID; stdcall; external 'kernel32';
function GetUsersWindowsLanguage: string;
var
WinLanguage: array [0..50] of char;
begin
VerLanguageName(GetUserDefaultUILanguage, WinLanguage, 50);
Result := WinLanguage;
end;
Upvotes: 6
Reputation: 125661
You want GetUserDefaultLangID instead. If your machine was set for Portugese when Windows was installed, that is the default language for your system. The user's currently selected language is the one chosen by the logged in user. (See the Remarks on the linked page.)
function GetUsersWindowsLanguage: string;
var
WinLanguage: array [0..50] of char;
begin
VerLanguageName(GetUserDefaultLangID, WinLanguage, 50);
Result := StrPas(WinLanguage);
end;
Upvotes: 3