• Resolved Vanderlindemedia

    (@jvanderlinde)


    Hi.

    I have a few websites that rely on a few hard functions within the template. It used to work untill version 4.2 if i’m correct, everything after that was not working no more. I’m not sure what caused this, but it’s surely an update from wordpress itself.

    I have a few websites with Qtranslate x in order to make a multilanguage website. Most common languages are NL & EN. For example, i have a hard coded footer and sometimes i need a translation in that as well. It’s really simple code and does’nt require much:

    <?php if(get_bloginfo(‘language’) == ‘nl-NL’) { ?>

    <p>show something in NL</p>

    <? } else { ?>

    <p>Show something in other language</p>

    <? } ?>

    This always used to work, untill an update of wordpress came by. What it does: if the language is NL, show this, else show that which presents english. The only thing i get now is that it always works on /en/ in this case, but no longer /nl/ and only displays the “Show something in other language”.

    The switch does’nt work no more. Anyone has a clue?

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

    (@bcworkz)

    Try echoing out the return from get_bloginfo('language') on a template somewhere after you’ve selected Dutch in General Settings. Because of the language pack installed (nl-NL.po for 4.7.x), my site is returning simply 'nl' when Dutch is selected. Naturally your comparison needs to match what is being returned even if it’s technically incorrect. For Belgium it returns 'nl-BE', but Netherlands is just 'nl'. This is how the Dutch translator translated ‘html_lang_attribute’, which is typically translated to the w3.org language tag, but not in this particular language pack.

    I suggest you alter your comparison to match either version in anticipation of it becoming nl-NL again in the future.

    Thread Starter Vanderlindemedia

    (@jvanderlinde)

    Whoa, thanks for the tip! That works… by changing ‘nl-NL’ to simply ‘nl’ the switch seems to work now.

    I hope it stays this way, because some clients really are picky when it comes to their site, and telling them no an update from WordPress caused the behaviour is usually a no go for them.

    <?php if(get_bloginfo(‘language’) == ‘nl’) { ?>

    <p>show something in NL</p>

    <? } else { ?>

    <p>Show something in other language</p>

    <? } ?>

    This seemed to work perfectly fine in a test template and switching in between them. ?? Good.

    Moderator bcworkz

    (@bcworkz)

    Yes, “an update caused it” sounds like a lame excuse even when true. I’d be angry too when my site appears broken if I were not able to fix it myself. I haven’t yet checked the 4.8 language pack. My fear is, if not 4.8, then sometime in the future it’ll change back to nl-NL and the problem will recur. You might consider something like this:
    if( 'nl' == substr( get_bloginfo('language'), 0, 2 )

    This will cause Dutch output for values like nl, nl-NL, nl-BE, nldfstggs. While not ideal, it’s better than getting English output ??

    Thread Starter Vanderlindemedia

    (@jvanderlinde)

    I understand.

    Working with numbers might be a better and more future proof sollution. Glad that it’s solved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hardcoded translation’ is closed to new replies.