LocalizationTable

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

本地化表是翻译的数据库。它包含各种语言的源字符串和翻译。它与 TranslatorLocalizationService 自动翻译系统一起用于控制游戏中的文本翻译。本地化表被设计为像纹理或脚本一样被处理的资源。它们在运行时不优化以进行修改。更改表的内容会导致整个表的内容复制到所有玩家。

本地化表入口

每个本地化表包含一组入口。每个入口包含文本的翻译,以及一些特殊字段:

  • 是代验证码快速查找的唯一键。如果它不为空,它必须在表中独一无二。
  • 来源 是源语言中的原始文本,将被 LocalizationService 自动文本替换系统用于匹配 GUI 文本并渲染翻译。来源字段可以由文本捕捉工具填充,或可以手动设置。对于基于键的查找,源值可以用作该地区的翻译,如果入口没有该地区的翻译。如果源为空,则入口不会被自动替换系统使用。
  • 上下文 是文本出现在对象上的全名称。上下文被自动文本替换系统用于解释。当源的多个匹配项被找到时,系统会从上下文字符串的最后匹配倒回,选择最佳匹配项。还有其他更强大的方法来处理歧义,例如使用多个表与 GuiBase2d.RootLocalizationTable
  • 示例 是你想要它成为的一切。如果文本捕捉工具猜测了某些参数为字符串,示例字段将包含使用在上下文中的示例。

所有这些字段都是可选的,但至少必须键或源不为空。没有两个记录可以拥有相同的键、来源和上下文。

请参阅翻译动态内容获取更多信息。

代码示例

LocalizationTable

local LocalizationService = game:GetService("LocalizationService")
local function createLocalizationTable(entries)
local localTable = Instance.new("LocalizationTable")
localTable.DevelopmentLanguage = LocalizationService.SystemLocaleId
localTable:SetEntries(entries)
return localTable
end
local entries = {
{
Key = "Hello_World", -- The 'expressionKey' to be used with GetString
Values = { -- A dictionary of keys corresponding to IETF language tags, and their translations.
["ru"] = " !", -- Russian
["fr"] = "Bonjour le monde!", -- French
["de"] = "Hallo Welt!", -- German
["en-US"] = "Hello world!", -- English
["it"] = "Ciao mondo!", -- Italian
["pt-BR"] = "Ol Mundo!", -- Portuguese
["ja"] = "", -- Japanese
["es"] = "Hola Mundo!", -- Spanish
},
},
}
local helloWorldTable = createLocalizationTable(entries)
print(helloWorldTable:GetString("en-US", "Hello_World"))

概要

方法

  • 返回一个阵列的词典,每个词典代表本地化数据的入口。

  • 返回一个 Translator 为此本地化表中的条目,指定语言。

  • RemoveEntry(key : string,source : string,context : string):()

    使用指定的 keysourcecontext 从本地化表中删除一个条目,以缩小要删除的特定条目。

  • RemoveEntryValue(key : string,source : string,context : string,localeId : string):()

    使用提供的 key , source , contextlocaleId 从本地化表中删除单个语言翻译,以缩小要删除的特定条目。

  • RemoveTargetLocale(localeId : string):()

    从指定的本地化表中删除所有翻译,带有指定的 localeId。

  • SetEntries(entries : Variant):()

    设置本地化表的内容。

  • SetEntryContext(key : string,source : string,context : string,newContext : string):()

    将本地化表入口的 上下文 字段设置为newContext,使用指定的keysourcecontext缩小搜索范围,以便将此更改应用到入口。

  • SetEntryExample(key : string,source : string,context : string,example : string):()

    将本地化表入口的 示例 字段设置为 example ,使用指定的 keysourcecontext 来缩小将有这种更改应用的入口。

  • SetEntryKey(key : string,source : string,context : string,newKey : string):()

    将本地化表入口的 字段设置为 newKey ,使用指定的 key , sourcecontext 来缩小将有这种更改应用的入口。

  • SetEntrySource(key : string,source : string,context : string,newSource : string):()

    将本地化表入口的 来源 字段设置为newSource,使用指定的keysourcecontext来缩小将有这种更改应用的入口。

  • SetEntryValue(key : string,source : string,context : string,localeId : string,text : string):()

    将指定的本地Id的文本设置为本地化表的入口,使用指定的 key , sourcecontext 来缩小包含这个更改的入口。

属性

SourceLocaleId

读取并联

这个表的输入键字串的 Roblox 本地,例如 “en-us” 或 “es-es”。这通常是游戏的“开发语言”。对于融合多个本地化表对象的翻译器,它是默认本地化表的地区ID。默认为“en-us”。

方法

GetEntries

获取输入函数返回包含在给定 LocalizationTable 中的一组词典,每个词典代表本地化数据的入口。

要设置本地化表的条目,您可以使用 LocalizationTable:SetEntries()

阵列中的每个词典包含以下字段:


<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<b>钥匙</b>
</td>
<td><code>图书馆.string</code></td> <td>本地化表中这个特定入口的查找键。</td>
</tr>
<tr>
<td>
<b>来源</b>
</td>
<td><code>图书馆.string</code></td> <td>用于格式化本地化字符串的字符串。如果没有提供键,将用作查找。</td>
</tr>
<tr>
<td>
<b>上下文</b>
</td>
<td><code>图书馆.string</code></td> <td>一个 <code>Class.Instance:GetFullName()</code> 路径到被用来生成本地化表的对象。如果没有提供键,用作查找 if 。</td>
</tr>
<tr>
<td>
<b>例子</b>
</td>
<td><code>图书馆.string</code></td> <td>用于格式化本地化的字符串。可选。</td>
</tr>
<tr>
<td>
<b>值</b>
</td>
<td><code>词典</code></td> <td>这个本地化入口的语言翻译词典。该词典的键是本地ID,值是用于为本地ID对应的语言进行本地化的字符串。</td>
</tr>
</tbody>
索引

返回

一个集合的词典,每个词典代表本地化数据的入口。

代码示例

The following code sample creates a LocalizationTable, sets its entries, then gets and displays its entries. In order for this example to work, a LocalizationTable instance must be located inside the LocalizationService service.

The entries variable is a table of dictionaries, each with the format required to create a LocalizationTable with LocalizationTable:SetEntries().

The get_results variable is a table of dictionaries - the same table that we created with the entries variable. We then loop through each of the tables in this dictionary to display its Values/strings.

Using a LocalizationTable

local LocalizationService = game:GetService("LocalizationService")
local localizationTable = LocalizationService:FindFirstChild("LocalizationTable")
local entries = {
{
["Key"] = "0001",
["Source"] = "en-us",
["Values"] = {
["0001"] = "Hello Muddah, hello Fadduh.",
["0002"] = "Here I am at Camp Granada.",
["0003"] = "Camp is very entertaining.",
["0004"] = "And they say we'll have some fun if it stops raining.",
},
},
}
localizationTable:SetEntries(entries)
local get_results = localizationTable:GetEntries()
for _index, dict in pairs(get_results) do
for _key, value in pairs(dict["Values"]) do -- Loop through every key, value pair in the dictionary to print our strings
print(value)
end
end

GetTranslator

返回一个 Translator 为此本地化表中的条目,指定语言。翻译器首先在这个表中搜索,然后查看祖先表。

参数

localeId: string
默认值:""

返回

RemoveEntry

()

使用指定的 keysourcecontext 从本地化表中删除一个条目,以缩小要删除的特定条目。

参数

key: string
默认值:""
source: string
默认值:""
context: string
默认值:""

返回

()

RemoveEntryValue

()

使用提供的 key , source , contextlocaleId 从本地化表中删除单个语言翻译,以缩小要删除的特定条目。

参数

key: string
默认值:""
source: string
默认值:""
context: string
默认值:""
localeId: string
默认值:""

返回

()

RemoveTargetLocale

()

从指定的本地化表中删除所有翻译,带有指定的 localeId。

参数

localeId: string
默认值:""

返回

()

SetEntries

()

设置本地化表的内容。

输入参数应为返回自 LocalizationTable:GetEntries() 函数的同一格式的词典阵列。

参数

entries: Variant
默认值:""

返回

()

SetEntryContext

()

将本地化表入口的 上下文 字段设置为newContext,使用指定的keysourcecontext缩小搜索范围,以便将此更改应用到入口。

参数

key: string
默认值:""
source: string
默认值:""
context: string
默认值:""
newContext: string
默认值:""

返回

()

SetEntryExample

()

将本地化表入口的 示例 字段设置为 example ,使用指定的 keysourcecontext 来缩小将有这种更改应用的入口。

参数

key: string
默认值:""
source: string
默认值:""
context: string
默认值:""
example: string
默认值:""

返回

()

SetEntryKey

()

将本地化表入口的 字段设置为 newKey ,使用指定的 key , sourcecontext 来缩小将有这种更改应用的入口。

参数

key: string
默认值:""
source: string
默认值:""
context: string
默认值:""
newKey: string
默认值:""

返回

()

SetEntrySource

()

将本地化表入口的 来源 字段设置为newSource,使用指定的keysourcecontext来缩小将有这种更改应用的入口。

参数

key: string
默认值:""
source: string
默认值:""
context: string
默认值:""
newSource: string
默认值:""

返回

()

SetEntryValue

()

将指定的本地Id的文本设置为本地化表的入口,使用指定的 key , sourcecontext 来缩小包含这个更改的入口。

参数

key: string
默认值:""
source: string
默认值:""
context: string
默认值:""
localeId: string
默认值:""
text: string
默认值:""

返回

()

活动