Dynamic Splicing of Localized Text
Last updated
Last updated
Dynamic concatenation of localizable text usually requires some preparation before concatenation of text takes effect.
A component is automatically attached to the LocalizationSetting GameObject: MyStringPack
This component keeps two StringTable lists, one for access, one for lookup access by field name; The other is to look up access based on the name of the text table and the field name or field ID.
For example, the code in Demo DynamicSetTextDemo.cs, the next line of code, after the string. L(), which means you need to query to get localized text.
if (index % 2 == 0) {
uiTextSetter.text = "Now Index = ".L() + ("<color=yellow>" + index + "</color>, ") + "Come on!".L();
}
The MyStringPack component in the Demo is associated with a text table called 'DemoCommonTexts' in its list of code concatenation texts, with the following contents:
From the table can be found: any code appears after added. The strings for L() are present in the field names in the text table.
In other words, it's added. The string of L() must be queried in the MyStringPack script during concatenation. The field data from the MyStringPack component is used when the code of the MyStringPack component concatenates fields of the same name that appear in multiple text tables in the text set list.
When you need to query localized text based on a text table name + field name or text table name + field ID, the MyStringPack component's list of table concatenation text sets is used as follows: Excel file name _ child table name :: Field name, Excel file name _ child table name combined to form a text table StringTable name. This solves the awkwardness of using the game's numerical table as a translation table.
You can also easily access localized text in your code in this way:
while (enabled) {
uiTextSetter.text = "Player Name".L() + ": <color=yellow>" +
$"PlayerAttributeForm::PlayerName{index}".LN()
+ "</color>";
if (index >= 2) {
index = 0;
}
index++;
yield return new WaitForSeconds(duration);
}
There was a row in the above code examples: $" PlayerAttributeForm: : PlayerName {index} ". LN (), which can index value is 0, 1, 2, this string is followed. LN() represents the data that needs to be searched for localization data in the list of table concatenation literal sets of the MyStringPack component. The data in the PlayerAttributeForm table is as follows:
introduction
Detailed introduction
simpleDescription
detailDescription
string
string
PlayerRoleConfig_PlayerRole :: Introduction to Yang Xiaofan
PlayerRoleConfig_PlayerRole :: Yang Xiaofan
PlayerRoleConfig_PlayerRole :: Introduction of Lin Xinyi
PlayerRoleConfig_PlayerRole :: Lin Xinyi Detailed introduction
PlayerRoleConfig_PlayerRole :: Evil Remains unchanged Introduction
PlayerRoleConfig_PlayerRole :: Evil remains unchanged
PlayerRoleConfig_PlayerRole :: Introduction to Fang Tianchen
PlayerRoleConfig_PlayerRole :: Fang Tianchen