Overview
Localization System Documentation
This document outlines how to use the localization system in your project.
Overview
The localization system allows you to easily translate text in your game to different languages. It uses a key-based approach where you assign a unique key to each piece of text, and then provide translations for those keys in separate language files.
Setting Up
Create a text file for each language you want to support (e.g.,
English.txt,Spanish.txt) in theResources/Localization/folder.In each language file, add your translations in the format
KEY : Translation.
Using Localized Text
In Code
To get localized text in your scripts:
localizedText = LocalizationManager.GetText("KEY", "Default Text");The second parameter is the default text to use if the key is not found.
In UI
For UI elements, use the LocalizedTextMeshProUGUI component instead of the regular TextMeshProUGUI:
Add the
LocalizedTextMeshProUGUIcomponent to your UI text element.Set the
Instance IDfield to the key you want to use for this text.Set the default text in the regular text field of the component.
Language Files
Each language file should be a plain text file with key-value pairs:
Placeholders
You can use placeholders in your translations for dynamic content. The system supports replacing placeholders using the PlaceholderManager.
Level Number Placeholder
For level numbers, use the following format in your translations:
In your code, you would then use:
Changing Languages
To change the current language:
Automatic Language Detection
The system automatically detects the system language on non-editor platforms. In the Unity editor, it uses the language specified in the DebugSettings asset.
Best Practices
Use descriptive keys that reflect the content or purpose of the text.
Keep your language files organized and consistent across all supported languages.
Test your localization with placeholder text to ensure UI elements adapt to different text lengths.
Regularly update your language files as you add new text to your game.
By following these guidelines, you can efficiently manage translations for your game across multiple languages.
Last updated