ScratchAddons
ScratchAddons copied to clipboard
Scratch project code translator
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
Does google translate have an API or something then? I fully agree with this and I’ve encountered stuff like this before.
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).
Yeah, but is it linked to a google account, or free use?
Yeah, but is it linked to a google account, or free use?
The calculator is estimating $10/1,000,000 characters.
In theory we could emulate the "translate text" block from the Scratch editor extension... I wonder how Scratch prevents that API from getting abused.
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...
Local translation models need 100+ MB to work though
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?
I don’t think anyone wants to pay for this…
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.
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.
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.
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.
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!
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.
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.
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!
-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.
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.
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.
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...)
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.
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...
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.
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.
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.
I remember something called yandextranslate, a free translation api: https://rapidapi.com/zakutynsky/api/YandexTranslate/
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?
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.
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.