• Resolved Paolo

    (@paoltaia)


    Hi,

    sorry if this is a dumb question, but I’ve searched everywhere and couldn’t find a straight answer to this.

    The function the_taxonomies() returns a list of tags and categories as such:

    Taxonomy Name:

    Term Name, Term Name 2, and Term Name 3.

    How can one translate the “and” between Term Name 2 and Term Name 3?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • This is the code in wp-includes/formatting.php that supplies the separators:

    $l = apply_filters( 'wp_sprintf_l', array(
    		/* translators: used to join items in a list with more than 2 items */
    		'between'          => sprintf( __('%s, %s'), '', '' ),
    		/* translators: used to join last two items in a list with more than 2 times */
    		'between_last_two' => sprintf( __('%s, and %s'), '', '' ),
    		/* translators: used to join items in a list with only 2 items */
    		'between_only_two' => sprintf( __('%s and %s'), '', '' ),
    	) );

    As you can see, the strings ‘%s, and %s’, and ‘%s and %s’ are passed through the standard translating function __().

    That means you can add those strings to the standard translation tables for your theme. Here is an article that may help explain how to do that: https://code.tutsplus.com/tutorials/translating-your-theme–wp-25014

    Another way to do this is to take advantage of the filter that is used by apply_filters(). Add a function like this to your functions.php file:

    function translate_list_separators( $separators ) {
       $separators['between_last_two'] = ', plus ';
       $separators['between_only_two'] = ' plus ';
    return $separators;
    }
    add_filter('wp_sprintf_l', 'translate_list_separators');

    Substitute your own translations for ‘, plus ‘, and ‘ plus ‘.

    Thread Starter Paolo

    (@paoltaia)

    awesome, thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Translate the_taxonomies() "and" between last too terms’ is closed to new replies.