No Such Localization consists of three categories of components.
LocalizationService acts as the central hub for the localization framework. There must be a single instance of this component in the scene. I recommend marking the GameObject DontDestroyOnLoad. If there are multiple instances of this script, the one that gets enabled later will act as the registered and active instance.
Other components that participate in the localization process register with this service instance and are able to change the current language, listen to localization events and publish events.
ComponentLocalizer<LT, CT> are components that make changes to other components based on the localization service's current language and translations and their own custom logic. The most prominant are Text localizers. The text of different UI components need to change and Text Localizers take care of that by registering to the
Localization Service and updating the text when current language changes.
Localizers change only a single field of their target component. This way they can be mixed and matched to create more complex Localization behaviours. SliderDirectionLocalizer is a simple example of a
Localizer component. It changes the direction of a @Unity.UI.Slider component when the language is right-to-left.
Translation Source components (subclassed from BaseTranslationSource ) provide translations for phrases to the
LocalizationService. In contrast to
Localizer components, they don't listen nor react to the events of
LocalizationService such as a language change.
This image shows how a menu UI is localized in a sample scene.
You can have as many translation sources and localizers as you need in your scene. The localizer components can find the right translation for a phrase through the LocalizationService. Since both translation sources and localizers are regular Unity components, you can save them in prefabs and reuse them in multiple scenes or load them dynamically.
You can organize translation sources depending on your needs:
- Distributed on individual @UnityEngine.GameObject s in your scene.
- Centeralized in a single source in your scene
- One source per translated language
It really depends on you, your game and your team. The architecture is flexible and gives you the options.