Localization
As of version 1.1.56.0, Rewired includes a localization system can be used to display localized names for controllers, controller elements, Actions, Action Categories, Map Categories, and other things. Anywhere a name is returned in the API, it will return a localized name if available.
Contents
Quick Setup
Add the Localized String Provider component to the Rewired Input Manager (or a child object) by selecting the Game Object and from the menu:
- Component -> Rewired -> Localization ->Localized String Provider
Create a JSON file with the keys and localized strings and assign it in the inspector. See Key Format and Exporting JSON keys for more information on how to create the JSON file.
Namespace
All Localization-related classes are in the Rewired.Localization namespace.
using Rewired.Localization;
Important Classes
- ReInput.LocalizationHelper - Provides access to all localization-related members. Access via ReInput.localization.
Localized String Provider
The localized string provider is responsible for performing a string key lookup and returning a localized string. A localized string provider is required to use the localization system.
Any class that implements Rewired.Interfaces.ILocalizedStringProvider can be used as the localized string provider by assigning it to ReInput.localization.localizedStringProvider. The LocalizedStringProviderBase component implements this interface and sets itself as the localized string provider in OnEnable. (The localized string provider should always null the ReInput.localization.localizedStringProvider property when no longer needed, usually in OnDisable.)
LocalizedStringProvider
The LocalizedStringProvider component is the default implementation of a localized string provider.
Add the Localized STring Provider component to the Rewired Input Manager (or a child object) by selecting the Game Object and from the menu:
- Component -> Rewired -> Localization -> Localized String Provider
Prefetch | Determines if localized strings should be fetched immediately in bulk when available. If false, localized strings will be fetched when queried. By default, localized strings are fetched on an as-needed basis. That is, no key lookup is done until the localized string is first displayed. If you want all keys for connected devices to be loaded in bulk, set prefetch to true in the inspector, or in code, ReInput.localizedStringProvider.prefetch = true. Controllers that are not presently connected cannot have their localized strings prefetched, but if prefetch is enabled, all localized strings for that controller will be fetched when it is connected. |
Localized Strings File | A JSON file containing localizied string key value pairs. |
Localized strings are cached when returned from the localized string provider. This prevents wasting CPU resources by constantly doing expensive string key lookups. The localized string cache can be cleared by calling ReInput.localization.Reload. The cache will also be cleared automatically after setting a new localized string provider.
Changing Localized Strings at Runtime
You might want to create a different set of localized strings for different languages.
You can set the LocalizedStringProvider.localizedStringsFile property to load a new set of localized strings.
You can also replace the Localized String Provider and all cached strings will be cleared automatically. Just set ReInput.localization.localizedStringProvider to your new provider.
Key Format
The Localization system and the Glyph system share the same keys, so all the information in the glyphs documentation on this topic applies to Localization as well. To avoid duplication of documentation, please read the the Key Format section of the Glyphs documentation first.
Beyond controllers and controller elements covered in the Glyphs documentation, a number of additional names can be localized.
All keys can be exported from the Rewired Editor -> Tools page.
Note: The [brackets] below are not part of the key. Items in brackets represent a variable value.
Additional Localization Keys:
Each of these keys can be defined in the Rewired Editor.
player/[key] | A Player name. |
action/[key] | An Action name, or the name of one pole of an Action (pos/neg). |
action/category/[key] | An Action Category name. |
controller_map/category/[key] | A Controller Map Category name. |
controller_map/layout/[key] | A Controller Map Layout name. |