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

读取并联

方法

GetEntries


返回

代码示例

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

参数

localeId: string
默认值:""

返回

RemoveEntry

()

参数

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

返回

()

RemoveEntryValue

()

参数

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

返回

()

RemoveTargetLocale

()

参数

localeId: string
默认值:""

返回

()

SetEntries

()

参数

entries: Variant
默认值:""

返回

()

SetEntryContext

()

参数

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

返回

()

SetEntryExample

()

参数

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

返回

()

SetEntryKey

()

参数

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

返回

()

SetEntrySource

()

参数

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

返回

()

SetEntryValue

()

参数

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

返回

()

活动