Help with localizing strings that change constantly

Hello!

I’m wondering how I would go about translating a string that constantly changes.

For example, this code:

local replicatedFirst = script.Parent
local contentProvider = game:GetService('ContentProvider')
local players = game:GetService('Players')
local playerUI = players.LocalPlayer.PlayerGui

replicatedFirst:RemoveDefaultLoadingScreen()

local UI = Instance.new('ScreenGui', playerUI)
UI = Instance.new('Frame', UI)
UI.Size = UDim2.new(1,0,2,0)
UI.Position = UDim2.new(0,0,-1,0)
UI = Instance.new('TextLabel')
UI.Text = 'Waiting for assets'
UI.Size = UDim2.new(1,0,0.5,0)
UI.Position = UDim2.new(0,0,0.5,0)
UI.TextSize = 40
UI.AutoLocalize = true
UI.Visible = true
UI.BackgroundColor3 = Color3.new(1,1,1)
UI.TextXAlignment = 'Center'
UI.TextYAlignment = 'Center'

local assetsToPreLoad = {}

for i,v in ipairs(game:GetChildren()) do
    local s,e = pcall(function()
        service = game:GetService(v.Name)
    end)
    if s then
        table.insert(assetsToPreLoad, #assetsToPreLoad + 1, service)
    end
end

local t = {
    [1] = '.';
    [2] = '..';
    [3] = '...';
}

for i = 1, math.huge do
    UI.Text = 'Waiting for assets'..t[(i % 3) + 1]
    wait(.5)
end

The text changes to ‘Waiting for assets.’, ‘…’, ‘…’

The problem is that when translating, it should change to ‘En attente des objets de jeu.’, ‘…’, ‘…’ but it stays in English.

Now, when I make it say ‘Waiting for assets’ and keep the text the same, it translates properly.

Any help?

Have you read Roblox’s complete tutorial on Localization?

Be sure that you enable the translated text in settings

1 Like

Yep. The problem only happens when the string changes constantly. If it stays the same, it will translate as expected.

This may be a bug or just that autolocalization only runs when instancing a GUI element. To manually translate text, take a look at the Translator class. I am using the function Translate(context, string) to localize the string. I’m quite new to Localization myself but this is the best I could do. Refer to the Localization tutorial for more info.

here is an example shown

local LocalizationService = game:GetService("LocalizationService")
local player = game.Players.LocalPlayer
local playerTranslator

local foundPlayerTranslator = pcall(function()
	playerTranslator = LocalizationService:GetTranslatorForPlayerAsync(player)
end)


--code


local t = {'.', '..', '...'}
local msg = 'Waiting for assets'

if foundPlayerTranslator then
    msg = playerTranslator:Translate(game, msg)
end

for i = 1, math.huge do
    UI.Text = msg .. t[(i % 3) + 1]
    wait(.5)
end
1 Like

Yeah, this should work. Thanks so much! I thought the translated string would just archive similarly to how :GetNameFromUserId() would, but guess not haha.