本地化服務是負責處理自動翻譯的服務。
它用於自動文字替換使用的 LocalizationTable 對象的儲存。
本地化服務只會使用其子本地化表格來自動替換文字,除非在 GUI 對象或其祖先上指定 GuiBase2d.RootLocalizationTable 。
概要
屬性
用於本地化核心和內部功能的本地 ID。
本地玩家為其操作系統設置的本地ID。
方法
返回一個列表的 LocalizationTable 對象,用於本地化核心腳本。
獲得所有用於自動本在地化的入口。
返回 Translator 用於使用載入的本地資料進行翻譯。
根據玩家的客戶端 IP 地理定位返回國家/地區代碼字串。
直到雲端 LocalizationTable 為論據本地載入了 - 如果可用。返回一個 Translator 實例,用於提供的本地進行翻譯。
直到雲端 LocalizationTable 為玩家的本地載入 - 如果可用。返回一個 Translator 實例,用於提供的本地進行翻譯。
屬性
方法
GetCorescriptLocalizations
Instances
返回
Instances
GetTranslatorForPlayer
參數
預設值:""
返回
範例程式碼
Getting and Using a Translator for a Player
local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")
local textLabel = script.Parent
local success, translator = pcall(function()
return LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer)
end)
if success then
local result = translator:Translate(textLabel, "Hello World!")
print(result)
else
print("GetTranslatorForPlayerAsync failed: " .. translator)
end
GetCountryRegionForPlayerAsync
參數
預設值:""
返回
範例程式碼
Getting Country/Region Code for a Player
local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local result, code = pcall(LocalizationService.GetCountryRegionForPlayerAsync, LocalizationService, player)
if result and code == "CA" then
print("Hello, friend from Canada!")
else
print("GetCountryRegionForPlayerAsync failed: " .. code)
end
GetTranslatorForLocaleAsync
參數
預設值:""
返回
範例程式碼
Getting and Using a Translator for a Locale
local LocalizationService = game:GetService("LocalizationService")
local textLabel = script.Parent
local success, translator = pcall(function()
return LocalizationService:GetTranslatorForLocaleAsync("fr")
end)
if success then
local result = translator:Translate(textLabel, "Hello World!")
print("Hello in French: " .. result)
else
print("GetTranslatorForLocaleAsync failed: " .. translator)
end
GetTranslatorForPlayerAsync
參數
預設值:""
返回
範例程式碼
Getting and Using a Translator for a Player
local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")
local textLabel = script.Parent
local success, translator = pcall(function()
return LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer)
end)
if success then
local result = translator:Translate(textLabel, "Hello World!")
print(result)
else
print("GetTranslatorForPlayerAsync failed: " .. translator)
end