概要
方法
GetCorescriptLocalizations():Instances |
GetCountryRegionForPlayerAsync(player: Instance):string |
GetTableEntries(instance: Instance):{any} |
GetTranslatorForLocaleAsync(locale: string):Instance |
GetTranslatorForPlayer(player: Instance):Instance |
GetTranslatorForPlayerAsync(player: Instance):Instance |
API 參考
屬性
方法
GetCorescriptLocalizations
LocalizationService:GetCorescriptLocalizations():Instances
返回
Instances
GetCountryRegionForPlayerAsync
參數
返回
範例程式碼
獲取玩家的國家/地區代碼
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)
endGetTableEntries
GetTranslatorForLocaleAsync
參數
返回
範例程式碼
獲取和使用地區的翻譯器
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)
endGetTranslatorForPlayer
GetTranslatorForPlayerAsync
參數
返回
範例程式碼
獲取和使用玩家的翻譯器
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