概要
方法
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"] = "你好,媽媽;你好,爸爸。",
["0002"] = "我在格蘭達營。",
["0003"] = "營地非常有趣。",
["0004"] = "他們說如果不下雨,我們會有些樂趣。",
},
},
}
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