How to Translate Your Game Using the Unity Translation Package

Welcome to the wild world of localization, where Veggie Gladiators are about to prove that vegetables aren’t just for salads, but for speaking multiple languages too! Picture this: your game is a hit in Tokyo, and suddenly the Veggie Gladiators have to fight in a sushi bar. Without localization, they’ll be lost in translation faster than a potato in a fruit salad. So, let’s arm our Veggie Gladiators with languages and take over the global gaming arena, one veggie at a time! By Ben MacKinnon.

Leave a rating/review
Download materials
Save for later
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Translating NPC Names

The other thing missing in the dialogue UI is translations of the NPC character names. Again, these keys and translations already exist in the table, so it’s just a matter of using them!

Open the DialogueLine script again, and import the Localization.Settings library again.

using UnityEngine.Localization.Settings;

Add a public accessor again called Speaker using the same method as before.

public string Speaker => LocalizationSettings.StringDatabase.GetLocalizedString(speaker);

Finally, open the DialogueManager script. Find the reference to the speaker in the ShowLine method, and change it to point to the new field Speaker.

speakerText.text = currentLine.Speaker;

Translating Questions

The final part you need to translate is the questions.

Select the Boss conversation, and you can see an example of a single-line dialogue that invokes a question from the player. Again, these are currently just stored as strings, but those strings are also stored as keys in the DialogueTable.

So far, when you’ve called LocalizationSettings.StringDatabase.GetLocalizedString you’ve just been passing a string, and that string happens to be a key in the table. But what that method is actually expecting is a TableEntryReference. TableEntryReference has an implicit operator that allows you to get the reference using only the string, assuming that string is the key.

If you want to be a bit more explicit, you should define a TableEntryReference to pass to the GetLocalizedString method.

Open the DialogueQuestion script. Add two imports to the top of the script this time.

using UnityEngine.Localization.Settings;  
using UnityEngine.Localization.Tables;

Now change the string question fields to TableEntryReference fields. Add two public string accessors that return the translated value for those references. The updated script should look like this:

using System;  
using UnityEngine.Localization.Settings;  
using UnityEngine.Localization.Tables;  

public class DialogueQuestion  
    public TableEntryReference firstOption;  
    public TableEntryReference secondOption;  
    public string FirstOption => LocalizationSettings.StringDatabase.GetLocalizedString(firstOption);  
    public string SecondOption => LocalizationSettings.StringDatabase.GetLocalizedString(secondOption);  

    public Conversation conversationWhenFirstOptionWasSelected;  
    public Conversation conversationWhenSecondOptionWasSelected;  

Finally, go back to the DialogueManager script once more and find the ShowQuestionUI method. Update it to use the new accessors.

firstOption.text = currentLine.dialogueQuestion.FirstOption;  
secondOption.text = currentLine.dialogueQuestion.SecondOption;

Save all the code and go back to Unity. Play the game one more time and see that every visible string is now translated!

Habla Español?

Now that you have one language supported, how about adding another? To add Spanish to the app, go all the way back to the start of the tutorial and start again…

Just kidding!

That’s the beauty of the Localization package, once you have one language support set up, it’s really simple to add further languages. You’ll need to repeat a few steps from the beginning of the tutorial, but not many.

First, open the Localization Settings again. Click Locale Generator and add Spanish (es) to the selected locales before clicking Generate Locales. Save the new locale into the same folder as before, RWLocalization.

Generate Spanish

Select the RWLocalizationGameDialogueTable. This is the one you set up to work with the Google Sheet, and fortunately, the sheet already has the Spanish translations available. In the Mapped Columns, add another Locale Column and select the Spanish (es) Locale. It should auto-assign the Column to D. If the column for the Spanish text doesn’t appear automatically in the DialogueTable, you may need to left-click in the Key row and select add missing table.

Add Spanish Locale to the Google Sheet Import

Click Pull to add the Spanish translation strings to the DialogueTable Table Collection.

For the Menu strings, you’ll need to manually add those strings to the UI Strings Table Collection. Open that file in the Table Editor, and add these Spanish translations to their relevant keys:

  • Title: Gladiadores vegetarianos.
  • NewGame: Nuevo juego.
  • Menu: Menú.
  • Choose Language: Elige lengua.

Finally, go back to the Title scene and add another button to the OptionsPanel so that the user can get the language to Spanish (es).

Add Spanish to OptionsPanel

And that’s it! You just added another language in a matter of moments. Well done.
Save everything and play through the game once more in Spanish.

Playing the game in Spanish

If you got stuck at any point with importing the translations, check out the final project inside the project materials folder, which can be downloaded using the button at the top or bottom of this tutorial.

Where to Go From Here?

You can download he project files using the link at the top or bottom of this tutorial.

In this tutorial, you learned how to use the Unity Localization package to translate all the strings in a game to two different languages. You learned about some of the different ways you can access translated strings through code and how to set the current locale of your game.

But the translation package isn’t limited to strings! It can also swap out assets, change fonts, or even change some serialized values in a scene depending on the selected locale.

To read more about these options, check out the Unity documentation.

And to find out what happens to our Veggie Gladiators, you’ll need to read the Unity Apprentice!


Ben MacKinnon

Author and Topics Master

Gijs Bannenberg

Tech Editor

Adriana Kutenko


Toby Flint

Final Pass Editor

Over 300 content creators. Join our team.