• Hi,

    I’m trying to internationalize a template file for a custom post type with taxonomies.

    I’m using;
    the_terms( $post->ID, 'concert_scenes', '<div style="padding-bottom: 3px"><b>Spelas p&aring:</b> ', ', ', '</div>' );?>
    to echo out the taxomomy.

    But I fail to understand how to translate this. I guess I need to use placeholders and printf() but how do I do this?

    I’ve been at this for quite some time now, googling, reading the i18n part of “Pro WP plugin development” and trying to search here at WP, but I can’t find a working solution… Anyone that has a clue?

    Regards /Joje

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    I take it you wish to allow for translation of “Spelas p?”? Taxonomy slugs and user terms are not translatable. No one normally sees taxonomy slugs and the terms are user defined so are presumably already localized. If your theme has predefined terms, you can use translation functions when the terms are created by code.
    wp_insert_term(__('katt', 'my_theme_domain'), 'my_taxonomy');

    printf() is a good way to have a fixed translatable string that needs to include a a variable, but in this context it’s not required, you can concatenate elements if you prefer.
    the_terms( $post->ID, 'concert_scenes', '<div style="padding-bottom: 3px"><b>' . __('Spelas p?', 'my_theme_domain') . ':</b> ', ', ', '</div>' );
    OR
    the_terms( $post->ID, 'concert_scenes', printf('<div style="padding-bottom: 3px"><b>%s:</b> ', __('Spelas p?', 'my_theme_domain')), ', ', '</div>' );
    I believe most WP translations all use UTF-8 char sets, it makes it easier on translators to avoid HTML entities and just use the actual character, so ? instead of &aring ;. Of course your theme files also need to be UTF-8, they are supposed to be anyway.

    FYI, where you must use printf() is when the translated string needs to contain a variable. This will not work because of $username:
    echo __("Our guest writer $username contributed to this article", 'my_text_domain');

    You could still translate the fixed strings separately and concatenate the results with $username, but this is much better:
    printf(__('Our guest writer %s contributed to this article', 'my_text_domain'), $username );

    Thread Starter George Bredberg

    (@joje47)

    Ok, thanks for a very good explanation. Yes, you where right to assume that is the part “Spelas p?” that I want to have internationalized. I thought I did a good thing using html entities ?? Tx for explaining even that part. I want it to look ok even if its viewed on a non Swedish computer. (It will be used by NGO:s where one part of them are immigrants, so they often have English computers and OS.)

    I have a follow up question, but it concerns another translation issue, so I make a new post so I can mark this as resolved.
    I add a link to it here, hope that’s ok.

    Moderator bcworkz

    (@bcworkz)

    I can’t imagine a new topic for a separate issue would be a problem, nor would linking to it, but I’m not a mod here.

    Using HTML entities or not is maybe a judgment call. I’m relying on WP installations nearly all being UTF-8. It is the default, but someone could change it, though I couldn’t imagine why. Also, at least with ? the character code is the same in UTF-8 as it is in the most common English charsets: ISO-8859-1 & 15. I’d be more concerned about proper character rendering in languages with characters beyond Latin Extended, such as Czech & Polish. ? is probably the least common vowel in other charsets, the other Swedish vowels are somewhat common in other Western languages.

    I don’t think avoiding HTML entities will a problem, at least for Swedish on WordPress. But if you wanted to be very conservatively safe, HTML entities will certainly be correct. I was thinking more about they being harder for translators to read, assuming they are seeing raw text and not rendered HTML. I’ve not done any translations so I’m not so sure that is the case.

    Thread Starter George Bredberg

    (@joje47)

    Yes, you are right about reading the html-entities when translating. At least in poedit it shows up as raw “text”. All html-entities will be shown as is making it a bit hard to read actually. That has been a concern, but since the guest on the website are the main focus, I used it anyway. Now I think I will remove it, and try it out on some computers that use an OS localized to other languages. It’s easy to do and revert back if it does not work out as expected.

    The link to my other question disappeared somehow. My mistake. It would have been nice with a preview function here ??

    How to translate title in widget declaration

    Moderator bcworkz

    (@bcworkz)

    Preview is a great idea! As it happens, the meta team behind the forum design are actively taking suggestions for improvements. You need to register for “Make” to leave a comment. Your first comment will have to go through moderation. Make is a great site for all WP behind-the-scenes activity.

    Please do come back here and post your findings on localized computers. I for one would be very interested in the results. I should think many others are as well. Tack!

    Thread Starter George Bredberg

    (@joje47)

    Hi,

    Interestingly it seems to work with extended characters in most situations I’ve tested, but when WordPress lists installed themes and shows links to author, if you use ? it shows up like a question mark instead. And that is in a computer localized to Swedish, with the Swedish translation active on WordPress backoffice. Not a big problem though.

    I made a screendump

    Moderator bcworkz

    (@bcworkz)

    That’s particularly odd since the titles are OK, it’s just the link text. Everything should be rendered in the Open Sans font loaded through fonts.googleapis.com, which obviously has ? within it. It seems more like a mysterious glitch than a systemic problem.

    I recently learned that the entire backend styling is moving away from Google fonts and will start using system fonts, so your finding may be moot soon (when v4.6 drops I believe), and the situation will get even more complicated with the backend potentially being rendered in any of over a half dozen of different fonts. The good news is I would expect any system fonts in this day and age to all have Swedish vowels at the usual character codes, so there’s a good chance nothing will change in regards to vowel rendering.

    Thanks for reporting back!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to translate using the_terms()’ is closed to new replies.