Can't figure out blueprints and localisation

Hi, I’m trying to get the language used by the Operating System (e.g what language Windows is in) for my game, so it can detect it and automatically change to the appropriate language. I can’t figure out how to do C++ programming for the life of me - and I cannot find anything even slightly related to what I’m trying to do. At the moment I have:

.h file

	UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Current Language"), Category = "Locale")
		static FCultureRef getLocalisation();

and in the .cpp

FText ULocaleChanger::getLocalisation()
{
	return FInternationalization::Get().GetCurrentCulture();
}

I’m really not sure what I’m doing wrong - or what I’m really doing at all to be honest - I tried using FText but it kicked out tonnes of errors and this code only brings up one error complaining about how I’m using FCultureRef.

4.17 (maybe 4.16) adds BP support for managing the language and locale of your game, so take a look at UKismetInternationalizationLibraryif you want an example of how your 4.15 version could work.

https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Engine/Classes/Kismet/KismetInternationalizationLibrary.h

https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Engine/Private/KismetInternationalizationLibrary.cpp

(You need to be logged in with a GitHub account linked to your Unreal Engine account for those links to work)

I’m trying to get the language used by the Operating System (e.g what language Windows is in) for my game, so it can detect it and automatically change to the appropriate language

UE4 will do this for you out-of-the-box.

Im currently testing with French set as my language and it didn’t automatically change - and the new internationalisation options seem to have completely broken my localisation - as I can’t even use my old code to change to french anymore.

I updated to 4.17, Im going to try adding said code into 4.15 and see if that works.

Actually just found out that the translations have now completely broke across the board on both 4.15 and 4.17.

Im currently testing with French set as my language

How did you change your language, and which Windows version are you on?

You can always test French by passing -culture=fr on the command line when starting your application.

Actually just found out that the translations have now completely broke across the board on both 4.15 and 4.17

Assuming you’ve edited your translations via a PO file, you may find you need to re-gather, re-import, and re-compile after upgrading to 4.17 (some of the internal keying has changed, but the external PO keying hasn’t so can preserve the data for you).

The same would be true of trying to take localisation data gathered in 4.17 and using it in 4.15, and is why you should always translate via the PO files rather than hand edit our archives.

I literally tested by setting French to my native language on my Windows 10 computer, and I made sure that it said my default culture was fr-FR.

I never used a PO file or anything of the sort - always used the localisation dashboard. However - after exporting the PO file from 4.15 and trying to import it in 4.17, I get an error now (after re-gathering the text it deleted all of the translations). [2017.10.08-21.55.07:024][ 0]LogShaderCompilers: Display: Using Local Shader Co - Pastebin.com

Ah, that. There was a change to the way that empty arrays were imported in properties that
inadvertently affected localisation targets in the dashboard.

You’ll want to double check any array properties in the Localisation Dashboard as you’ll find they have extra empty entries at the end, and you should delete those entries. In particular there will be an array of extra modules to import, and it’s the empty entry in that one that is causing the import error.

I chose to go for long winded copy and pasting translations in to make sure I did it just how I put it into UE 4.15 originally, as I couldn’t find any empty arrays, entries or anything of the sort.

Still though - the game doesn’t change language. I binded a key set to “G” to swap between French and English, and whilst the game does lag and appear to change, nothing changes at all.

What kind of build are you testing with. Is it Play in Editor (PIE), running the editor with -game, or a cooked/packaged build?

Game localisation isn’t available in PIE, but 4.18 does add a preview option for localisation that works with PIE/UMG/etc.

I was using PIE and it indeed wasn’t working, after switching to Standalone game it’s all up and running perfectly now.

I am unfortunately having some trouble now with TextRenders though - the text isn’t changing language despite everything else in the game changing…

By that do you mean that text render actors don’t update when changing the culture, or that they’re not localised at all?

They don’t update when changing the culture, even destroying them and then re spawning them does nothing - it just stays in the Native Language. I know it’s been localised in the dashboard as when changing the “Is localizable” from yes to no, and back again - it re appears in the localisation dashboard as if it was never in their to start with.

Nevermind, I figured out the problem about the TextRenders not changing language, it was a stupid error where I forgot that ‘append’ can’t be localised, whereas format text can be so I have moved to them.

On a serious problem for me though - when localising you can using ‘TAB’ spacing or new lines in the localisation - this is a huge problem for me as a use ‘TAB’ spacing in my controls menu, and I need new lines for my key prompts.

They should be updated by FTextRenderComponentCultureChangedFixUp which binds onto the OnTextRevisionChangedEvent event to dirty their render state so they refresh to show the new text.

Can you confirm that FTextRenderComponentCultureChangedFixUp::FImpl::HandleLocalizedTextChanged code is being run when the culture is changed? It’s in TextRenderComponent.cpp in Engine\Source\Runtime\Engine\Private\Components.

Although the fact that re-spawning them doesn’t update the text would suggest another issue. How is the text set on these components?

The translation editor (which is separate to the localisation dashboard, but linked from it) is quite an old tool. It was written before multi-line editable text was a thing, and hasn’t been touched in some time.

It would be better to edit your translations via PO files, and you can always use something like PO edit if you want a tool to help with that. There aren’t restrictions on whitespace or new-lines in localised text, it’s just that our translation editor is too old to handle such things.

Whilst it seemed to initially work - it didn’t, it just doesn’t display the second line anymore.

Are you using a PO? If so, how are you adding the new-lines? You have to use \n in the string in the PO file rather than add a new-line in the file.

Anything new on this? Still isn’t working for me.

I’m using \r\n which was what POEdit said was already in use for English.

When in English translation, the TextRender I’m using shows both the lines - however upon changing to any other language, the second line of the TextRender doesn’t appear.