LocalizationService

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
服务
未复制

本地化服务是负责处理自动翻译的服务。

它用作自动文本替换使用的 LocalizationTable 对象的存储。

本地化服务只会使用其子本地化表格来自动替换文本,除非在 GUI 对象或其祖先上指定 GuiBase2d.RootLocalizationTable

概要

属性

方法

属性

RobloxLocaleId

只读
未复制
读取并联

SystemLocaleId

只读
未复制
读取并联

方法

GetCorescriptLocalizations

Instances

返回

Instances

GetTableEntries

参数

instance: Instance
默认值:"nil"

返回

GetTranslatorForPlayer

参数

player: Instance
默认值:""

返回

代码示例

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

暂停

参数

player: Instance
默认值:""

返回

代码示例

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

暂停

参数

locale: string
默认值:""

返回

代码示例

获取并使用本地翻译器

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

暂停

参数

player: Instance
默认值:""

返回

代码示例

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

活动