Localization

Note that this is not a complete solution to UHFPS localization. In fact, localization keys are primarily used here to retreive text from the localization asset. It is more accurate to refer to this as a pre-setup for localization rather than a complete localization system. However, integrating it with a third-party localization system should be straightforward.

You can always turn this system off or on by simply removing or adding the desired scripting symbol at the click of a button.

Enabling Game Localization

  1. Select the GameLocalization asset in the Scriptables folder.

  2. Click the Enable GLoc Localization button.

If you have localization enabled, you can use GString instead of the classic String to localize the string. On the other hand, if you choose not to use localization, you can still use GString, but this time it will behave like the classic String field.

Adding New Localization Strings

  1. Open or create a new GameLocalization asset. In the desired folder, right-click and select Create -> UHFPS -> Game Localization.

  2. Using the Localizations dropdown menu, you have the option to add new sections and add section keys.

  1. In order to utilize localized strings, use the GString instead of String in your scripts when creating a string field.

using UnityEngine;
using UHFPS.Runtime;

public class Example : MonoBehaviour
{
    public GString SomeText;
}
  1. To listen for localization or input changes, you need to subscribe to them. To accomplish this, simply write a subscribe method within the Start function.

using UnityEngine;
using UHFPS.Runtime;

public class Example : MonoBehaviour
{
    public GString SomeText;

    private void Start()
    {
        SomeText.SubscribeGloc();
    }
}

If you want to change a UI text when the text changes, for instance, you can achieve this by writing a custom action using the onUpdate parameter found within the SubscribeGloc() method.

using UnityEngine;
using UHFPS.Runtime;
using TMPro;

public class Example : MonoBehaviour
{
    public GString SomeText;
    public TMP_Text UIText;

    private void Start()
    {
        SomeText.SubscribeGloc(text => UIText.text = text);
    }
}

You can also subscribe to listen for input changes by utilizing the SubscribeGlocMany() method. However, this requires you to specify the input you want to listen to in the GameLocalization asset, using the "[action] Text" format.

The [action] selector will be converted to a <sprite=0> format, which is utilized for displaying icons within the text. You can modify the icons by using the Input Sprites Asset, which uses the TMP_Sprite Asset.

using UnityEngine;
using UHFPS.Runtime;
using TMPro;

public class Test : MonoBehaviour
{
    public GString SomeText;
    public TMP_Text UIText;

    private void Start()
    {
        SomeText.SubscribeGlocMany(text => UIText.text = text);
    }
}
  1. Finally, choose the localization key by clicking on the link icon located on the right side of the string field.

If you need to subscribe to listen for changes in an alternative manner, you can take look at the the static GameLocalizationE class, which contains all the necessary subscribe methods. This class can be found within the GameLocalization script.

Keep in mind that these methods are tied to GameLocalization. If you disable localization, these methods will cease to function.

As indicated in other guides, you can simply place an Asterisk (*) at the beginning of the localization string to disable the default behavior. Rather than retrieving text using a key, the key will serve as the actual text.

Third-Party Integration

As mentioned earlier, this doesn't provide a complete solution for localization. However, it's quite straightforward to integrate a third-party localization system with the existing system.

Within the GameLocalization script, there are two methods that utilizes localization, namely ObserveGloc() and ChangeLanguage(). To integrate with a third-party localization system, you'll need to write a bridge that links these two systems within the ObserveGloc() method. In this method, there's a subscription to an OnLanguageChange property, which is called when you subscribe to ObserveGloc() or when you change language using ChangeLanguage(). Thus, to integrate with a third-party system, you'll need to modify how you retrieve the text using a key. In the current system, the text is retrieved from a dictionary constructed from the GameLocalizationAsset.

Last updated