WordPress.org

Forums

Ceceppa Multilingua
getting media translation by media ID (5 posts)

  1. gpz_
    Member
    Posted 8 months ago #

    how can I get the media translation having the media ID?

    if I use this code in my template:

    $attachment = get_post($id_image);
    $img_alternative_text = get_post_meta($attachment->ID,'_wp_attachment_image_alt',true);

    the WP_Post object returned have always the same values for every language selected

    thanks

    https://wordpress.org/plugins/ceceppa-multilingua/

  2. Alessandro Senese
    Member
    Plugin Author

    Posted 8 months ago #

    Hi,
    I just added new api in my development version, you can download it here: http://www.alessandrosenese.eu/wp-content/uploads/2014/07/ceceppa-multilingua.zip

    To retrieve translated alt text or title you can use:

    $attachment = get_post($id_image);
    $img_alternative_text = CMLMedia::get_alternative_text( $attachment->ID );
    $img_title = CMLMedia::get_title( $attachment->ID );

    The functions are not documented yet.
    However both accept "language id/slug" as second parameter, the default one is the current language.

    Regards

  3. gpz_
    Member
    Posted 8 months ago #

    thanks a lot!
    I'm using not the standard plugin because I have some others problems like menu labels, you think I can make a merge of the different versions?

  4. Wenci
    Member
    Posted 8 months ago #

    Hi again Alessandro and hi gpz_

    i just tested your dev version of the plugin and didn't got it working sadly but i opted for a different way to get translated text from image, by simply putting the translated text in the description of the image but this cant be done for a multi language sites, hopefully i m using only english and italian now.

    So if i can help you to test it deeper it would be really cool,i used your code inside the Dynamic Featured Image (this is a wonderful plugin to get multiple featured images inside a slideshow like this tut show: http://ankitpokhrel.com.np/blog/sliding-featured-image-thumbnails-in-your-wordpress-theme/)plug-in loop here is the code:

    <?php if ( function_exists('dfi_get_featured_images') ) {
    		$featuredImages = dfi_get_featured_images();
    		if( !is_null($featuredImages) ){
    		  foreach($featuredImages as $images) {
    	            $caption2 = dfi_get_image_title($images['full']);
                        $caption3 = dfi_get_image_caption($images['full']);
      	            $ib = dfi_get_image_id($images['full']);
    		    if($lang!=('it_IT')){
                           $caption4 = get_post_meta( $ib , '_wp_attachment_image_alt', true);
    		    }else{$caption4 = CMLMedia::get_alternative_text( $ib->ID,'it_IT' );}
    		    echo "<div class='desccont'>";
    		    echo "<p class='desc'>" . $caption2 . "</p>";
    		    echo "<p class='desc'>" . $caption3 . "</p>";
    		    echo "<p class='desc'>" . $caption4 . "</p>";
    		    echo "</div>";}
    					       } else {
    						            if ( has_post_thumbnail() ) {
    						                echo '' . the_post_thumbnail( 'full', array( 'class' => 'aligncenter' ) ) . '';
    						            }
    						       }
    						 } else {
    						    if ( has_post_thumbnail() ) {
    						            echo '' . the_post_thumbnail( 'full', array( 'class' => 'aligncenter' ) ) . '';
    						    }
    						 }
    						 ?>

    Did i used your code correctly? And a second question:
    -A post setted to All languages will show image translated fields in the non-main language post?
    To make it easy: I have a post in All languages and my main language is english, when i m on the italian version of the site, the images in the post will show his Italian Translated Alt text?

  5. Alessandro Senese
    Member
    Plugin Author

    Posted 8 months ago #

    Hi Wenci,
    sorry for the delay.

    1) you're using the code correctly... if doesn't works you can try to do it yourself...
    The image fields are stored in the post meta with this key: _cml_media_meta.
    You can use this code to retrieve all the translations of the media:

    $meta = get_post_meta( $media_id, '_cml_media_meta', true );

    $meta is an array containing all translated fields.

    2) depend when you have created the post. because the option to translate media fields is available only in the newest version of the plugin.

Reply

You must log in to post.

About this Plugin

About this Topic