LocalizationService

顯示已棄用項目

*此內容是使用 AI(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
預設值:""

返回

範例程式碼

Getting and Using a Translator for a Locale

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

活動