Callbacks
The plugin has callbacks that allow modifying the translation before they are applied to the target object (Label's text, etc)
In the Localize component, there is a section named "On Localize Call". When expanded, that section allows specifying an object and a script function in that object that its called whenever the localization is executed.
The function should have no parameters and return void. It can modify the translation by changing the value of the following variables:
Localize.MainTranslation : Holds the translation returned by the Main Term
Localize.SecondaryTranslation : Translation of the Secondary Term
Localize.CallBackTerm : Term used to generate the MainTranslation (can be the one set or inferred from the target object)
Localize.CallBackSecondaryTerm : Secondary Term used to generate SecondaryTranslation
Localize.CurrentLocalizeComponent : Localize Component that owns the callback
Given that the Callback function has no parameter, the previous variables are static variables that are only valid when the callback function its called.
Example
In the "Unity Standard Localization Scene" there is an example that uses callback to replace a part of the localization with a dynamic value.
It adds the color of the winner player to the localization while also keeping the correct order of words for each language:
English "{PLAYER} wins" turns into "Red wins"
Spanish: "El {PLAYER} ha ganado" turns into "El Rojo ha ganado"
To accomplish that, a script should include the following function:
public void OnModifyLocalization() { // if no MainTranslation then skip (most likely this localize component only changes the font) if (string.IsNullOrEmpty(Localize.MainTranslation)) return;
// get translation of Red color into the current language string PlayerColor = LocalizationManager.GetTermTranslation( "Color/Red" );
// set the color in the correct location Localize.MainTranslation = Localize.MainTranslation.Replace("{PLAYER_COLOR}", PlayerColor); } |
Then on the Localize component, select the object that has the script with that function and select the callback function.
Every time the object is localized, it will call the function to process it before showing the localization in the label.
Please, notice that for just replacing {[Tags}] within a text, is easier to use the Local or Global Parameters. Callbacks should be used when more extensive customizations are needed.
Created with the Personal Edition of HelpNDoc: Free help authoring tool