1

I'm rebuilding my website from a child theme of twentytwelve to child theme of twentyfourteen. Most of the functions I'm using comes from tutorials, so most of the string aren't localized. With this child theme I'm working on I really want to localize the theme because I want to use the theme on an Afrikaans website and on an English website.

I want to now what is the correct way to localize these following strings:

echo '  #This article have ' . str_word_count($post->post_content) . ' words to read!';

and

echo "<div class=\"pagination\"><span>Page ".$paged." van ".$pages."</span>";

and

echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";

Many thanks in advance

1 Answer 1

1

Always keep in mind: your translators might need need to reorder all words. So you cannot insert dynamic values into translatable strings like you did here.

Use sprintf() or printf() and placeholders instead:

$string = _x( 
    'This article has %s words to read', 
    '%s = number of words', 
    'your_textdomain' 
);

printf( $string, number_format_i18n( str_word_count($post->post_content) ) );

$string = _x( 
    'Page %1$s of %2$s',
    '%1$s = current page, %2$s = all pages',
    'your_textdomain'
);

echo "<div class='pagination'><span>" 
    . sprintf( $string, $paged, $pages ) 
    . "</span>";

No placeholder is needed in this case:

echo "<a href='" . get_pagenum_link($paged + 1)."'>" 
    . _( 'Next &rsaquo;', 'your_textdomain' ) 
    . "</a>";
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.