wordpress-activitypub icon indicating copy to clipboard operation
wordpress-activitypub copied to clipboard

Dealing with translations on a site with mulitple languages

Open ghost opened this issue 2 years ago • 18 comments

Dealing with translations might become necessary, and it might be done via different approaches. As there are not too many widely used translation plugins there might be solutions that work for most users.

Easy first step solution: Select/choose languages that should be published via ActivityPub in the settings.

More advanced solution: Create some sort of group actors that publish certain languages.

#multilang

ghost avatar Jul 31 '23 09:07 ghost

FYI: https://wordpress.org/support/topic/post-language-seems-to-default-to-blog-default/

pfefferle avatar Jul 31 '23 19:07 pfefferle

Just for reference: I did a dirty and hardcoded hack so that one of the sites I manage with PolyLang installed only sends English posts as activity. https://github.com/Menrath/wordpress-activitypub/commit/8fe1a1ac7a19a499260c9c01bca970d0a973a45b

Menrath avatar Oct 02 '23 07:10 Menrath

For me, the core basic functionality for multilingual support would be to set the language of the ActivityPub's content to match that of the blog's post. In this way, the post would be federated with the correct language tag. This allows followers to filter out posts in specific languages if they want to (like it's possible on Mastodon).

Since each WP multilingual plugin handles language differently, one solution is creating compatibility classes like class-multilingual or class-polylang (or other plugins) as described by @pfefferle, where the post's language can be discovered using plugin-specific functions like pll_get_post_language from Polylang. And then the language can be passed on to the "@context": ["https://www.w3.org/ns/activitystreams", {"@language": "en"}] in the ActivityPub object.

I might be completely off track here (sorry, only rudimentary php and activitypub knowledge), but what do you think?

bruvellu avatar Jan 09 '24 23:01 bruvellu

I can see use cases where it would be better not pass the language information via @language but use the contentMap instead. As many multilingual plugins save an extra post for each translation this would require only creating a single activity for multiple posts.

But that depends on whether you aim for one object to receive all replies and likes or actually prefer having multiple activities for each language.

As you see there are many solutions for this problem. People should try to build a solution for their needs, and then we can see whether there are missing hooks/filters to fulfill their needs.

Of course one can also make new settings pages and add a proper management of this functionality, but I would do this in a second step. At the same time for the project I do some infrastructure work I am currently fine with my hot-fix.

Menrath avatar Jan 10 '24 09:01 Menrath

Something I just thought. Would it be possible to set the ActivityPub object's language using a filter placed in the functions.php? That way, the logic of getting the post's language would be up to the site's owner, which makes sense since each site and multilingual plugin is different.

bruvellu avatar Jan 11 '24 20:01 bruvellu

It totally is possible, but I did not fully understand, what you would prefer.

Menrath avatar Jan 13 '24 11:01 Menrath

Hey, I had another look into this and maybe the issue lies elsewhere.

For clarity, I post in different languages, and it's fine for me that the objects and associated replies, likes, etc., remain separate for each language. But, I'm looking for a way to make the language of the federated post to match that of the blog post. Currently, this is not the case. The language of the federated post is always set to English (website's default) independent of the original post's language, at least on Mastodon.

I thought this was because the plugin was not setting the post's language in the ActivityPub object (that's why I asked about using filters). But using the command below, I noticed that the object has a contentMap entry set to the correct language:

curl https://brunovellutini.com/posts/pedalando-abaixo-de-zero/ -H 'Accept: application/activity+json'

(...)
  "content" : "Post's contents in Portuguese...",
  "contentMap" : {
    "pt": "Post's contents in Portuguese...",
  },

(...)

So, the post's language appears to be correctly set to pt (please let me know if I'm wrong).

However, the post federated to Mastodon is tagged with lang="en":

<div class="status__content__text status__content__text--visible translate" lang="en">
   Post's contents in Portuguese...
</div>

Any ideas on how the correct language can be set on the federated post? (maybe it's a Mastodon-specific issue?)

Cheers, Bruno

bruvellu avatar Jan 28 '24 17:01 bruvellu

The question: does the Mastodon server you use has also received the object that way?

There already is a filter where you can set the locale. https://github.com/Automattic/wordpress-activitypub/blob/master/includes/transformer/class-post.php#L684

But it would be better to have one ActivityPub-object for one post which contains all languages.

  "content" : "Post's contents in Portuguese...",
  "contentMap" : {
    "pt": "Post's contents in Portuguese...",
    "en": "Post's contents in English...",
...
  },

Menrath avatar Jan 28 '24 17:01 Menrath

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar May 28 '24 01:05 github-actions[bot]

I think with WordPress itself working on multi-language support in the core, this should be kept open, even if it is not necessary to implement a solution in this plugin itself yet.

Menrath avatar May 28 '24 06:05 Menrath