Accessibility is a crucial aspect of gaming, encompassing various elements such as user-friendly control schemes, subtitles, and color-blindness settings. However, while many developers focus on implementing these features, multiple language support is often overlooked, especially in the mobile gaming industry. Fortunately, with the Unity Localization package and a simple integration with Google Spreadsheet, you can easily incorporate multiple languages into your game without incurring any additional development costs.
To get started, this tutorial will introduce you to the Unity Localization package and demonstrate how you can utilize it to enable translations not only for UI and other text elements but also for runtime assets. You will explore different methods of importing localized strings from professional platforms using the XLIFF format, and you will have the opportunity to try out a free method using Google Sheets integration. For this tutorial, you will use a project from the Unity Apprentice book. You can download the sample project using the provided link at the top or bottom of this tutorial.
To begin, open the starter project and navigate to the Title Scene located at Assets ⸠RW ⸠Scenes. Click the Play button in the Unity editor to access the Veggie Gladiators opening menu. Proceed by clicking on “New Game” to enter the dining hall, where you will control a Potato Warrior. Use the WASD keys to navigate the scene. Approach any non-playable character (NPC) and press the space bar to initiate a conversation. Some conversations may consist of multiple dialogue lines that require user input, so take your time to explore and discover all the interesting dialogue. Once you have explored to your satisfaction, exit play mode.
Now, your task is to add support for additional languages to this project, starting with your first translation. To achieve this, you will need to install the Unity Localization package. Open the Package Manager by selecting Window ⸠Package Manager. Ensure that “Packages: Unity Registry” is selected, and scroll down the list to locate the Localization package. Select it and click on “Install” to add the latest version of the package to your project.
Once the package has been imported, you need to set up the Localization Settings Asset. Unity saves these settings as a serialized asset, allowing you to monitor any changes made to your localization settings through source control. Begin by creating a new folder named “Localization” under the RW folder. Open the Project Settings from the Edit menu and select “Localization” from the list. Click on “Create” and save the new Localization Settings file into the Localization folder you just created. The Project Settings Localization window will now display various options for localization. Selecting the new file in the Project window will also reveal these options in the Inspector window.
Before delving into these options, it is necessary to set up your first locales. A locale represents a language along with an optional region, and it may include additional information such as currency, calendar, and user-added custom data. Click on the “Locale Generator” button to open a new window. In the Locale Generator window, select “English (en)” as the current default language of the project, and add “German (de)” as another locale. Then, click on “Generate Locales” and save the new assets in the same Localization folder as before. German translations can serve as a good test for your app’s UI flexibility since German words tend to be longer than those in other languages. However, the choice of languages to support ultimately depends on your app’s user base demographics or targeted regions.
With the new Locale files created for English and German, you need to select the default locale for the project. In the Localization Settings window, add the “English (en)” locale to both the “Specific Locale Selector” and “Project Locale Identifier” options. With this setup complete, you are now ready to add your first translation.
Currently, the Title menu contains two pieces of text that can be translated: the title itself and the “New Game” button. Both of these elements utilize a TextMeshPro component to render the text. The Localization Package is designed to seamlessly integrate with TextMeshPro and Legacy Text components, as these are the most commonly localized elements. Select the Canvas ⸠Panel ⸠Title text in the hierarchy. From the Component Menu of the TextMeshPro component (the kebab menu button), click on “Localize” to add a new component to the Title GameObject called “LocalizeStringEvent.” This component is the key driver for localization throughout your project. When added through the TextMeshPro menu, it automatically assigns a callback to its “UpdateString” method, which updates the text value of the TextMeshPro component.
However, before you can begin translating the values in these text components, you need to create a collection to work with. You may have noticed that the two dropdown menus for “String Reference” and “Table Collection” currently do not have any selectable values. To address this, click on “Create Table Collection” to open the Localization Tables window. Name the new table “UI Strings” and save it in a new folder located at RW ⸠Localization ⸠Menu. The table will automatically display the locales you set up earlier, with each locale having its own column. With the table now set up, keep the Localization Tables window open and return to the Title text in the hierarchy.
You can now select the “UI Strings” table from the “Table Collection” dropdown. Once selected, the button below will change to “Add Table Entry.” Click on “Add Table Entry.” The component will undergo a visual change, allowing you to enter an “Entry Name” and a value for each locale. Fill in the fields with the following values:
Entry Name: Title
English (en): Veggie Gladiators
German (de): Gemüse Gladiatoren
As you update these values, you will notice that they also update in the table. Congratulations! You have successfully set up your first translated string in Veggie Gladiators. Click on “Play” in the Unity Editor, and you will see a new dropdown appear in the game window, enabling you to change the loaded locale at any time.
Now, you need to establish a method for players to select their preferred language in the game.
Source link