This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

String translation in the “/inc/template-tags.php”

Resolved 21 replies premiumthemetheme-vantage
11 years ago · Last reply by Andrew Misplon 10 years ago

Hi,

… I use the tool “Poedit” for my translations. It works very fine with the theme Vantage!

But, now I found a little point, who will not translated.
In /Vantage/inc/template-tags.php – Line: 141 – in the following string line:

'on' => __('Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></span>', 'vantage'),

———————————————————————————————-

Here the complete function for a better overview:

function vantage_posted_on() {
	$posted_on_parts = array(
		'on' => __('Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></span>', 'vantage'),
		'by' => __( '<span class="byline"> by <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'vantage' ),
	);

My problem/wish is, that I can translate the string “Posted on”!
But in the “.po”-file is not the right string – I think..
There is this string:

Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>

————————————

How I write the correct translation-string?

I hope you understand my question.

GM

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

21
  1. mikeSo 11 years, 8 days ago

    Hi – Its me again…

    … the same problem I’ve with the strings

    Posted in %1$s and tagged %2$s.

    and …

    Posted in %1$s.

    In the same file “/Vantage/inc/template-tags.php” – on Line: 317 until 324 – in the following string line:

    // But this blog has loads of categories so we should probably display them here
    		if ( '' != $tag_list ) {
    			$meta_text = __( 'Posted in %1$s and tagged %2$s.', 'vantage' );
    		}
    		else {
    			$meta_text = __( 'Posted in %1$s.', 'vantage' );

    Can you help me please – I must this translate urgent ;)

    GM

  2. Andrew Misplon Staff 11 years, 8 days ago

    Hi Mike

    I’ll jump in tomorrow and take a look at this with Poedit. If you want to hotfix right now you could drop that entire function into the functions.php file of a child theme and manually change those strings. Not ideal…but if you want to fix right now:

    if ( ! function_exists( 'vantage_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     *
     * @since vantage 1.0
     */
    function vantage_posted_on() {
    	$posted_on_parts = array(
    		'on' => __('Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></span>', 'vantage'),
    		'by' => __( '<span class="byline"> by <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'vantage' ),
    	);
    	$posted_on_parts = apply_filters('vantage_post_on_parts', $posted_on_parts);
    	$posted_on = sprintf( implode(' ', $posted_on_parts),
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		apply_filters('vantage_post_on_date', esc_html( get_the_date() )),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'vantage' ), get_the_author() ) ),
    		get_the_author()
    	);
    	echo apply_filters('vantage_posted_on', $posted_on);
    }
    endif;
  3. Andrew Misplon Staff 11 years, 8 days ago

    If you’d like to keep your translated files in the languages folder of a child theme, I’ve got one ready to go here:

    https://siteorigin.com/wp-content/uploads/2015/01/vantage-child-translation-ready-02.zip

    The child theme has a function in functions.php that tells WordPress to look for the translated files in the child theme languages folder.

    • mikeSo 11 years, 7 days ago

      Is it possible also place a other “CHILD” file except the language “.po” and the /style.css?

      Example the file “/vantage/inc/template-tags.php”
      I create folder -> “/vantage-child/inc/” and copy the file “template-tags.php” in this folder.
      And then I can make my changes in this file.

      Thanks – GM ;)

  4. Andrew Misplon Staff 11 years, 8 days ago

    If you can reply I’ll then star that email as it comes to me and help out with the string issue as soon as I can tomorrow.

    Thanks

  5. mikeSo 11 years, 7 days ago

    Hallo Andrew,

    … many thanks for the CHILD Theme. It works fine.
    After A few little adjustments!
    —————————————————————————–
    NOTE for VANTAGEfriends:… in WP-Admin, under Appearance -> Customize

    Note: Before you change the theme (vantage) to (vantage-child), you have to remember your own layout colors!
    Only – If you have previously changed the colors in the main theme (vantage).
    Your changed theme colors are not adopted!

    Good News:
    ONLY the first time. After the first time, you can change between both themes without additional adjustments.
    —————————————————————————–

    GM

    • Andrew Misplon Staff 11 years, 7 days ago

      That’s correct. Thanks for pointing that. Unfortunately menu and Customizer settings reset when activating a child theme. It’s expected but still a pain.

  6. mikeSo 11 years, 7 days ago

    Hallo Andrew (again),

    … thanks for your (Not ideal…) fix tipp.

    I think it’s up to line 141 in the /vantage/inc/template-tags.php:
    I have tried the following and it works for me:

    function vantage_posted_on() {
    	$posted_on_parts = array(
    		'on' => __('Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>', 'vantage'),
    		'onMIKE' => __('<time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></span>'),
    		'by' => __( '<span class="byline"> by <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'vantage' ),
    	);

    Unfortunately, I don´t know if this correct (clean) code.
    I’m not so good CODER ;( !

    GM ;)

  7. mikeSo 11 years, 7 days ago

    A little correction in the line with “onMIKE”:

    function vantage_posted_on() {
    	$posted_on_parts = array(
    		'on' => __('Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>', 'vantage'),
    		'onMIKE' => __('<time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></span>', 'vantage'),
    		'by' => __( '<span class="byline"> by <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'vantage' ),
    	);

    The “, ‘vantage’ ” are missing.

    GM ;)

    • Andrew Misplon Staff 11 years, 7 days ago

      Sorry, I’m not following there. What is the added line for? Where you are you then using it?

      • mikeSo 11 years, 7 days ago

        I take a additional line in the file “/vantage/inc/template-tags.php”. After line 141.
        The line begins with ‘onMIKE’ instead of normaly with ‘on’
        And that I forgot to place followings “‘, ‘vantage’),” in this line (on the end of line).

        Do you know now – what I means? I hope ;)

  8. mikeSo 11 years, 7 days ago

    Maybe you can integrate the the next update?

    GM ;)

  9. Andrew Misplon Staff 11 years, 7 days ago

    I can confirm that right now I can translate the following:

    Posted in %1$s and tagged %2$s.
    Posted in %1$s.

    But as you’ve pointed out, I’m unable to translate:

    Posted on <a href=\"%1$s\" title=\"%2$s\" rel=\"bookmark\"><time class=\"entry-date\" datetime=\"%3$s\">%4$s</time></a><time class=\"updated\" datetime=\"

    Thanks for bringing this to our attention. I’ll log a bug report now.

  10. mikeSo 11 years, 7 days ago

    You can place in your next “vantage Theme” update,
    also a additional line in the file “/vantage/inc/template-tags.php”. After line 141.
    Then works the translation of this string “Posted on”.

    Or not ?!?

    GM ;)

  11. Andrew Misplon Staff 11 years, 7 days ago

    Ok got you. Thanks for clearing this up. I’ll log this now.

    • mikeSo 11 years, 7 days ago

      Thanks – GM ;)

  12. Andrew Misplon Staff 11 years, 7 days ago

    Hi GM

    I’m going to answer here at the bottom rather.

    You can copy many files over but not template-tags.php. If a function is wrapped in template-tags.php as follows:

    if ( ! function_exists( 'vantage_posted_on' ) ) :

    Then it’s save to copy that entire function over to your functions.php file in your child theme. That’s the only way of changing the contents of template-tags.php, function by function. But the function must be wrapped as I indicated in order for you to copy it.

    • mikeSo 11 years, 7 days ago

      Hallo Andrew,

      Many thanks for your help, it is a nice “TEMPSolution”.
      But I think is better – I’m looking for your next update ;)

      Many thanks again!
      GM

  13. Andrew Misplon Staff 11 years, 7 days ago

    Thanks again GM. I have definitely logged this. Unfortunately from then on it’s up to the developers to decide what lands up in the next update based on how much time they have etc. I have pushed this though so hopefully we’ll see it included soon.

  14. rolf 10 years, 11 months ago

    I ended up with this exact problem: unable to translate that exact string “Posted on…”. Looking at the code here, I think the issue is that the ‘on’ string tries to translate a string including the “modified date” . A minor change fixes this:

    $posted_on_parts = array(
    		'on' => __('Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><time class="updated" datetime="', 'vantage') . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( get_the_modified_date() ) . '</time></span>',
    • Andrew Misplon Staff 10 years, 11 months ago

      Apologies for the hassle rolf, thanks for posting. We’ve fixed this, the change will be included in x.3.4. This is what the posted_on function will look like in the new version:

      if ( ! function_exists( 'vantage_posted_on' ) ) :
      /**
       * Prints HTML with meta information for the current post-date/time and author.
       *
       * @since vantage 1.0
       */
      function vantage_posted_on() {
      	$posted_on_parts = array(
      		'on' => __( 'Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><time class="updated" datetime="%5$s">%6$s</time>', 'vantage'),
      		'by' => __( '<span class="byline"> by <span class="author vcard"><a class="url fn n" href="%7$s" title="%8$s" rel="author">%9$s</a></span></span>', 'vantage' ),
      	);
      	$posted_on_parts = apply_filters('vantage_post_on_parts', $posted_on_parts);
      	$posted_on = sprintf( implode(' ', $posted_on_parts),
      		esc_url( get_permalink() ),
      		esc_attr( get_the_time() ),
      		esc_attr( get_the_date( 'c' ) ),
      		apply_filters('vantage_post_on_date', esc_html( get_the_date() )),
      		esc_attr( get_the_modified_date( 'c' ) ),
      		esc_html( get_the_modified_date() ),
      		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
      		esc_attr( sprintf( __( 'View all posts by %s', 'vantage' ), get_the_author() ) ),
      		get_the_author()
      	);
      	echo apply_filters('vantage_posted_on', $posted_on);
      }
      endif;
      if(!function_exists('vantage_display_logo')):
      /**
       * Display the logo 
       */
      function vantage_display_logo(){
      	$logo = siteorigin_setting( 'logo_image' );
      	$logo = apply_filters('vantage_logo_image_id', $logo);
      	if( empty($logo) ) {
      		if ( function_exists( 'jetpack_the_site_logo' ) && jetpack_has_site_logo() ) {
      			// We'll let Jetpack handle things
      			jetpack_the_site_logo();
      			return;
      		}
      		// Just display the site title
      		$logo_html = '<h1 class="site-title">'.get_bloginfo( 'name' ).'</h1>';
      		$logo_html = apply_filters('vantage_logo_text', $logo_html);
      	}
      	else {
      		// load the logo image
      		if(is_array($logo)) {
      			list ($src, $height, $width) = $logo;
      		}
      		else {
      			$image = wp_get_attachment_image_src($logo, 'full');
      			$src = $image[0];
      			$height = $image[2];
      			$width = $image[1];
      		}
      		// Add all the logo attributes
      		$logo_attributes = apply_filters('vantage_logo_image_attributes', array(
      			'src' => $src,
      			'width' => round($width),
      			'height' => round($height),
      			'alt' => sprintf( __('%s Logo', 'vantage'), get_bloginfo('name') ),
      		) );
      		if($logo_attributes['width'] > vantage_get_site_width()) {
      			// Don't let the width be more than the site width.
      			$width = vantage_get_site_width();
      			$logo_attributes['height'] = round($logo_attributes['height'] / ($logo_attributes['width'] / $width));
      			$logo_attributes['width'] = $width;
      		}
      		$logo_attributes_str = array();
      		if( !empty( $logo_attributes ) ) {
      			foreach($logo_attributes as $name => $val) {
      				if( empty($val) ) continue;
      				$logo_attributes_str[] = $name.'="'.esc_attr($val).'" ';
      			}
      		}
      		$logo_html = apply_filters('vantage_logo_image', '<img '.implode( ' ', $logo_attributes_str ).' />');
      	}
      	// Echo the image
      	echo apply_filters('vantage_logo_html', $logo_html);
      }
      endif;

Replies on this thread are closed.

Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Have a different question or issue?

Start New Thread