Hey, I need help from somebody on this. There are no errors in the output or anything but it still prints “Hello how are you?” instead of printing it in German. Basically, even if tried doing it it another language or translated it to the other way round, such as setting German to English it still probably wouldn’t work.
I’ve added the German language to Localization
, selected "Use Translate Content"
and all forms of "Automatic Text Capture"
have been enabled:
local LocalizationService = game:GetService("LocalizationService")
-- Load Translator for "de". Wrap the function within a pcall() to protect against failures.
local res, translator = pcall(function()
return LocalizationService:GetTranslatorForLocaleAsync("de")
end)
if res then
-- Use Translate function, providing object context and string
local sourceTranslation = translator:Translate(game, "Hello how are you?")
print(sourceTranslation)
else
print('GetTranslatorForPlayerAsync failed: ' .. translator)
end
For now this script is just a test to see if the translations work and I would eventually use it on a bigger problem, such as lots of people giving text entries through StringValues
and displaying them in TextLabels
through GUIs, but not all of this content by users is in the same language for me to read, that’s why I want to be able to translate it. I’ve looked all around on the Devforum about it but none of it has been really that helpful. I even tried testing the script in the main game to see if it was a problem with testing in studio not translating languages, but I still had the same issue.
Similarly, I have used Roblox’s method of translating by using a TextLabel
object, instead of assigning game
to avoid an “Argument 2 missing or nil
” error. Still, this method just prints “Hello World!”, instead of “Hello World!” in German:
local LocalizationService = game:GetService("LocalizationService")
local textLabel = script.Parent
local success, translator = pcall(function()
return LocalizationService:GetTranslatorForLocaleAsync("de")
end)
if success then
local result = translator:Translate(textLabel, "Hello World!")
print(result)
else
print("GetTranslatorForLocaleAsync failed: " .. translator)
end
As said before, none of this has produced any errors so I have no clue where the problem may be coming from. I am not familiar with using code to translate languages, so please let me know if I need to change anything. Am I missing something here? If anybody could help me on this particular problem, it would be greatly appreciated! Thank you.