How to translate strings via script?

So i have a filter that blocks certain phrases/words but it’s too complicated to have the filter table of 200 words and it’s hard to whitelist certain contexts. I’ve tried the solution in Automatically translate strings? but it just grabs from your translation table in your game. Is there any api i can use for this to translate? Cause it would be very nice if i could translate strings like the chat does.

I’m a bit confused on why you need to translate the strings, in order to make it easier to filter?

If there’s something that requires filtering in your game, your best bet is to just use the filtering methods Roblox provide, as it has an extensive list of things that it blocks. There’s a good chance that you would need to use the roblox provided filter anyway, in order to be fully compliant with Community Standards.

It’s a custom filter, the Roblox filter doesn’t filter some stuff.

Roblox does not provide a translation API with arbitrary strings, but you can use an external services API, such as Google Translate, DeepL, and others.

DeepL has a free API plan, take a look, it’s very generous.

use this (external api):

local HttpService = game:GetService("HttpService")

local function translate(text: string, targetLang: string)
	local url = "https://ftapi.pythonanywhere.com/translate?dl=" .. targetLang .. "&text=" .. HttpService:UrlEncode(text)
	local response = HttpService:GetAsync(url)
	local data = HttpService:JSONDecode(response)

	return data["destination-text"]
end

using this website: https://ftapi.pythonanywhere.com/

HTTP 500 (Internal Server Error)

Enable HTTP requests maybe it will work

HTTP Requests are enabled though

Have you thought of using Levenshtein distance for this? It gives you an integer distance between two strings that indicates how many “edits” you have to do to convert one string to the other(operations are defined as either insertion, deletion or substitution of letters). You could have a list of words and if what the user types has a small levenshtein distance with one of them assume they’re trying to bypass said word.

Another thing you can do is have mappings between characters of one language that might be used to bypass english characters(for example the greek Μ instead of the english M).

In general since you’re trying to make filters many of the issues can be solved through code as long you know what to look for.

My script replaces diacritics but not yet Greek letters (thanks!), but the main problem is how can i translate what players are saying? It’s very lengthy to make a massive table so i’d ratheruse a translator api somwhere, though the one Jerry listed returns HTTP 500 (perhaps roblox safety systems).

Error 500 means that the request was successful, but there was an error on the server. It could have been due to a route failure, which is actually an internal error, but some developers often use this to indicate that you made a mistake in the parameters. Based on my tests, you may have entered the language code incorrectly.

You must ensure that the language code is correct. For example, for English, you will use en, for Portuguese (from Portugal), you will use pt, and for Portuguese (from Brazil), you will use pt_br.

Oh i guess that was the problem, cause i was trying to set the destination language to English and tried typing “en-us” and “en” but it turns out you have to use underscores for the language dialect.

https://ftapi.pythonanywhere.com/languages if you want to see all possible targetLang’s

Though the translator is working but it takes few seconds to translate and that causes bugs/problems. Is this a roblox problem? I am planning on making the filter an api so i don’t have to change the filter in multiple games. Are there faster translator api or perhaps is it possible to add strings to lozalizationtable via script? (Also does roblox translate word by word e.g “Hallo” is “Hello” and “Welt” is “world” so will “Hallo Welt!” translate to “Hello world!”)

its an api so there will be limits to it in terms of speed, and roblox might be doing something too, i dont know about roblox translation, maybe you can use faster apis like deepl or something like that, but they cost money or have a limit