Get current user language

Hi. In my game i have multiplayer chat and i want to show user icon of his current language. For exmple, in the begining he writes on Engilsh and there is ‘en’ icon, after that he switch his language to another(German) and icon changes to ‘gr’. Is it possible to get current language of the user? I can’t use FInternationalization because this isnt a localization thing.

Where are you looking to release your game. The language used in a game is usually taken from the Platform (Steam, Xbox, PS4) as users can change their languages in their own settings.

So you will probably need to look at getting the current language used from the platforms you are looking to release, in order to then choose what to show (EN, GR ect)

UE4 provides API wrapper for platform API, you can find ton of static functions here:

Just remember that those are references to rollback generic implementation, you need to use FPlatfrom* insted of FGenericPlatfrom*

Here some function you might be interested:

Also remember that those will work only if platform you running in provide such information.

It’s windows now, but it’s may be Linux or Mac.
I need something like windows language panel, but inside of the game, just thought that there is built in functions for that in UE4.

Nope, this returns default language/locale, i need to get the current. Like now it’s english, I press shift+alt and get русский. I need windows language panel analog but in game.

Oh so what you looking for is not platfrom language but keyboard layout language that is different thing. Sadly i dig up and Slate which should handle those things don’t have API for that, primerly because it not really needed for the game, insted Slate simply handles character and states that input system gives and don’t care where they came from. So yeah you will need to use system APIs of platform directly as Dune suggest.

If it’s login page, it is better to know what keyboard layout is. Thanks for your help.

There is function for that, i guess, but it’s not implemented

int FCulture::FICUCultureImplementation::GetKeyboardLayoutId() const
{
	return 0;
}

Small snippet code for winows

First

#if PLATFORM_WINDOWS
#include "AllowWindowsPlatformTypes.h"
#endif

Second

FString ShortLayoutName = "";

#if PLATFORM_WINDOWS
	HKL kstate = GetKeyboardLayout(0);
	TCHAR szCodePage[10];
	if (GetLocaleInfo(LOWORD(kstate), LOCALE_SISO639LANGNAME, szCodePage, sizeof(szCodePage)))
	{
		ShortLayoutName = szCodePage;	
	}
#endif

In ShortLayoutName will be your current keyboard layout name.

1 Like