local NotificationsModule = {}
local LocalService = game:GetService("LocalizationService")
local function translate(text,plr)
local translator = LocalService:GetTranslatorForPlayerAsync(plr)
local success, result = pcall(function()
return translator:TranslateAsync(text)
end)
return success and result or text
end
-- ONLY CONFIG
local POSITIONS = {
Hidden = UDim2.new(0.5, 0, 1.2, 0),
Top = UDim2.new(0.5, 0, 0.194, 0),
Middle = UDim2.new(0.5, 0, 0.531, 0),
Bottom = UDim2.new(0.5, 0, 0.865, 0)
}
-- DONT TOUCH BELOW
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local function tween(object, props)
TweenService:Create(object, tweenInfo, props):Play()
end
local function shiftUp(ui)
local bottom, middle, top
for _, notif in ipairs(ui:GetChildren()) do
if notif:IsA("Frame") and notif.Name == "Notification" then
if notif.Position == POSITIONS.Bottom then bottom = notif end
if notif.Position == POSITIONS.Middle then middle = notif end
if notif.Position == POSITIONS.Top then top = notif end
end
end
if top then
top:Destroy()
end
if middle then
tween(middle, {Position = POSITIONS.Top})
end
if bottom then
tween(bottom, {Position = POSITIONS.Middle})
end
end
local queues, processing = {}, {}
local function processQueue(plr)
if processing[plr] then return end
processing[plr] = true
while queues[plr] and #queues[plr] > 0 do
local data = table.remove(queues[plr], 1)
local ui = plr:WaitForChild("PlayerGui"):WaitForChild("GameUI")
:WaitForChild("Holder"):WaitForChild("NotificationFrame")
shiftUp(ui)
local notification = ui.Template:Clone()
notification.Name = "Notification"
notification.Visible = true
notification.Inner.Header.Text = translate(data.title,plr)
notification.Inner.Contents.Text = translate(data.desc,plr)
notification.Parent = ui
notification.Position = POSITIONS.Hidden
tween(notification, {Position = POSITIONS.Bottom})
local s = script.Notification:Clone()
s.Parent = ui
s:Play()
game:GetService("Debris"):AddItem(s, s.TimeLength + 1)
task.delay(5, function()
if notification and notification.Parent then
notification:Destroy()
end
end)
task.wait(0.7)
end
processing[plr] = false
end
function NotificationsModule:Notify(plr, title, desc)
queues[plr] = queues[plr] or {}
table.insert(queues[plr], {title = title, desc = desc})
processQueue(plr)
end
return NotificationsModule
The code above is incharge of my Notification Module, which is a massive part of my game.
I want to make my game include translations, so as you can see. I made a function which grabs the id and translates it accordingly.
I tested this in-game, and if I switch my language in the player settings to Italian, it refuses to translate to Italian, instead it stays english.
It is my first time using LocalizationService, so my bad for a lack of understanding