概要
方法
GetTranslator(localeId: string):Instance |
RemoveEntry(key: string,source: string,context: string):() |
RemoveEntryValue(key: string,source: string,context: string,localeId: string):() |
RemoveTargetLocale(localeId: string):() |
SetContents(contents: 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):() |
代码示例
本地化表
local LocalizationService = game:GetService("LocalizationService")
local function createLocalizationTable(entries): LocalizationTable
local localTable = Instance.new("LocalizationTable")
localTable.SourceLocaleId = LocalizationService.SystemLocaleId
localTable:SetEntries(entries)
return localTable
end
local entries = {
{
Key = "Hello_World", -- 要与 GetString 一起使用的 'expressionKey'
Values = { -- 一个字典,包含与 IETF 语言标签对应的键及其翻译。
["ru"] = " !", -- 俄语
["fr"] = "Bonjour le monde!", -- 法语
["de"] = "Hallo Welt!", -- 德语
["en-US"] = "Hello world!", -- 英语
["it"] = "Ciao mondo!", -- 意大利语
["pt-BR"] = "Ol Mundo!", -- 葡萄牙语
["ja"] = "", -- 日语
["es"] = "Hola Mundo!", -- 西班牙语
},
},
}
local helloWorldTable = createLocalizationTable(entries)
local translatorEnglish = helloWorldTable:GetTranslator("en-US")
print(translatorEnglish:FormatByKey("Hello_World"))API 参考
属性
DevelopmentLanguage
Root
方法
GetContents
GetEntries
返回
代码示例
使用本地化表
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 -- 循环遍历字典中的每个键值对以打印我们的字符串
print(value)
end
endGetString
RemoveEntry
RemoveEntryValue
RemoveKey
SetContents
SetEntries
LocalizationTable:SetEntries(entries:Variant):()
参数
entries:Variant |
返回
()
SetEntry
SetEntryContext
SetEntryExample
SetEntryKey
SetEntrySource