No announcement yet.

Displaying Localized Text

This is a sticky topic.
  • Filter
  • Time
  • Show
Clear All
new posts

    Displaying Localized Text

    Before proceeding, please be sure to read this UDN topic: Localized Text in the Unreal Engine

    1. Place a CLIK label in your HUD or menu, with the instance name of: myTextField

    2. Next, add the variable which will contain the localized text you want displayed as well as the GFx CLIK widget variable at the top of your HUD or menu UnrealScript class:

    var GFxClikWidget MyTextField;
    var localized string MyLocalizedString;
    3. Now, we'll set the text field to display the contents of 'MyString' on initialization:

    event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
    	case ('myTextField'):
    	    MyTextField = GFxClikWidget(Widget);
    	    MyTextField.SetString("text", MyLocalizedString);
        return true;
    4. Then, as usual, we'll bind the CLIK widget in the default properties:

    5. Next, we need to figure out which Script package contains our HUD or menu script file. In my case, my HUD script is GFxMiniMapHud.uc and it is contained in the UTGame.u compiled Script.

    So I'll go to this directory: C:\UDK\UDK-2010-11\UDKGame\Localization\INT\
    and open the file: in a text editor. This is the international (English) localized ini file that matches the UTGame.u script package. Obviously, if your HUD or menu class is located in a different script package, you'll want to open or create an INT file for it instead.

    6. At the bottom of this file, I'll add the HUD's class name as a section, then add the variable 'MyLocalizedString' as the key, and the text I want it to display as the value. Be sure to replace 'GFxMinimapHud' with the name of your actual HUD or menu class:

    MyLocalizedString="This is a localized string."
    That's all there is to it! Just do a Make/Build of your game, then run the game. You should see the sentence: "This is a localized string." on the screen where you placed the CLIK label.

    Alternatively, you can call the Localization function like this:

    var string MyString;
    MyString = Localize("GFxMinimapHud", "MyLocalizedString", "utgame");
    • Replace "GFxMinimapHud" with the heading name in your INT file.
    • Replace "MyLocalizedString" with the key name.
    • Replace "utgame" with your localization filename minus the file extension.

    Or, you could use this line of code as well:

    class'GFxObject'.static.TranslateString( "<Strings:NameOfLocalizedFile.LocalizedHeader.LocalizedVar>" );
    You could use a standard Flash textfield for this as well, instead of a CLIK label. In that case, the script setup will be slightly different:

    var GFxObject MyTextField;
    var localized string MyString;
    MyTextField = GetVariableObject("_root.myTextField");

    Using Config Files

    You can also use an INI file in the Config directory to store text to be displayed; however, it will not be localized. That procedure follows:

    You must specifiy the name of the INI file to be used in your class by adding: config(nameofini) to the class declaration. Like so:

    class MyClass extends GFxMoviePlayer
    Also be sure the variable in the class file is listed like so:
    var config string MyString;
    Your INI file would have something along these lines in it:

    +MyString="This is a non-localized string."

    Thank you for the info, very helpful.