Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

Aurovrata Venet on "[Plugin: Media Library Assistant] Multi-language WPML/Polyland plugin support"

$
0
0

Dear David

Some observations about PolyLang wrt MLA:

Is translation enabled for media?
PolyLang allows the user to switch off the translation for media (a checkbox in the plugin settings page).
- you can verify if this is the case with the polylang function,
pll_is_translated_post_type('attachment')

- if media is not translated, then MLA needs to do nothing further.

What happens when PolyLang translates media?

- When a media file is translated in PolyLang, it duplicates the existing attachment post, allowing for the attachment title/alt text/caption/description to be translated. However, both are pointing to exactly the same media file.

- the duplicate post is now associated with the original attachment post by inserting a new unique term to the post_translations taxonomy in the wordpress table,
wp_insert_term($uniqueID_as_term, 'post_translations', array('description' => serialize(array( 'en'=>'<postID_en_trans>','jp'=>'postID_jp_trans' )) )
Note how it makes use of the description field of the new term to store the serialised array containing the translation mapping.

- it also register the above 2 post with the corresponding unique term,

wp_set_object_terms(<postID_en_trans>, $uniqueID_as_term,'post_translations');

The MLA plugin can reproduce all of the above by simply making a call on the API function pll_save_post_translations($arr) (see doc) to save the twined 'attachment' posts, by building the following array $arr:

//let's say $def_post_id is the media attachment post ID we want to translate
// first we check if there is already a translation
$trans_post_id = pll_get_post($def_post_id, $trans_lang);
// if $trans_post_id=null MLA duplicates the original post for user selected language $trans_lang slug (eg 'jp')
$trans_post_id =... //duplicate attachment post id.
$def_lang = pll_get_post_language($def_post_id,'slug');
$arr = array( $def_lang => $def_post_id,
              $trans_lang => $trans_post_id);
pll_save_post_translations($arr);
//polylang plugin will merge the new translated key with existing translations, so we don't need to worry about passing the previous translations)

So MLA can pretty much do what it does so far, with the exception of adding a dropdown 'language' menu in the Quick-Edit box, and saving bulk media meta data set for selected language in the $trans_post_id attachment post, where each one is twined with its original language using the above piece of code.
If for a given language there is already a post for that media, then the post needs to be updated rather than created.

A list of languages can be obtained for the menu by calling the PolyLand function pll_languages_list(array('slug','name'));.

Translating MLA Att.Category
PolyLang allows for plugins to register strings to translate using the API function pll_register_string($pluginName, $string), so we could also look at allowing for the translation of media taxonomies. This would require the additional association of translated taxonomies with their default language (like the media post above), but it would also necessitate the association of translated media attachment post with its corresponding translated taxonomy.

I would suggest that we leave this for another day, and set if we can get the MLA to manage translated media post for now.

Your thoughts?

kind regards

Vrata


Viewing all articles
Browse latest Browse all 11471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>