Lean Localization is a lightweight localization asset, allowing you to easily add language-specific text, images, and much more.
First you need to add the LeanLocalization component to your scene:
Your Hierarchy window should now have a new LeanLocalization GameObject added, and this should be automatically selected for you.
Inside the Lean / Localization / Languages folder, you can see some prefabs for different languages. To add support for one in your project, simply drag and drop this prefab so it becomes a child of your LeanLocalization GameObject. If done correctly, this language will appear in the LeanLocalization component's Languages list.
To add a phrase, simply type the title of your phrase into the Translations search box, and click the Translations > Add button.
Your new phrase will automatically be added as a child to your LeanLocalization GameObject.
To add a translation, select your LeanPhrase component, and click the Add button next to the language you want to add a translation for.
Inside the phrase translation you can see three settings:
Text - Allows you to set the translated text for that phrase.
Object - Allows you to set the translated object for that phrase (e.g. Texture, Prefab, Sound).
Sprite - Allows you to set the translated sprite for that phrase.
Step 5 - Add Localization Components
Finally, you need to add a localization component to your scene.
Once added, you will see the Phrase Path setting, which you can set the phrase you want to use.
You can also click the List button to quickly see what's available.
That's it, your game will now automatically update based on your translations!
That's it! Your phrase should now have automatically translated from one language (e.g. English) to another (e.g. Spanish).
There are multiple ways to do this.
Select the GameObject that has the LeanLocalization component, then click the Current Language > List button.
Drag and drop the GameObject that has the LeanLocalization component into your event Object field, and select the LeanLocalization.SetCurrentLanguage function.
Simply call the Lean.Localization.LeanLocalization.SetCurrentLanguageAll() static method. For example:
Lean.Localization.LeanLocalization.SetCurrentLanguageAll("English");
If you just want to get translated text, then you can call:
Lean.Localization.LeanLocalization.GetTranslationText("YourPhraseNameHere");
If you want a Unity Object (e.g. Sprite), then you can call:
Lean.Localization.LeanLocalization.GetTranslationObject("YourPhraseNameHere");
You can find the default languages in the Lean/Localization/Languages folder. To create your own, you can:
You should now see a language prefab. Now you must:
That's it! You can now drag and drop your new language prefab onto the LeanLocalization GameObject in your scene as a child, or drop the prefab into the
LeanLocalization component's Prefabs setting.
To localize more components, simply implement the LeanLocalizedBehavior base class in your own components.
This class has the UpdateTranslation(LeanTranslation translation); method, where the specified translation will be null if it doesn't exist. If it does exist then you can read the translation.Data value, you can then cast this to the required type before use.
Take a look at the code for LeanLocalizedSpriteRenderer to see just how easy this is.
The more translations you add to your project, the more difficult Lean Localization can be to use, because the translation name dropdown list will become increasingly long.
To fix this, you can organize your translations into groups.
To do this, simply add forward slashes to your translation names when creating them.
When using a translation name dropdown, this will automatically place MyTranslation into a group called MyGroup.
If you have many translations or use many scenes then you may want to use prefabs instead of placing everything in the scene.
Drag and drop your phrases, CSV loaders, and tokens into your Project window, turning it into a prefab.
Delete your prefab instances from the scene.
Drag and drop your prefabs (or a root folder they belong to) into the LeanLocalization.Prefabs setting.
Done!
Your localizations should now be automatically loaded from prefabs, giving you better performance, and improved organization.
If you have many LeanLocalization components in different scenes, then this may be tedious to do. To fix this you can make your LeanLocalization component itself a prefab too, so you only have to view the prefab itself to trigger the update.
Tokens allow you to find and replace text. For example, if you want to include the player's name inside a localized text field, then the tokens feature allows you to do this.
To create a token you can either:
You've now created a token, where the GameObject name controls the name of the token.
A token can be added using curly braces, like this:
Hi, my name is {NAME}!
Where the token GameObject is called NAME.
Your translated text should now automatically have any tokens replaced.
You can also change the value of a token in game using the LeanToken.SetValue method.
Cultures allow you to associate language codes with language names. For example, English might be associated with en-GB, en-US, etc.
When you start your application the current device language code will be loaded, and the associated language will be chosen.
Internally, the LeanPhrase component only stores Text (string) and Object (UnityEngine.Object) types.
Sprites in the Unity project window are stored as children of their source image. This means when you drag and drop a sprite, you're usually dragging and dropping the parent image, which may give you undesired behaviour when you drag it into an Object field.
To avoid any unexpected behaviour, I added the additional Sprite setting, so you can drag and drop the sprite's parent image, and Unity will automatically drop the sprite in.
This issue doesn't occur for most other scenarios, so you can use the Object type for everything else like Mesh, Material, etc.
Yes, if your project contains the TextMeshPro package then it will automatically be supported.
Here's a list of all my other assets, please check them out!
You can also view this list on my Asset Store page.
Rapidly develop your game with consistent input across desktop & mobile using Lean Touch. This lightweight asset comes with many modular components, allowing you to customize them to your exact project needs!
Lean Touch+ is an extension to the popular Lean Touch asset, adding many more example scenes.
Lean Localization is a localization library that's designed to be as simple to use as possible for both designers, and programmers.
Quickly optimize the performance of your games using Lean Pool. Within minutes you can use this lightweight asset to preload, recycle, and limit the spawning of your prefabs.
Quickly polish your games using Lean Transition. This asset allows you to easily tween or animate almost anything in your game, making it transition smoothly.
Lean GUI is a colllection of components that extend Unity's GUI system, allowing you to rapidly enhance the user experience (UX) of your game's UI.
Lean GUI Shapes allows you to quickly add lines, rounded boxes, polygons, and much more to your GUI!
Lean Texture allows you quickly modify textures in your project with a range of filters, pack them together into channels, and much more!
Lean Texture+ is an extension to Lean Texture, adding many new types of texture modification tools!
Unlock a universe of visual possibilities with Modular Backgrounds. Simply drag and drop these graphics into the background of your scenes.
Paint all your objects using Paint in 3D - both in game, and in editor. All features are optimized with GPU accelerated texture painting, so you can enjoy consistent performance, even if you paint your objects one million times!
Paint all your sprites with Paint in 2D. With incredible performance on mobile, WebGL, and much more!
Paint in Editor unlocks the ability to paint objects in your scene - great for making small tweaks, or even creating entirely new texture sets!
FLOW allows you to add large scale interactive fluids to your scene - all highly optimized using GPU acceleration.
Unlock the full potential of your 2D games using Destructible 2D, this asset allows you to quickly convert all your boring solid sprites into fully destructible ones!
Quickly make the space scene of your dreams using Space Graphics Toolkit. This huge collection of space effects can be customized and combined in any way you like, allowing you to quickly make realistic or fantasy worlds. Each feature has been heavily optimized to run on almost any device and platform.
Enhance your space scenes using this large pack of high detail volumetric planets. These planets are finished using the powerful planet features from Space Graphics Toolkit (not required).
Unity sounds only emanate from a single point source. This is great for explosions and footsteps, but quite often you need something more advanced. Volumetric Audio is an easy to use package that allows you to define boxes, spheres, capsules, paths, or meshes that sounds can emanate from.
Changed folder structure to be inside Plugins/CW/LeanLocalization.
Updated inspector code to support third party assets that implement nested inspectors.
Added LeanLocalization.GetFirstCurrentLanguage method.
Renamed LeanLocalization.SaveLanguage setting to SaveLoad.
Added LeanLocalization.SaveLoad = WhenChangedAlt setting.
Fixed LeanLanguageName attribute not showing tooltip text.
Fixed LeanLanguage.CurrentLanguage not loading after save.
Added LeanLanguageCSV.Format = Comma setting.
Added LeanLanguageCSV.Format = Semicolon setting.
Fixed LeanLanguageCSV error.
Fixed LeanLanguageCSV not dirting when clicking Load Now or Clear.
Added Debug demo scene.
Fixed language aliases not registering properly.
Fixed missing class error in .NET 4.x.
Moved main build to Unity 2019.4.12f1.
Added auto translation option to LeanPhrase component.
Moved languages to separate LeanLanguage component and prefabs.
Allowed multiple LeanLocalization instances at once.
Changed LeanLocalization.SaveLanguage to only save when manually modified.
Moved main build to Unity 2018.4.0f1.
Updated documentation.
Added asmdef.
Phrases can now be added from the translation name List dropdown.
Translation sources can now be selected from the translation name List dropdown.
Updated TextMeshPro package structure.
Added TMP_Dropdown support to TextMeshPro package.
Added LeanLocalizedTextMeshPro to TextMeshPro package.
Added LeanLocalizedTextMeshProFont to TextMeshPro package.
This interface can be implemented by any component that needs to listen for localization changes.
This contains information about a language, and any of its optional cultures.
The language code used for auto translation.
This culture names for this language (e.g. en-GB, en-US).
This component will load localizations from a CSV file. By default they should be in the format:
Phrase Name Here = Translation Here // Optional Comment Here
The text asset that contains all the translations.
The format of the CSV data.
See the inspector for examples of what the different formats look like.
The language of the translations in the source file.
This allows you to control when the CSV file is loaded or unloaded. The lower down you set this, the lower your app's memory usage will be. However, setting it too low means you can miss translations if you haven't translated absolutely every phrase in every language, so I recommend you use LoadImmediately unless you have LOTS of translations.
LoadImmediately = Regardless of the language, the CSV will load when this component activates, and then it will be kept in memory until this component is destroyed.
LazyLoad = The CSV file will only load when the CurrentLanguage or DefaultLanguage matches the CSV language, and then it will be kept in memory until this component is destroyed.
LazyLoadAndUnload = Like LazyLoad, but translations will be unloaded if the CurrentLanguage or DefaultLanguage differs from the CSV language.
LazyLoadAndUnloadPrimaryOnly = Like LazyLoadAndUnload, but only the CurrentLanguage will be used, the DefaultLanguage will be ignored.
This stores all currently loaded translations from this CSV file.
This will unload all translations from this component.
This will load all translations from the CSV file into this component.
This attribute allows you to modify a normal string field into one that has a dropdown list that allows you to pick a language.
This component manages a global list of translations for easy access.
Translations are gathered from the prefabs list, as well as from any active and enabled LeanSource components in the scene.
All active and enabled LeanLocalization components.
Dictionary of all the phrase names mapped to their current translations.
How should the cultures be used to detect the user's device language?
If the application is started and no language has been loaded or auto detected, this language will be used.
This allows you to control if/how this component's CurrentLanguage setting should save/load.
None = Only the DetectLanguage and DefaultLanguage settings will be used.
WhenChanged = If the CurrentLanguage gets manually changed, automatically save/load it to PlayerPrefs?
This stores all prefabs and folders managed by this LeanLocalization instance.
Called when the language or translations change.
Change the current language of this instance?
When rebuilding translations this method is called from any LeanSource components that define a token.
When rebuilding translations this method is called from any LeanSource components that define a transition.
This sets the current language using the specified language name.
This sets the current language of all instances using the specified language name.
This returns the CurrentLanguage value from the first LeanLocalization instance in the scene if it exists, or null.
This adds the specified UnityEngine.Object to this LeanLocalization instance, allowing it to be registered as a prefab.
This calls AddLanguage on the first active and enabled LeanLocalization instance, or creates one first.
This creates a new token with the specified name, and adds it to the current GameObject.
This calls AddToken on the first active and enabled LeanLocalization instance, or creates one first.
This creates a new token with the specified name, and adds it to the current GameObject.
This allows you to set the value of the token with the specified name.
If no token exists and allowCreation is enabled, then one will be created for you.
This allows you to get the value of the token with the specified name.
If no token exists, then the defaultValue will be returned.
This calls AddPhrase on the first active and enabled LeanLocalization instance, or creates one first.
This creates a new phrase with the specified name, and adds it to the current GameObject.
This will return the translation with the specified name, or null if none was found.
This will return the translated string with the specified name, or the fallback if none is found.
This will return the translated UnityEngine.Object with the specified name, or the fallback if none is found.
This rebuilds the dictionary used to quickly map phrase names to translations for the current language.
If you call this method, then UpdateTranslations will be called next Update.
This component will update an AudioSource component with localized text, or use a fallback if none is found.
This component simplifies the updating process, extend it if you want to cause a specific object to get localized
This is the name of the translation this script uses.
If you call this then this component will update using the translation for the specified phrase.
This component will update a UI.Dropdown component with localized text, or use a fallback if none is found.
If you call this then this component will update using the translation for the specified phrase.
This component will update an Image component with a localized sprite, or use a fallback if none is found
This component will update a Renderer component's sharedMaterial with a localized material, or use a fallback if none is found.
This component will update a SpriteRenderer component with a localized sprite, or use a fallback if none is found
This component will update a UI.Text component with localized text, or use a fallback if none is found.
This component will update a Text component's Font with a localized font, or use a fallback if none is found.
This component will update a TMPro.TextMeshProUGUI component with localized text, or use a fallback if none is found.
This component will update a TextMesh component's Font with a localized font, or use a fallback if none is found.
This component will update a TMPro.TextMeshPro component with localized text, or use a fallback if none is found.
This component will update a TextMeshPro component's Font with a localized font, or use a fallback if none is found.
This component will update a TMPro.TextMeshProUGUI component with localized text, or use a fallback if none is found.
This component will update a TextMeshProUGUI component's Font with a localized font, or use a fallback if none is found.
This component will update a TMP_Dropdown component with localized text, or use a fallback if none is found.
If you call this then this component will update using the translation for the specified phrase.
The component works like LeanToken, but must be added to the child GameObject of the one that will be translated.
This contains data about each phrase, which is then translated into different languages.
The language of this translation.
The translated text.
The translated object (e.g. language specific texture).
This will return the translation of this phrase for the specified language.
Add a new translation to this phrase for the specified language, or return the current one.
This class stores a reference to an object (e.g. folder) in your project that contains LeanSource components so they can be registered.
This is the base class used for all translation sources. When a translation source is built, it will populate the LeanLocalization class with its translation data.
This allows you to register a token or language.
This allows you to register a phrase based on the specified languages.
The class stores a token name (e.g. "AGE"), allowing it to be replaced with the token value (e.g. "20").
To use the token in your text, simply include the token name surrounded by braces (e.g. "I am {AGE} years old!")
This is the current value/text for this token. When this changes, it will automatically update all localizations that use this token.
This method allows you to set Value from an inspector event using a float value.
This method allows you to set Value from an inspector event using a string value.
This method allows you to set Value from an inspector event using an int value.
This contains the translated value for the current language, and other associated data.
The name of this translation.
The data of this translation (e.g. string or Object).
If Data has been filled with data for the primary language, then this will be set to true.
This stores a list of all LeanSource instances that are currently managing the current value of this translation in the current language.
This returns Text with all tokens substituted using the LeanLocalization.Tokens list.
How do I automatically translate words?
How do I get a translation from C# code?
How do I add to the language list?
How do I localize other components?
How do I better organize my translations?
Why can you only translate Text, Object, and Sprite?
LeanLocalizedTextMeshProUGUIFont