If you are having a notice about writing the .mo files please read this doc

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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 6 replies, has 2 voices.

Last updated by thiesd 2 years, 7 months ago.

Assigned support staff: Bernat Torras.

Author Posts
April 5, 2017 at 6:10 pm #1248172

thiesd

Hi

In my website (under construction), I have a small function for a shortcode that enables me to show two links to previous and next posts on a post page. I translated a few post today from Dutch to English using WPML, but on the translated page the shortcode does not work anything. This is of course logical, as the translated posts in english have to be referred to in a different way (probably something involving '-en'. I could just write a second function script for a different shortcode and include that on the english posts, but the problem is that I do not know how I should refer to the translated posts.

Could you perhaps point me in te right direction?

The dutch version shows the two links that are produced by the script ('vorige' and 'volgende'):
hidden link

On the translated version of that same page the links do (logically) not show up:
hidden link

Below is the function that works fine on the original posts, and that I need to duplicate and alter in order to refer to the translated pages (in English):

function prev_next_link() {

	if ( is_singular('post') ) {
		$next_name = "VOLGENDE <i class=\"x-icon-chevron-right\" data-x-icon=\"&#xf105;\"></i>";
		$prev_name = "<i class=\"x-icon-chevron-left\" data-x-icon=\"&#xf104;\"></i> VORIGE";
		$next_link = get_next_post() ? '<a style="float: left;" href="' . get_permalink( get_next_post()->ID ) . '">' . $prev_name . '</a>' : '';
		$prev_link = get_previous_post() ? '<a style="float: right;" href="' . get_permalink( get_previous_post()->ID ) . '">' . $next_name . '</a>' : '';
		$posts = '<div class="wp-post-navigation-next">'.$next_link.$prev_link.'</div>';
		echo $posts;
	} 
}

add_shortcode( 'custom_prev_next_link', 'prev_next_link' );

I'm not asking you to rewrite the entire thing, but I would appreciate it if you could show me the way to refer to the translated (english) versions of the posts.

Thank you!

April 6, 2017 at 6:01 am #1248428

thiesd

I solved it, sorry for the hassle. There doesn't seem to be a way to delete this topic altogether, so I'll just switch it to solved.

Best regards!

April 6, 2017 at 7:13 am #1248478

Bernat Torras

Hi @thiesd,

Thanks for contacting support, I'll do my best to help you with this! 🙂

I'm checking your website on your secondary language (hidden link) and I can see these "VOLGENDE" and "VORIGE" links there properly linking to translated pages.

Could you tell us if you're still experiencing the problem or if it has been already fixed?

In any case, even if it redirects you properly to the english posts, I think that you should update your code to be able to translate these "VOLGENDE" and "VORIGE" strings. If you want to do it, you should wrap them in gettext (__()) functions like so:

function prev_next_link() { 
    if ( is_singular('post') ) {
        $next_name = __('VOLGENDE','my-textdomain')." <i class=\"x-icon-chevron-right\" data-x-icon=\"&#xf105;\"></i>";
        $prev_name = "<i class=\"x-icon-chevron-left\" data-x-icon=\"&#xf104;\"></i> ".__('VORIGE','my-textdomain');
        $next_link = get_next_post() ? '<a style="float: left;" href="' . get_permalink( get_next_post()->ID ) . '">' . $prev_name . '</a>' : '';
        $prev_link = get_previous_post() ? '<a style="float: right;" href="' . get_permalink( get_previous_post()->ID ) . '">' . $next_name . '</a>' : '';
        $posts = '<div class="wp-post-navigation-next">'.$next_link.$prev_link.'</div>';
        echo $posts;
    } 
}
 
add_shortcode( 'custom_prev_next_link', 'prev_next_link' );

Please take in mind that I've used 'my-textdomain' as an example. You should replace this with any unique string that identifies the context of this strings (like your theme or site name).

Once done, you should render the page again to confirm that the strings appear in the default language and then go to WPML>String Translation. There you should be able to find and translate them completely. Please check as well if the language assigned to these strings (you'll see it with the small language flags next to each string) is the correct one (dutch). If not, select them and click the 'change language of selected strings' button to change them (and translate them afterwards).

Thanks,
Bernat

April 6, 2017 at 9:31 am #1248647

thiesd

Hi Bernat,

Thank you for your reply. You are right that the problem of the links not appearing already was solved. I made the mistake of testing it with just one post translated - and one post means of course that there is no next or previous one, so that's why the links didn't appear.

Thanks a lot for the elaborate reply! I replaced the code with yours - only to find out that I apparently am not entitled to use the String Translate plugin in my subscription. I have only a small site, and the rather steep cost of upgrading (plus much higher annual renewal) to the CMS version just for these two words is too high - so I will have to try and find another solution (probably by writing a second function for the translated pages, and manually replace the shortcode there).

Thanks for your trouble!

April 6, 2017 at 1:08 pm #1248896

Bernat Torras

Hi @thiesd,

Sorry, I wrongly assumed that you had WPML String Translation active on your site. No worries, in fact, these gettext functions (_e() or __()) are default WordPress functions to register translatable strings in your code. You can create a po/mo file to translate them. You can read these documentation links to get more information about it:

https://codex.wordpress.org/I18n_for_WordPress_Developers

hidden link

Also, if you're getting troubles to achieve this, you could also use a quick (and a bit dirty) workaround to assign different value to these strings depending on the current language. Something like this:

function prev_next_link() { 
    if ( is_singular('post') ) {
	    
	    if(ICL_LANGUAGE_CODE=='en'){
			$prev = 'PREVIOUS';
			$next = 'NEXT';
		}else{
			$prev = 'VOLGENDE';
			$next = 'VORIGE';
		}	
        $next_name = $prev." <i class=\"x-icon-chevron-right\" data-x-icon=\"&#xf105;\"></i>";
        $prev_name = "<i class=\"x-icon-chevron-left\" data-x-icon=\"&#xf104;\"></i> ".$next;
        $next_link = get_next_post() ? '<a style="float: left;" href="' . get_permalink( get_next_post()->ID ) . '">' . $prev_name . '</a>' : '';
        $prev_link = get_previous_post() ? '<a style="float: right;" href="' . get_permalink( get_previous_post()->ID ) . '">' . $next_name . '</a>' : '';
        $posts = '<div class="wp-post-navigation-next">'.$next_link.$prev_link.'</div>';
        echo $posts;
    } 
}
  
add_shortcode( 'custom_prev_next_link', 'prev_next_link' );

Hope it helps! 🙂

Thanks,
Bernat

PS: If you think that its fixed or if there's nothing else we can do to help you here, please set the ticket status to resolved.

April 6, 2017 at 2:34 pm #1249014

thiesd

Hi Bernat,

Thank you, that is great support! I'm sure i'll be able to fix it with the information in the links or with your (quick and dirty) workaround, so i'll close this ticket for now.

Thanks again,
Thies

April 6, 2017 at 3:03 pm #1249057

thiesd

Just to confirm that your workaround works perfectly - i'll try the more elegant road later on when I have more time. Case closed, thank you!

Cheers,
Thies