Switching the text of a text object to match the environment in which the text is multilingually supported

Page update date :
Page creation date :

Verification environment

  • Windows 11
Unity Editor
  • 2021.3.12f1
Input System (Unity Technologies)
  • 1.4.3
Localization (Unity Technologies)
  • 1.3.2

Prerequisites for this tip

The following settings have been made in advance as a premise for the description of this tip.

About localization

In many cases, games are created in the language of the environment in which they are developed, or in English. However, in order for more people to play games, it is necessary to create games according to the culture and language of the country. This is commonly referred to as "localization."

In this tip, I would like to do "multilingual support", which is one of the localizations. There are many ways to do multilingual support in Unity, but in this case we'd like to use Unity's official extension package, Localization, to support multiple languages.

Installing the Localization Package

To support localization, you must first install the "Localization" package.

From the menu, select Window - > Package Manager.

In the top left corner of the package manager that appears, select Unity Registry.

"Localization" will be displayed in the menu on the left, so select it and click the Install button. It will take some time to install. Once installed, close the dialog.

Creating a Localization

After installing the package, create the text for each language. Select Edit - > Project Settings from the menu.

Select Localization from the menu on the left and click the Create button.

The file will be created, so specify any folder. Multiple files will be generated, so it is better to create them in a dedicated folder. Here, we create a "Localization" folder in the "Scenes" folder and create it in it.

When created, the screen will look like this.

The file is also created in the specified folder. At this point there is still one.

Creating a Locale

We will create the text corresponding to the language. Open the project settings Localization and click the Locale Generator button.

Select the corresponding locale. Choose only what you need. The more you check, the wider the game can be deployed, but the amount of work will increase proportionally.

This time, "Japanese (ja)", "English (en)", and "Spanish (es)" are selected.

After setting, click the "Generate Locales" button at the bottom right to create it.

Specifies the folder in which to create the file. It can be a different place, but it is easier to manage if it is organized, so specify the "Localization" folder created earlier.

Avaliable Locales is added to the number of locales you select.

Files are also created in the specified folder for as many locales as you select.

Next, configure Locale Selectors. This is a setting for what information determines the locale when the game is launched. If there are no special decision conditions, you can leave it as it is. I want the default locale to be Japanese when the locale is not determined by trying. From the third Specific Localse Selector, click the circle button on the right.

Select Japanese (ja).

Similarly, the Project Locale Identifier should be "Japanese (ja)".

Creating Texts

Create text for each locale. There are several ways to create it, but here we will create it by setting the text from scratch with a GameObject.

From the menu, select Window > Asset Management - > Localization Tables.

Click New Table Collection.

Make sure that all the locales you created are checked.

Since this time we are localizing the text, select "String Table Collection" for "Type". Specify the table name because the text for each locale is maintained as a table list. TextTable In this example, it is used.

After entering, click the "Create" button.

Select a destination. Since multiple files are generated for each table, it is preferable to create a dedicated folder. Here, we create a "TextTable" folder in the "Localization" folder and specify it.

Once created, the table will appear. It's 0 lines because I haven't created anything yet.

Files are also created for folders as many locales. Basically, I don't touch this directly.

Let's try to create one. There is an "Add New Entry" button in the table, so click it.

This will add one line and display an input field for each locale. Try translating the word "hello" into each language and typing "Hello", "Hello", and "Hola" respectively. The key is Hello . By the way, if you enter it, it will be saved automatically.

Add one more line so you know you can manage more than one. Based on the words "thank you", the key ThankYouis to type each word "thank you", "thank you", and "gracias".

Please close the dialog after entering. You can dock it somewhere.

Localization settings for text objects

In this case, let's make the display text switch to the UI text object according to the locale set in the game.

First, place the text object arbitrarily. I don't use it this time, but TextMeshPro I can handle it.

After selecting the placed object, choose Localize from the Text component's three-point menu.

This adds a new Localize String Event component.

Since String Reference is not selected, click None.

When the dialog is displayed, enter the text key to be set in the input field above. Hello In this case, type and double-click from Hello the list below.

You can expand the String Reference to see that the various values are set. That's all there is to it.

Run and verify

Once you're done, try running the game. The text should change when you run the game. In the figure below, it is displayed in Japanese because it is running in a Japanese environment.

In the upper right corner of the game screen on the editor, you can change the language of the game. Try selecting Spanish for a while.

Then, you can confirm that the content of the text switches automatically.

As you can see, Unity's official localizetion package makes it easy to apply and switch to the UI and see how it works.

Try setting another text and see if the text changes.

Try running in another language environment

Build and output the program to see if it appears in the corresponding language when run in another language environment.

The following diagram shows the results of installing English additionally for the Windows 11 Japanese OS and running it in an environment with English as the default language. I think you can make sure that the language is switched according to the environment.