askvity

How Do I Use Localization in Unity?

Published in Unity Localization 4 mins read

To use localization in Unity, you typically employ the official Localization package, which allows you to manage translated text, audio, textures, and other assets for different languages or regions. A common way to start localizing UI text is directly from the Text component in your scene.

Using localization in Unity involves setting up the Localization package, creating String Tables to store your translated text, and then linking components in your scene (like Text elements) to these localized strings.

Localizing a Text Component Directly

One straightforward method to begin localizing text in your UI is by using the built-in context menu option:

  1. In your Unity scene, select a GameObject that has a Text component (like a TextMeshPro Text component).
  2. Right-click the Text component in the Inspector window.
  3. From the context menu that appears, select the Localize option.

Upon selecting "Localize":

  • Unity automatically adds a Localize String component to the GameObject. This component is responsible for displaying the correct translated string based on the currently selected locale.
  • Unity automatically configures the Localize String component for the GameObject it is attached to.
  • If the Text component contains a string value that is also already present in a String Table, then Unity automatically assigns this existing translation entry to the Localize String component during the setup process. This streamlines the connection between your UI element and your localization data.

This action essentially replaces the static text in the Text component with a dynamic link to your localization data.

The Unity Localization Package

The core of Unity's localization system is the Localization package, available through the Package Manager.

Here are key aspects of using the Localization package:

  • Installation: Install the package via Window > Package Manager, search for "Localization", and install it.
  • Localization Settings: Access the central settings via Edit > Project Settings > Localization. This is where you define supported locales (languages), manage Addressables, and configure other localization preferences.
  • String Tables: Create and manage String Tables within the Localization Settings. String Tables store your text entries, each associated with a unique Key and translations for each supported locale. For example:
Key English Spanish French
title Game Title Título del Juego Titre du Jeu
welcome Welcome! ¡Bienvenido! Bienvenue !
  • Asset Tables: Similar to String Tables, Asset Tables store references to localized assets like textures, audio clips, or Prefabs.
  • Localize Components: The Localize String component added by right-clicking the Text component is one type of Localize component. There are others, such as Localize Texture, Localize Audio Clip, etc., which you can add manually or through similar context menus (where available) to link various assets to your localization data.

Workflow Summary

Here's a simplified workflow for localizing text using the Unity Localization package:

  1. Install the Localization package.
  2. Go to Project Settings > Localization and add the locales (languages) you want to support.
  3. Create a String Table Collection.
  4. Manually add Keys and translations for each string you need to localize in the String Table.
  5. In your scene, select the GameObject with the Text component.
  6. Right-click the Text component and select Localize.
  7. Verify that the automatically added Localize String component is linked to the correct String Table and Key. If the text was already in a table, it should link automatically. If not, you might need to manually select the String Table and Key.
  8. Test by changing the selected locale in the Editor's Localization settings or via script during runtime.

This process enables your application to switch between different languages dynamically, providing a tailored experience for users worldwide.

Related Articles