Accessibility is an important topic in gaming, from friendlier control schemes to subtitles and color blindness settings. But as developers add these settings, too many games forget to support multiple languages, especially in the mobile games scene. With the Unity Localization package and a simple Google Spreadsheet, you can start supporting multiple languages in your game without spending a fortune on your development budget!
In this tutorial, you will learn about the Unity Localization package and how you can use it to set up translations not only of UI and other text but also of runtime assets. You can read about different ways to import local strings from professional platforms in XLIFF format before trying the free method for yourself with a Google Sheet integration.
You can use a project from our Unity Apprentice book for this tutorial. Download the sample project using the link above or below this tutorial. Open the startup project and then the title Scene of Properties ▸ RW ▸ Views. Click on the play button in the Unity editor to see the Veggie Gladiators drop-down menu.
Click New Game to the dining room, where you control a Potato Warrior. Walk around the scene with the WASD. Go to any NPC and start a conversation by pressing space bar.
Some of the conversations have multiple lines of dialogue that require user input, so take the time to walk around and discover all the interesting dialogue. Once you’ve learned everything you can from your fellow greens, out of play mode.
Now, your task is to add some additional language support to this project.
Your First Translation
First, you need to add the Unity Localization package to the project.
Installing the Localization Package
This can be done by opening the Package Manager by choice window ▸ Package Manager. ensuring Packages: Unity Registry selected, then scroll down the list to find the Localization package. Select it and click Install to add the latest package version to the project.
Once the package has been imported, you need to set up the Localization Settings Asset. Unity stores these settings as a serialized asset, so any changes to your localization settings can be monitored by source control.
First, create a new folder under the RW folder and name it Localization.
Then, open the Project Settings from Edit menu, and select Localization in the list. Click make and save the new Localization Settings file in the Localization folder you just created.
You will see that the Project Settings Localization window will update to show more options for localization. Selecting a new file in the Project window will also make these options visible in the Inspector window.
Before we dive into these options, you need to set up your areas first.
Click on the Local Generator button to open a new window. In the Locale Generator window, select englishwhich is the current and default language of the project, and german (de). Then click Create Locals.
Save the new properties in the same Localization folder as before.
However, German words are usually longer than in other languages. Therefore, German translations can be a good way to check if your app’s UI is flexible enough to handle any translation.
With the new Locale files created for English and German, you should select the default locale for the project. on Localization Settings window again, add the english local to both of Specific Locale Selector and Project Locale Identifier options.
With that, you’re ready to add your first translation!
The Title menu currently only has two pieces of text that can be translated. The title and the New Game button.
Both of these use a TextMeshPro text translation component. The Localization Pack is built to work directly with the TextMeshPro and Legacy Text components, since these are the most likely things you need to localize.
Select the Canvas ▸ Panel ▸ title hierarchy text. Then, from the Component Menu of the TextMeshPro component, the kebab menu button, click Localize.
This will add a new component to the title GameObject, the LocalizeStringEvent. This is the main component driving the localization of your project. When it is added via the TextMeshPro menu, it automatically provides a callback to it UpdateString method to update the text value of the TextMeshPro component.
However, there is one last thing to do before you start interpreting the values of these text components. You will notice that the two dropdowns for String reference and Table collection no values can be selected. That’s because you first need to create a collection to use!
Click Create Table Collection to open the Localization Tables window Name this new table UI Strings and save it in a new folder in the RW ▸ Localization ▸ Menu.
You’ll notice that it automatically selects the locales you set up earlier. The table will be populated with one column for each locale supported by the app.
With the table now set up, keep the Localization Tables window open and navigate back to title text. You can choose the UI Strings table from Table collection dropdown. Once you have, the button below will change to Add Table Entries.
Click Add Table Entries. The component will change visually once again, enabling you to enter a Entry Name and a value for each locale. Fill in the new fields with the following values:
- Entry Name: Title
- english: Veggie Gladiators
- German: Gemüse Gladiatoren
Once you’ve updated the values here, you’ll see that they’ve been updated in the table as well.
Now, you’ve set up your first rendered string of Veggie Gladiators! Click play in the Unity Editor, and you’ll see that a new dropdown appears in the game window. This allows you to change the loaded locale at any point.
Nice! But now you have to make a way for athlete to choose which language appears in the game.