ScratchAddons icon indicating copy to clipboard operation
ScratchAddons copied to clipboard

Scratch project code translator

Open DNin01 opened this issue 1 year ago • 43 comments
trafficstars

Why this would be helpful

I found a project and wanted to do some remixing, but all the variable, list, broadcast, and other names were in a different language, so it was difficult to navigate the code.

How this addon works

A new addon that could translate names of at least variables, lists, broadcasts, custom blocks, and sprites would be very helpful to anyone who is working with a project created by someone who writes in a different language. Somewhere there would be an option to translate all of those names with a service like Google Translate to another language.

The translated names could be visual only and not actually be renamed internally if possible, which would prevent your own projects from getting corrupted (we don't want this addon to do something that can't be undone, at least not without a warning).

Possible alternatives

No response

Additional context

No response

DNin01 avatar Apr 04 '24 23:04 DNin01

Does google translate have an API or something then? I fully agree with this and I’ve encountered stuff like this before.

BlueGoat11 avatar Apr 05 '24 13:04 BlueGoat11

Does google translate have an API or something then? I fully agree with this and I’ve encountered stuff like this before.

Probably, considering all the other applications that have translation stuff built-in (including Scratch, with the Translate extension).

CST1229 avatar Apr 05 '24 13:04 CST1229

Yeah, but is it linked to a google account, or free use?

BlueGoat11 avatar Apr 05 '24 14:04 BlueGoat11

Yeah, but is it linked to a google account, or free use?

The calculator is estimating $10/1,000,000 characters.

BroJac5246 avatar Apr 05 '24 14:04 BroJac5246

In theory we could emulate the "translate text" block from the Scratch editor extension... I wonder how Scratch prevents that API from getting abused.

WorldLanguages avatar Apr 05 '24 14:04 WorldLanguages

If we use Google Translate API and someone enables this addon on turbowarp desktop and they're offline, it won't work! We will have to use some kind of local library for the translation. Something like https://github.com/LibreTranslate/LibreTranslate perhaps...

Waakul avatar Apr 05 '24 14:04 Waakul

Local translation models need 100+ MB to work though

WorldLanguages avatar Apr 05 '24 14:04 WorldLanguages

If we use Google Translate API and someone enables this addon on turbowarp desktop and they're offline, it won't work!

We can provide an error pop-up instead or ask GarboMuffin to not include it if need be.

Speaking of Turbowarp, @GarboMuffin does Turbowarp use Scratch's Google Translate API? If so, do you know how we could use that?

BroJac5246 avatar Apr 05 '24 15:04 BroJac5246

I don’t think anyone wants to pay for this…

BlueGoat11 avatar Apr 05 '24 15:04 BlueGoat11

There's a package for google translate (non-official) for js: @vitalets/google-translate-api which is free. but we'll need to add host permissions to https://translate.google.com/, if we do so the extension will be disabled for everyone until they allow this permission.

NOTE: Please note that @vitalets/google-translate-api's repo's ReadMe file has a disclaimer that say's to use the official API (which is paid) to be 100% legal and that it's for pet projects or prototyping.

Waakul avatar Apr 05 '24 18:04 Waakul

I'm buying a server soon. I could host a LibreTranslate API there. Note that this would also require to add a host permission pointing to the API's port on the server but at least it's legal.

Waakul avatar Apr 05 '24 18:04 Waakul

I'm buying a server soon. I could host a LibreTranslate API there. Note that this would also require to add a host permission pointing to the API's port on the server but at least it's legal.

If we send requests from Scratch webpages, I believe we don't have to request host permissions, but it should still be disclosed by the addon and our privacy policy.

DNin01 avatar Apr 05 '24 18:04 DNin01

I wonder how Scratch prevents that API from getting abused.

It doesn't - you can access it by typing the URL into the address bar.

mxmou avatar Apr 05 '24 19:04 mxmou

If we send requests from Scratch webpages, I believe we don't have to request host permissions

Well, if we need to bypass CORS, then we do need new host permissions. Of course, if we're sending a request to a server we control, we can always set up CORS correctly. I don't know why we're talking about Google Translate and running our own servers though, when Scratch itself offers the API we want!

WorldLanguages avatar Apr 06 '24 16:04 WorldLanguages

If we send requests from Scratch webpages, I believe we don't have to request host permissions

Well, if we need to bypass CORS, then we do need new host permissions. Of course, if we're sending a request to a server we control, we can always set up CORS correctly. I don't know why we're talking about Google Translate and running our own servers though, when Scratch itself offers the API we want!

Scratch's API has a filter that isn't always accurate. Also, what if someone puts stuff against the CG in code? The addon's duty is to translate with not a single filter.

Waakul avatar Apr 06 '24 16:04 Waakul

If we send requests from Scratch webpages, I believe we don't have to request host permissions

Well, if we need to bypass CORS, then we do need new host permissions. Of course, if we're sending a request to a server we control, we can always set up CORS correctly. I don't know why we're talking about Google Translate and running our own servers though, when Scratch itself offers the API we want!

Scratch's API has a filter that isn't always accurate. Also, what if someone puts stuff against the CG in code? The addon's duty is to translate with not a single filter.

The Scratch API is free and since the filter is imposed by Scratch, it will be consistent with existing Scratch behavior.

BroJac5246 avatar Apr 06 '24 18:04 BroJac5246

If we send requests from Scratch webpages, I believe we don't have to request host permissions

Well, if we need to bypass CORS, then we do need new host permissions. Of course, if we're sending a request to a server we control, we can always set up CORS correctly. I don't know why we're talking about Google Translate and running our own servers though, when Scratch itself offers the API we want!

Scratch's API has a filter that isn't always accurate. Also, what if someone puts stuff against the CG in code? The addon's duty is to translate with not a single filter.

The Scratch API is free and since the filter is imposed by Scratch, it will be consistent with existing Scratch behavior.

Variable names, custom blocks, list names..., etc Aren't filtered!

Waakul avatar Apr 06 '24 18:04 Waakul

-snip- Scratch's API has a filter that isn't always accurate. Also, what if someone puts stuff against the CG in code? The addon's duty is to translate with not a single filter.

The Scratch API is free and since the filter is imposed by Scratch, it will be consistent with existing Scratch behavior.

Variable names, custom blocks, list names..., etc Aren't filtered!

If there's something that should be filtered out but isn't then it's probably for the better if we don't translate it, then.

BroJac5246 avatar Apr 06 '24 18:04 BroJac5246

If we send requests from Scratch webpages, I believe we don't have to request host permissions

Well, if we need to bypass CORS, then we do need new host permissions. Of course, if we're sending a request to a server we control, we can always set up CORS correctly. I don't know why we're talking about Google Translate and running our own servers though, when Scratch itself offers the API we want!

Scratch's API has a filter that isn't always accurate. Also, what if someone puts stuff against the CG in code? The addon's duty is to translate with not a single filter.

The filter that the translate extension uses is mostly just there to catch swears in case those somehow show up in results. ...though it actually fails to catch a few swear words (the BS one, for example)

I get what you're saying, but I don't think we should fixate on it, at least not if we have no other good API options. This is almost never going to be a problem anyway.

DNin01 avatar Apr 06 '24 19:04 DNin01

we'll need to add host permissions to https://translate.google.com/, if we do so the extension will be disabled for everyone until they allow this permission.

We could use optional host permissions instead, then we'd only need to ask for anything when the user enables the addon.

DNin01 avatar Apr 10 '24 01:04 DNin01

What I just said:

I don't know why we're talking about Google Translate and running our own servers though, when Scratch itself offers the API we want!

(Don't say it's because we want variables named "fuck" to be translatable...)

WorldLanguages avatar Apr 10 '24 16:04 WorldLanguages

Translating all the variables and text of a project with a translation service costs money, so the two options would either be to use the Scratch API, or to give a copy and pastable list of named items in the project file that a user can copy into google translate then, copy back to do the translation.

If we used scratch api, we should reduce number of api calls to avoid abusing the api. They allow maximum 1028 characters so. You can probably just insert everything as a list and convert them all in one or a few goes.

Joeclinton1 avatar Apr 12 '24 11:04 Joeclinton1

Translating all the variables and text of a project with a translation service costs money, so the two options would either be to use the Scratch API, or to give a copy and pastable list of named items in the project file that a user can copy into google translate then, copy back to do the translation.

If we used scratch api, we should reduce number of api calls to avoid abusing the api. They allow maximum 1028 characters so. You can probably just insert everything as a list and convert them all in one or a few goes.

Umm uhh, what if we host our own translation service? I'm getting a server soon so...

Waakul avatar Apr 12 '24 11:04 Waakul

Translating all the variables and text of a project with a translation service costs money, so the two options would either be to use the Scratch API, or to give a copy and pastable list of named items in the project file that a user can copy into google translate then, copy back to do the translation. If we used scratch api, we should reduce number of api calls to avoid abusing the api. They allow maximum 1028 characters so. You can probably just insert everything as a list and convert them all in one or a few goes.

Umm uhh, what if we host our own translation service? I'm getting a server soon so...

You have no idea the cost or complexity of a good translation service do you? Additionally the functionality of the addon cannot depend on some questionable local server. That's such a bad idea.

Joeclinton1 avatar Apr 12 '24 11:04 Joeclinton1

Translating all the variables and text of a project with a translation service costs money, so the two options would either be to use the Scratch API, or to give a copy and pastable list of named items in the project file that a user can copy into google translate then, copy back to do the translation.

If we used scratch api, we should reduce number of api calls to avoid abusing the api. They allow maximum 1028 characters so. You can probably just insert everything as a list and convert them all in one or a few goes.

Umm uhh, what if we host our own translation service? I'm getting a server soon so...

Why would we do that, though, when Scratch's API is free? Also, how powerful is your server, and do you have an internet connection that can keep up? And how do you intent to protect against DDoS attacks? Pay extra for Cloudflare?

Additionally, your server could be blocked by some school networks, while Scratch's should remain accessible.

Also, W_L made it clear that he thinks we should use Scratch's API.

BroJac5246 avatar Apr 12 '24 11:04 BroJac5246

Translating all the variables and text of a project with a translation service costs money, so the two options would either be to use the Scratch API, or to give a copy and pastable list of named items in the project file that a user can copy into google translate then, copy back to do the translation. If we used scratch api, we should reduce number of api calls to avoid abusing the api. They allow maximum 1028 characters so. You can probably just insert everything as a list and convert them all in one or a few goes.

Umm uhh, what if we host our own translation service? I'm getting a server soon so...

Why would we do that, though, when Scratch's API is free? Also, how powerful is your server, and do you have an internet connection that can keep up? And how do you intend to protect against DDoS attacks? Pay extra for Cloudflare?

Additionally, your server could be blocked by some school networks, while Scratch's should remain accessible.

Pretty powerful, it will be kept in a server room with efficient cooling and also be monitored by IT professionals. And cloudflare's ddos attack protection is free right? I do agree that schools might be blocked but if so, then even scratchaddons would probably be blocked. We could also explore free apis tho.

Waakul avatar Apr 12 '24 11:04 Waakul

I remember something called yandextranslate, a free translation api: https://rapidapi.com/zakutynsky/api/YandexTranslate/

Waakul avatar Apr 12 '24 11:04 Waakul

You can probably just insert everything as a list and convert them all in one or a few goes.

How context-sensitive is the algorithm? Will we be able to do that or would have to make a separate request for each entry?

DNin01 avatar Apr 12 '24 18:04 DNin01

You can probably just insert everything as a list and convert them all in one or a few goes.

I Google Translate charges per character, if that's a consideration. I don't know if Scratch has the fee waved or not.

BroJac5246 avatar Apr 12 '24 19:04 BroJac5246

You can probably just insert everything as a list and convert them all in one or a few goes.

How context-sensitive is the algorithm? Will we be able to do that or would have to make a separate request for each entry?

It's very context sensitive. Almost anything you use to delimt the sentences will have edge cases where it accidently merges the two. However I found %0A (the Line Feed symbol) has the magic ability to delimit anything.

Here's an example: https://translate-service.scratch.mit.edu/translate?language=fr&text=The%0Acat%0Aslept%0Asoundly%0Aon%0Athe%0Asunlit%0Awindowsill.

This returns {"result":"Le\nchat\ndormi\nsainement\nsur\nle\nensoleillé\nrebord de fenêtre."}

Using anything else will fail here.

The \n can then easily be used as the delimiter to split on. It might seem like translations of \n would cause problems but the backslash outputs to \\ so you can distinguish them.

Also tested in various languages and it works.

Joeclinton1 avatar Apr 16 '24 21:04 Joeclinton1