Localization Service
概要
方法
GetCorescriptLocalizations():Instances |
GetCountryRegionForPlayerAsync(player: Instance):string |
GetTableEntries(instance: Instance):{any} |
GetTranslatorForLocaleAsync(locale: string):Instance |
GetTranslatorForPlayer(player: Instance):Instance |
GetTranslatorForPlayerAsync(player: Instance):Instance |
API 參考
屬性
方法
Get Corescript Localizations
Localization Service: Get Corescript Localizations():Instances
返回
Instances
Get Country Region For Player Async
參數
返回
範例程式碼
獲取玩家的國家/地區代碼
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("你好,來自加拿大的朋友!")
else
print("GetCountryRegionForPlayerAsync 失敗: " .. code)
endGet Table Entries
Get Translator For Locale Async
參數
返回
範例程式碼
獲取和使用地區的翻譯器
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("法語的你好: " .. result)
else
print("GetTranslatorForLocaleAsync 失敗: " .. translator)
endGet Translator For Player
Get Translator For Player Async
參數
返回
範例程式碼
獲取並使用玩家的翻譯器
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