How to get content translations programmatically

How to get content translations programmatically

How to get content translations programmatically
In order to get current content translations of the current post in MultilingualPress 3, you can use the Translations class passing the arguments via TranslationSearchArgs. Here is an example:
add_filter(‘the_content’, function($content) {
$args =
InpsydeMultilingualPressFrameworkApiTranslationSearchArgs::forContext(
new InpsydeMultilingualPressFrameworkWordpressContext()
)->forSiteId(get_current_blog_id())->includeBase();

$translations = InpsydeMultilingualPressresolve(
InpsydeMultilingualPressFrameworkApiTranslations::class
)->searchTranslations($args);

foreach ($translations as $translation) {
$postId = $translation->remoteContentId();
$title = $translation->remoteTitle();
$url = $translation->remoteUrl();

$language = $translation->language();
$bcp47tag = $language->bcp47tag();
$englishName = $language->englishName();
$isoCode = $language->isoCode();
$locale = $language->locale();
$name = $language->name();
}

return $content;

});
Now you can loop through the $translations array where each Translation object contains translation data and language information.