Switch images from image objects to match country or language

Page update date :
Page creation date :

Verification environment

Windows
  • 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.

Prerequisite knowledge

About half of the content in this tip is the same as the previous one below, so I'll only give you a few simple steps for the duplicates. For detailed instructions, see the following tips:

Preparation of materials

This time, we will switch images, so we will prepare an image file. In this tip, we will use three locales, "Japanese (ja)", "English (en)", and "Spanish (es)", so we will use the flag images related to them as examples.

Japanese (ja) English (en) Spanish (es)

Keep these in the Scenes folder.

Material source

Installing the Localization Package

If you have not already installed the Localization package, install it. This procedure is similar to the previous one.

Creating a Localization

This is also the same as last time, so I will post only the image.

Here, we create a "Localization" folder in the "Scenes" folder and create it in it.

Creating a Locale

This is also the same as last time, so I will omit the detailed procedure. The locales to add are "Japanese (ja)", "English (en)", and "Spanish (es)".

I specified the "Localization" folder mentioned earlier.

Leave the default locale as "Japanese (ja)".

Registering Images

From here, it will be the image settings. Images will be registered according to each locale. There are several ways to create it, but in this case, you can create a GameObject from scratch.

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 image, select "Asset Table Collection" for "Type". Except for text, you will basically select this. Specify the table name because the values for each locale are maintained as a table list. ImageTable 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 an "ImageTable" 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 create a record. 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. Set the flag of each country for each locale. I think it's easier to drop the image from the project. Leave the NationalFlag key as .

Since it is a table format, you can register multiple items, but this time I will leave only one. Please close the dialog after entering. You can dock it somewhere.

Localization settings for image objects

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

First, place the raw image object. It is also possible with objects that deal with other images, but requires a little additional step. Raw images are easy to set up.

Images don't change the size of objects, so you need to preset them so that at least the aspect ratios are the same.

From the Raw Image component's three-point menu, choose Localize.

A new Localize Texture Event component will be added. Since Localize Asset Reference is not selected, click None (Texture).

When the dialog appears, enter the key of the Localization asset to be set in the input field above. NationalFlag In this case, type and double-click from NationalFlag the list below.

If you expand the Localize Asset Reference, you can 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 image 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, the locale switch is displayed so that you can change the locale of the game. Try selecting Spanish for a while.

Then, you can confirm that the content of the image 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 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. You can see that the image is properly switched according to the environment.