Chris (now @chris@toot.works) is a user on mastodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Chris (now @chris@toot.works) @cs

Hi everyone! I made a translator bot that translates statuses it's mentioned in.

To use it, mention @translator (translator@toot.works) in your status, followed by the two-letter code for the language you want to translate to (e.g. "ja" for Japanese) (full list of possible codes here: christopher.su/projects/transl). It uses English if no language is given.

Give it a try and toot me your suggestions and comments!

@translator ja

· Web · 169 · 164

@jeroensmeets [en] good idea, @cs @ mastodon. social! Which API do you use?

@cs [nl] @jeroensmeets ik ben met behulp van de API Microsoft vertaling!

@cs @translator @jeroensmeets Minor #privacy drawback is that all toots will be run through and stored by trackers. 😟

@metbril @jeroensmeets It is a paid API, so it might be slightly better. I haven't really looked too far into how source input can be used.

@cs Never mind. It's my personal choice to use it, or not. Keep up the good work.

@jeroensmeets

@metbril @cs for my app I'm also looking at translation, built a first version on Google's API. Wasn't too impressed, this looks promising.

To cover costs I'm thinking about making it an in app purchase, so that would handle the choice to use it.

@jeroensmeets @metbril Built-in translation in a client would be pretty awesome. I was thinking you might be able to build some kind of caching server to avoid having to perform the same translations more than once, thus saving you some cost, but then you'd need server-side code for that.

@cs @metbril true. For now I just added a button to translate a toot with a cache or switch back to the original content.

All the html in the content is a pain in the butt, especially because my platform (fusetools) doesn't have a richtext component yet.

@jeroensmeets @metbril Parsing from the HTML status content returned by the API was a huge pain for this bot as well. I wish the API would just include some plain text version of statuses.

@cs @metbril yes, had to write a small library to parse the content into clean text, into an array of clean paragraphs and an array of words with extra data how to handle appearance and click.

11t now displays the timeline as paragraphs of clean text, and when you click a toot, you get a mock richtext view of the toot where usernames, links and hashtags are bold and clickable. It's far from perfect.

@jeroensmeets @cs Guys. Now that you're discussing app development I don't mind being out of the loop. :wink:

@cs i just favourited a post by @translator to make it feel good about itself.

@jeroensmeets [to] @cs 'oku ou favourited pe na'e fai ia 'e ha fu'u pou 'e ongo'i lelei fekau'aki mo ia.

@adam [ja] @cs @translator は、インスタンス間でこの作業を行います?

@cs Ah. The fourth account :P

I assume it won't translate toots that are forwarded to it (i.e. someone replies to a toot and tags the bot), correct?

@jbbdude It does right now, which is kind of problematic... next item to fix is not tooting when the source language and translated language are the same.

@cs Wait, so if I reply to a foreign language toot (say, in Japanese) with "@translator en" it would translate the previous toot? That's amazing!

@cs that's awesome. Thanks for making a bot I don't hate

@cs imagine being able to send it a permalink to a toot and have it parse the toot contents

@mig5 That's a good idea! Another suggestion has been to have some command that requests a translation of the parent toot (e.g. I see your toot in another language, I reply with a translator command, it replies with a translation of your toot).

@cs Would there be any chance of extending that to translate the /parent/ post into some specified language?

Say:

@translator parent fr

@dredmorbius Yeah, this has been the most requested feature now. I didn't add it in at first, because I didn't want spam notifications at the parent toot posters, but I suppose it wouldn't be too bad. Considering adding it! I would have to make it respect , probably.

@cs You could have translate bot /not/ mention the author of a toot.

@dredmorbius Would do that for sure. I wonder if Mastodon might still send a notification to the author though. It might look at the parent toot id, check that toot, and then send a notification to its author. Need to manually test a reply toot that doesn't mention the author and see if it still notifies.

@cs My understanding is that Notifs occur /only/ if the user is directly mentioned, or of a toot is favourited or boosted.

Otherwise, a post is added to a thread, but there's no notification generated.

@dredmorbius Actually, another problem with this: the toot.works instance is essentially a single-user (+bots) instance. If the parent toot isn't federated to the instance, I'm not sure if the bot can fetch the parent toot's content to translate it. Any idea on how to fix it?

When browsing my timeline on toot.works, I frequently click on toots that are replies and I can't see the parent toot :/

@chris You might need to work around that. I'm not sure what the bot API looks like but:

1. Open the requestor's local instance of the request (e.g., <instance>/@<requestor>/<post-ID>
2. Look at the parent post, which should be the original.
3. Grab its timeline URL.
4. Search that on the bot instance. This adds the post to that instance.

I don't know that there's a streamlined way of doing this, but it would include the parent work, if you can make this happen.

@dredmorbius Ah, using the instance search through the API to pull in the post to the instance is brilliant. I hadn't thought of that.

Another approach that I thought of that could work: the "Get a status" API endpoint was changed to not require authentication in one of the more recent versions, so I could try calling that API directly on the other instance. Would only work if the other instance was on a new enough version that the API didn't require auth though.

@webmind Yea, here, it didn't properly translate to Japanese because the mention on my toot was actually @translator on my local instance rather than @translator on the toot.works instance. I was tooting from the .social instance there.

@translator ja

@cs [ja] @webmind また、それはバギーだけの種類: p

A new translator bot? That's awesome! @translator fr

@Tryphon [fr] Un nouveau bot de traducteur ? C'est génial !

@cs That's awesome! Is it based on the Google API (or similar), or your own implementation?

@Tryphon It's using a Microsoft Translation API, so similar to that :)

.@cs Are you making a local server-side implementation using something like Moses, Phrasal or Joshua next? Not to be greedy 😂

@cs Nice work! I had lots of fun with it... 😂

@cs I think this should be integrated into the UI, honestly. I don't want to toot something to get a translation and I *really* love "translate this"-buttons in other webapps :)