MyLocalization Decument
  • v1.3
    • MyLocalization English Document
      • MyLocalization Data Flow Diagram
      • Quick Start
        • Run the Demo Correctly
        • Preparation
        • Localize Text
        • Localize Texture
        • Localization of Other Types of Resources
      • Load Assets
        • Only Load Resources Corresponding to the Current Language
        • Implement IResLoader interface
        • Enable IResLoader Subclass
        • Convert Resource References Associations to Paths
        • Text Localization Items Do Not Need to Be Loaded with Language Type
      • Edit Text for Localization
        • Basic Operation
        • Automatic Translation
        • Find and Replace
        • Speech Binding Text
        • CSV Table Export and Import
        • Essay on the Importance of Text Table (StringTable)
      • Display and Setter Components
        • Correspondence between Setter Components and Display Components
        • RTL (Right To Left) Related Settings
        • Dynamic Splicing of Localized Text
        • Quickly create and modify localized field text using properties of MyString
    • MyLocalization 中文文档
      • MyLocalization 数据流程图
      • 快速开始
        • 正确运行 Demo
        • 准备工作
        • 文本本地化
        • 图片本地化
        • 其他资源的本地化
      • 加载当前语言资源
        • 只加载当前语言对应的资源
        • 实现 IResLoader 接口
        • 启用 IResLoader 子类
        • 将资源引用关联转为路径
        • 文本的本地化项不能随语言类型加载
      • 编辑文本表
        • 基本操作
        • 自动翻译
        • 搜索与替换
        • 语音绑定文字
        • CSV表格导出与导入
        • 使用 MyString 的属性快速创建和修改本地化字段文本
      • 一切准备都为了Setter组件实现本地化
        • Setter 组件与显示组件的对应关系
        • RTL (Right To Left)相关设置
        • 动态拼接本地化文本
Powered by GitBook
On this page
  1. v1.3
  2. MyLocalization 中文文档
  3. 一切准备都为了Setter组件实现本地化

动态拼接本地化文本

PreviousRTL (Right To Left)相关设置

Last updated 2 years ago

动态拼接可本地化的文本通常需要做一些准备才能时拼接文本生效.

在LocalizationSetting GameObject 上会自动挂上一个组件: MyStringPack

这个组件中会保持两个StringTable列表, 分别用于两种访问方式, 一种是根据字段名称查找访问的方式; 另一种是根据文本表的名称和字段名称或字段ID查找访问的方式.

例如Demo中的代码 DynamicSetTextDemo.cs 中下面一行代码, 字符串后面加了.L() ,意思是需要查询获得本地化文本.

if (index % 2 == 0) {
    uiTextSetter.text = "Now Index = ".L() + ("<color=yellow>" + index + "</color>, ") + "Come on!".L();
}

Demo中的 MyStringPack 组件的 代码拼接文字集合列表中就关联了一张名叫'DemoCommonTexts'的文本表, 内容如下:

从表中可以发现: 任何代码中出现后面加了.L()的字符串都在这张文本表中的字段名称中出现了.

换句话说, 后面加了.L()的字符串在拼接过程中一定会来 MyStringPack 脚本中去查询结果. 当MyStringPack 组件的 代码拼接文字集合列表中多张文本表中出现相同名称的字段时, 将使用后者的字段数据.

当需要根据文本表表名+字段名 或 文本表表名+字段ID 查询本地化文字时, 会使用到MyStringPack 组件的 填表拼接文字集合列表, 如下表表格中填写: Excel文件名_子表名 :: 字段名 , Excel文件名_子表名 组合成为一个文本表StringTable的名称. 这种方式就解决了把游戏数值表当作翻译表的尴尬.

简介
详细介绍

simpleDescription

detailDescription

string

string

PlayerRoleConfig_PlayerRole :: 杨小凡简介

PlayerRoleConfig_PlayerRole :: 杨小凡详细介绍

PlayerRoleConfig_PlayerRole :: 林欣艺简介

PlayerRoleConfig_PlayerRole :: 林欣艺详细介绍

PlayerRoleConfig_PlayerRole :: 邪不改简介

PlayerRoleConfig_PlayerRole :: 邪不改详细介绍

PlayerRoleConfig_PlayerRole :: 方天辰简介

PlayerRoleConfig_PlayerRole :: 方天辰详细介绍

在代码中也可以方便地使用此种方式访问本地化文本:

    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);
    }

在上面的代码实例中有一行: $"PlayerAttributeForm::PlayerName{index}".LN(), 其中 index 可以取值是0, 1, 2, 此字符串后面跟了.LN() 代表需要去MyStringPack 组件的 填表拼接文字集合列表中的数据中去查找本地化数据. PlayerAttributeForm 这张文本表中的数据如下: