Lớp công cụ
LocalizationTable
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Phương Pháp
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):() |
Mẫu mã
Bảng Địa Phương Hóa
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", -- Chìa khóa 'expressionKey' sẽ được sử dụng với GetString
Values = { -- Một từ điển các khóa tương ứng với các thẻ ngôn ngữ IETF, và các bản dịch của chúng.
["ru"] = " !", -- Tiếng Nga
["fr"] = "Bonjour le monde!", -- Tiếng Pháp
["de"] = "Hallo Welt!", -- Tiếng Đức
["en-US"] = "Hello world!", -- Tiếng Anh
["it"] = "Ciao mondo!", -- Tiếng Ý
["pt-BR"] = "Ol Mundo!", -- Tiếng Bồ Đào Nha
["ja"] = "", -- Tiếng Nhật
["es"] = "Hola Mundo!", -- Tiếng Tây Ban Nha
},
},
}
local helloWorldTable = createLocalizationTable(entries)
local translatorEnglish = helloWorldTable:GetTranslator("en-US")
print(translatorEnglish:FormatByKey("Hello_World"))Tài Liệu Tham Khảo API
Thuộc Tính
DevelopmentLanguage
Root
Phương Pháp
GetContents
GetEntries
Lợi Nhuận
Mẫu mã
Sử dụng LocalizationTable
local LocalizationService = game:GetService("LocalizationService")
local localizationTable = LocalizationService:FindFirstChild("LocalizationTable")
local entries = {
{
["Key"] = "0001",
["Source"] = "en-us",
["Values"] = {
["0001"] = "Xin chào Muddah, xin chào Fadduh.",
["0002"] = "Tôi đang ở Camp Granada.",
["0003"] = "Trại rất thú vị.",
["0004"] = "Và họ nói rằng chúng ta sẽ có chút vui vẻ nếu trời ngừng mưa.",
},
},
}
localizationTable:SetEntries(entries)
local get_results = localizationTable:GetEntries()
for _index, dict in pairs(get_results) do
for _key, value in pairs(dict["Values"]) do -- Lặp qua từng cặp khóa, giá trị trong từ điển để in chuỗi của chúng ta
print(value)
end
endGetString
GetTranslator
RemoveEntry
RemoveEntryValue
RemoveKey
RemoveTargetLocale
SetContents
SetEntries
LocalizationTable:SetEntries(entries:Variant):()
Tham Số
entries:Variant |
Lợi Nhuận
()
SetEntry
SetEntryContext
SetEntryExample
SetEntryKey
SetEntrySource