本地化服务是负责处理自动翻译的服务。
它用作自动文本替换使用的 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
参数
默认值:""
返回
代码示例
获取并使用本地翻译器
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