Master Unity Localization

Find Saas Video Reviews — it's free
Saas Video Reviews
Makeup
Personal Care

Master Unity Localization

Table of Contents

  1. Introduction
  2. Installing the Localization Package
  3. Setting up the Localization Settings
  4. Creating String Table Collection
  5. Changing the Text
  6. Changing Languages in the Game
  7. Creating Locale Selector Script
  8. Adding Buttons to Change Languages
  9. Saving and Loading Locales
  10. Changing Sprites
  11. Using Localization in the Build
  12. Conclusion

Introduction

In this tutorial, we will learn how to add support for multiple languages in your game. This will include changing text and sprites. We will be using the Localization package in Unity to achieve this. By the end of this tutorial, you will have a better understanding of how to localize your game for different languages and regions effectively.

Installing the Localization Package

Before we start localizing our game, we need to install the Localization package. To do this, follow these steps:

  1. Make sure you have Unity version 2021.2 or higher.
  2. Go to the Package Manager.
  3. Select "Unity Registry" and search for the Localization package.
  4. Install the package.

Setting up the Localization Settings

Once the Localization package is installed, we need to set up the Localization settings. Follow these steps:

  1. Go to the Project Settings.
  2. Select Localization.
  3. If you don't have any Localization settings, create a new folder to keep the project organized.
  4. Choose the languages you need. Unity syntax for language is "Locale".
  5. Generate locales.
  6. Choose a default language. Set the "Project Locale Identifier" to the default language.

Creating String Table Collection

Now let's create a String Table Collection to control the text for different languages.

  1. Go to "Window, Asset Management, Localization tables".
  2. Select "New Table Collection".
  3. Choose "String Table Collection" as we want to control text.
  4. Create a key, which will hold a reference to the text for different languages.
  5. Add the text for each language.
  6. Make sure the preloading options are selected.

Changing the Text

To change the text for different languages, follow these steps:

  1. Add the "Localize String Event" component to the TextMeshPro text.
  2. Choose the table and key that we created earlier.
  3. Update the TextMeshPro text using the "Update String Event" component.

Changing Languages in the Game

To allow players to change languages in the game, we need to create a Locale Selector script.

  1. Include the Localization Settings namespace in the script.
  2. Create a function named "SetLocale" that takes an int parameter "localeID".
  3. In the function, select the locale from available locales based on the "localeID".
  4. Create a public void function for buttons that starts the "SetLocale" coroutine.
  5. Pass the "localeID" to the function.

Adding Buttons to Change Languages

To add buttons that allow players to change languages, follow these steps:

  1. Create an empty game object called "Localization Manager" in Unity.
  2. Add the Locale Selector script to the Localization Manager object.
  3. Select the button and add the "OnClick" event.
  4. Drag the Localization Manager object to the event.
  5. Choose the Locale Selector script and the "Change Locale" function.
  6. Pass the ID of the language to the function for each button.

Saving and Loading Locales

To remember the language chosen by the player, we can save and load the locale using PlayerPrefs.

  1. Save the "localeID" number when the player chooses a language.
  2. In the Start function, call the "SetLocale" function with the saved "localeID" number.

Changing Sprites

To change sprites for different languages, follow these steps:

  1. Create a UI Image and position it accordingly.
  2. Add the "Localize Sprite Event" component to the image.
  3. Create an Asset Table Collection to control the sprites for each language.
  4. Add the table entry and select the sprites for each language.
  5. Use the "Update Asset" event to update the sprite of the image.

Using Localization in the Build

To use Localization in the build of your game, follow these steps:

  1. Go to "Window, Asset Management, Addressables, and select Groups".
  2. Click on the Build button to create a new build or update an existing build.
  3. If there are any errors, use the Analyze window to fix them.

Conclusion

In this tutorial, we have learned the fundamentals of the Localization package in Unity. We have learned how to install the package, set up Localization settings, change text and sprites for different languages, and allow players to change languages in the game. By implementing these techniques, you can provide a localized gaming experience to players worldwide.

Are you spending too much time on makeup and daily care?

Saas Video Reviews
1M+
Makeup
5M+
Personal care
800K+
WHY YOU SHOULD CHOOSE SaasVideoReviews

SaasVideoReviews has the world's largest selection of Saas Video Reviews to choose from, and each Saas Video Reviews has a large number of Saas Video Reviews, so you can choose Saas Video Reviews for Saas Video Reviews!

Browse More Content
Convert
Maker
Editor
Analyzer
Calculator
sample
Checker
Detector
Scrape
Summarize
Optimizer
Rewriter
Exporter
Extractor