TextService: FilterAndTranslateStringAsync

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Find out how to use this function

  1. What is the issue? Include screenshots / videos if possible!

It always returns a empty table

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried verifying all the arguments, and did not find anything on Developer Hub. I’m not sure if anyone even knows this exists

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Result = TextService:FilterAndTranslateStringAsync(message, UserId, {"es-es"}, TextFilterContext.PublicChat)

print(Result:GetTranslations()) -- empty table

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

FilterAndTranslateStringAsync() is a function of TextService. It is used to filter text and translate it between two languages. You’re correct in your assumption that this is an obscure function; there’s no documentation on it in the Developer API.

However, we can see that it exists by viewing it in the Object Browser inside Roblox Studio:


The Roblox API github tells us that this function was added 2023-05-17 11:55 so it is very very new:
image

It is so new that Roblox hasn’t even made a DevForum post about the new features!

(The update that adds this new feature is 576)


Anyways, I set up a script

to check it out and noticed that it returns a TextFilterTranslatedResult instance:

local PLR = game:GetService("Players")
local TXT = game:GetService("TextService")

PLR.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg, recipient)
		local filteredTranslate = TXT:FilterAndTranslateStringAsync(
			msg,
			plr.UserId,
			{"en-es"},
			Enum.TextFilterContext.PublicChat
		)
		print(filteredTranslate)
	end)
end)

From there we can see that TextFilterTranslateResult:GetTranslations() is not an array, but a dictionary!
image


So before trying to decode the dictionary, I checked out TextFilterTranslatedResult.SourceText:

print(filteredTranslate.SourceText)


As you can see from the output, the source text is not a string, it is a TextFilterResult. So I looked at the Object Brower reference for that and found GetChatForUserAsync(userId):
image

print(filteredTranslate.SourceText:GetChatForUserAsync(plr.UserId))

image

But this only gives us a string in our source language, English. We probably want to get the string in our target language; in this case, Spanish.


Going back to TextFilterTranslatedResult again:

It verifies that the returned data is a dictionary. However, there is no more information about it. You could have stumbled on a function that has little to no functionality yet due to its brand-new nature.

I hope this steers you in the right direction! Check the #updates:release-notes page later on, to see if they add documentation for it in version 576.

1 Like

Interesting!

I’m making a custom chat and was hoping to be able to localize each message to specific users (so every message posted in the chat window is translated to the language preferences of the LocalPlayer by the server)

At first I thought this was just an older function - I mean I think Roblox tried this out in their default chat system a few years ago but I’m not sure.

But your idea to check when it was added proves this is something new.

When I wake up tomorrow I’ll see if I can look into the TextFilterTranslatedResult and if it has been documented.