This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by nancyL 3 months ago.

Assigned support staff: Rajeeb Banstola.

Author Posts
July 8, 2019 at 10:09 pm #4165967

nancyL

Hi, I've developed a custom template for the company's website and I am having a problems when scanning for the templates strings it doesn't find the correct 'READ MORE' so that i can translate the string. here's the code on my front-page.php:
please note that I've even used echo to display READ MORE to make sure it's a 'string'

<div class="container">
	<div class="row">
		<?php
			// Get the last 3 posts.
			global $post;
			$args = array( 
			'posts_per_page' => 3,
			'suppress_filters' => false,
			);
			$myposts = get_posts( $args );
			foreach( $myposts as $post ) :	setup_postdata($post); 
		?>
	        <div class="col-sm">
	            <div class="card CustomLinks">
	                <?php the_post_thumbnail('full', ['class' => 'card-img-top']);?>
	                <div class="card-body">
	                    <h5 class="card-title"><?php the_title(); ?></h5>
	                    <p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
	                </div>
	                <div class="card-body ourLINKS">
	                    <a href="<?php the_permalink() ?>" class="btn btn-block" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Read More</a>
	                </div>
	            </div>
		    <br/>
	        </div>
		<?php endforeach; ?>
	</div>
</div>

Thanks for the help

July 8, 2019 at 10:50 pm #4166035

Rajeeb Banstola

Hi,

Thank you for contacting WPML!

You need to use gettext calls to make the strings translatable. Please try the below code:

<div class="container">
    <div class="row">
        <?php
            // Get the last 3 posts.
            global $post;
            $args = array( 
            'posts_per_page' => 3,
            'suppress_filters' => false,
            );
            $myposts = get_posts( $args );
            foreach( $myposts as $post ) :  setup_postdata($post); 
        ?>
            <div class="col-sm">
                <div class="card CustomLinks">
                    <?php the_post_thumbnail('full', ['class' => 'card-img-top']);?>
                    <div class="card-body">
                        <h5 class="card-title"><?php the_title(); ?></h5>
                        <p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
                    </div>
                    <div class="card-body ourLINKS">
                        <a href="<?php the_permalink() ?>" class="btn btn-block" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo __('Hello world','theme-text-domain'); ?></a>
                    </div>
                </div>
            <br/>
            </div>
        <?php endforeach; ?>
    </div>
</div>

Make sure to change 'theme-text-domain' to the name of your theme's textdomain.

You can find more examples of GetText call here:
https://wpml.org/faq/language-setup/#examples

Let me know how this goes!

Best,

July 8, 2019 at 11:38 pm #4166155

nancyL

My issue is resolved now. Thank you!