2025-07-18 01:11:49 +08:00
|
|
|
|
-- 本地化读取工具
|
2025-07-16 00:45:20 +08:00
|
|
|
|
local Localization = {}
|
|
|
|
|
|
|
|
|
|
--> Services
|
|
|
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
|
|
local LocalizationService = game:GetService("LocalizationService")
|
|
|
|
|
|
|
|
|
|
--> Modules
|
|
|
|
|
local Utils = require(ReplicatedStorage.Tools.Utils)
|
|
|
|
|
|
|
|
|
|
--> Json
|
|
|
|
|
local JsonLanguage_En_US = require(ReplicatedStorage.Json.Language_En_US)
|
|
|
|
|
local JsonLanguage_Zh_CN = require(ReplicatedStorage.Json.Language_Zh_CN)
|
|
|
|
|
local JsonImage_En_US = require(ReplicatedStorage.Json.Image_En_US)
|
|
|
|
|
local JsonImage_Zh_CN = require(ReplicatedStorage.Json.Image_Zh_CN)
|
|
|
|
|
|
2025-08-01 19:23:12 +08:00
|
|
|
|
local JsonParam = require(ReplicatedStorage.Json.Param)
|
|
|
|
|
|
2025-07-16 00:45:20 +08:00
|
|
|
|
--> Variables
|
|
|
|
|
local LocalPlayer = game.Players.LocalPlayer
|
2025-07-18 01:11:49 +08:00
|
|
|
|
local SystemLocaleId = LocalizationService.SystemLocaleId
|
2025-07-16 00:45:20 +08:00
|
|
|
|
|
2025-08-01 19:23:12 +08:00
|
|
|
|
--> Color
|
|
|
|
|
local QUALITY_COLOR = {
|
|
|
|
|
[1] = Color3.fromRGB(255, 255, 255), -- 白色
|
|
|
|
|
[2] = Color3.fromRGB(0, 255, 0), -- 绿色
|
|
|
|
|
[3] = Color3.fromRGB(0, 150, 255), -- 蓝色
|
|
|
|
|
[4] = Color3.fromRGB(150, 0, 255), -- 紫色
|
|
|
|
|
[5] = Color3.fromRGB(255, 150, 0), -- 橙色
|
|
|
|
|
[6] = Color3.fromRGB(255, 0, 0), -- 红色
|
|
|
|
|
[7] = Color3.fromRGB(255, 215, 0), -- 金色
|
|
|
|
|
[8] = Color3.fromRGB(255, 0, 255), -- 粉色
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-16 00:45:20 +08:00
|
|
|
|
-- 获取本地Json文件
|
|
|
|
|
function Localization:GetLocalizationJson()
|
|
|
|
|
if SystemLocaleId == "zh-CN" then
|
|
|
|
|
return JsonLanguage_Zh_CN, JsonImage_Zh_CN
|
|
|
|
|
else
|
|
|
|
|
return JsonLanguage_En_US, JsonImage_En_US
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-18 01:11:49 +08:00
|
|
|
|
local JsonLanguage, JsonImage = Localization:GetLocalizationJson()
|
|
|
|
|
|
2025-07-16 00:45:20 +08:00
|
|
|
|
-- 获取文本Id数据
|
|
|
|
|
function Localization:GetLanguageData(Id: number)
|
|
|
|
|
if not Id then return end
|
2025-07-19 03:03:02 +08:00
|
|
|
|
local data = Utils:GetIdDataFromJson(JsonLanguage, Id)
|
|
|
|
|
if not data then return "" end
|
|
|
|
|
return data.text
|
2025-07-16 00:45:20 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 获取图片Id数据
|
|
|
|
|
function Localization:GetImageData(Id: number)
|
2025-07-23 01:04:27 +08:00
|
|
|
|
if not Id then return "" end
|
2025-07-19 03:03:02 +08:00
|
|
|
|
local data = Utils:GetIdDataFromJson(JsonImage, Id)
|
|
|
|
|
if not data then return "" end
|
|
|
|
|
return data.sourceId
|
2025-07-16 00:45:20 +08:00
|
|
|
|
end
|
|
|
|
|
|
2025-08-01 19:23:12 +08:00
|
|
|
|
-- 获取装备品质描述
|
|
|
|
|
function Localization:GetEquipmentQualityDesc(Quality: number)
|
|
|
|
|
local qualityData = Utils:GetSpecialKeyDataFromJson(JsonParam, "key", "quality_show")
|
|
|
|
|
if not qualityData then return "" end
|
|
|
|
|
local languageData = Utils:GetSpecialKeyDataFromJson(JsonLanguage, "id", qualityData.intArray[Quality])
|
|
|
|
|
if not languageData then return "" end
|
|
|
|
|
local language = languageData.text
|
|
|
|
|
return language
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 将Color3转换为十六进制字符串
|
|
|
|
|
local function Color3ToHex(color: Color3): string
|
|
|
|
|
local r = math.floor(color.R * 255)
|
|
|
|
|
local g = math.floor(color.G * 255)
|
|
|
|
|
local b = math.floor(color.B * 255)
|
|
|
|
|
return string.format("#%02X%02X%02X", r, g, b)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 根据quality获取带颜色包装的文本
|
|
|
|
|
function Localization:GetColoredTextByQuality(quality: number, text: string): string
|
|
|
|
|
if not quality or not text then return text or "" end
|
|
|
|
|
|
|
|
|
|
local color = QUALITY_COLOR[quality]
|
|
|
|
|
if not color then return text end
|
|
|
|
|
|
|
|
|
|
local hexColor = Color3ToHex(color)
|
|
|
|
|
return string.format('<font color="%s">%s</font>', hexColor, text)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 根据quality获取装备品质描述(带颜色)
|
|
|
|
|
function Localization:GetColoredEquipmentQualityDesc(Quality: number): string
|
|
|
|
|
local qualityData = Utils:GetSpecialKeyDataFromJson(JsonParam, "key", "quality_show")
|
|
|
|
|
if not qualityData then return "" end
|
|
|
|
|
local languageData = Utils:GetSpecialKeyDataFromJson(JsonLanguage, "id", qualityData.intArray[Quality])
|
|
|
|
|
if not languageData then return "" end
|
|
|
|
|
local language = languageData.text
|
|
|
|
|
|
|
|
|
|
return self:GetColoredTextByQuality(Quality, language)
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-16 00:45:20 +08:00
|
|
|
|
return Localization
|