概要
方法
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, "你好,世界!")
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, "你好,世界!")
print(result)
else
print("GetTranslatorForPlayerAsync 失败:" .. translator)
end