WordPress.org

Support

Support » Plugins and Hacks » Polylang » [Resolved] [Plugin: Polylang] Multilingual theme options

[Resolved] [Plugin: Polylang] Multilingual theme options

  • During the last couple of weeks I’ve experimenting with several multilingual plugins. I was about to implement WPML (which I downloaded half year ago), but discovered it is no longer freely available. WPML was easy to use and uses the approach one post/page per language. I tried xili-language and qtranslate and some others as alternatives and was about to give it up, when i discoverd Polylang last week! Great plugin, ease of use, works great!

    Only one question. I’m using the Atahualpa theme. As theme options you can set and change texts that will appear in the site (like e.g. texts for “read more” and “previous posts”). How can I make this multilingual with polylang?
    I read the post “how to internationalize a theme”, but that’s not the right direction (I think)…

    http://wordpress.org/extend/plugins/polylang/

Viewing 15 replies - 1 through 15 (of 27 total)
  • Plugin Author Chouby

    @chouby

    In fact “how to internationalize a theme ?” is intended for themes which harcode the strings, not for themes which use user defined strings.

    What you request is technically feasible but will require work.

    First of all, you will need mandatory WordPress 3.3 and Polylang 0.6. You will need to make some modifications to the theme, which means that these modifications will be lost each time the theme will be updated, excepted if you convince the author to make its theme compatible with Polylang (which would be great !).

    And finally, you will need to enter your strings in the theme options and enter the translations in the string translations table of Polylang.

    Are you ready ?

    I already thought so (for the hardcoded strings)

    WP 3.3 check, Polylang 0.6 check
    Modifications in theme – I already made a few small ones…

    I know the Atahualpa theme made an addon for WPML – so if we can convince them Polylang is a better option 🙂 So far, I’m impressed.

    I’m ready!

    Plugin Author Chouby

    @chouby

    The modifications refer to version 3.7.3 of the theme. Go to the file atahualpa/functions/bfa_get_options.php. Go straight at the bottom and put the following code at line 495

    $pll_ata_strings = array(
        "multi_next_prev_newer",
        "multi_next_prev_older",
    );
    
    foreach ($bfa_ata as $key=>$str){
        if (in_array($key, $pll_ata_strings)) {
    	if (is_admin())
    	    pll_register_string('atahualpa', stripslashes($str));
    	else
                $bfa_ata[$key] = pll__($str);
        }
    }

    The problem is that the theme mixes strings with other options such as CSS, so the big job is to build the $pll_ata_strings array. Fortunately you have an options array at the beginning of the same file, so the game is to detect what is a string and what is something else. In fact, true options are probably at line 311, but it is much less readable than what seems to be the old option array.

    Hope it helps!

    Hi Chouby, thanks for the swift reply…

    I entered the code and see the parameters popping up in the string translations tabular, but no impact in the user interface: the string appears and not its translation.

    Am I missing something?

    Plugin Author Chouby

    @chouby

    It works well on my test site. To be honest, I tested with the string ‘post_feed_link_title’ which was easier to find on the frontend than ‘multi_next_prev_newer’.

    Is your theme 3.7.3 ? Did you put the code just above the line :

    $result = array($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']);

    Does the site title (not theme dependant) translation work ?

    Ahhh, briljant…
    My line counter showed a different number from yours (probably because of the $default_option line half way the function), so I put the code just below the $result line instead of above.

    Now my site is showing up the correct bilangual wording for newer and older posts!

    Thanx! Now my Atahualpa site is fully multilingual! (Except that the archive widget is not working in 0.6 )

    BTW one tip: in my first attempt to use your code, the string translation didn’t work – I could not save the changed language values. It turned out that the value in atahualpa contained the “%rarr” value (as string). So change your atahualpa settings first to something without special characters!

    Plugin Author Chouby

    @chouby

    I am aware of the problem with the archives widget. You discovered a new bug with special characters. Both will be fixed in 0.6.1.

    To prevend an error when updating polylang, change the code above into:

    if (function_exists('pll_register_string')) {
      foreach ($bfa_ata as $key=>$str){
        if (in_array($key, $pll_ata_strings)) {
    	if (is_admin())
    	    pll_register_string('atahualpa', stripslashes($str));
    	else
                $bfa_ata[$key] = pll__($str);
        }
      }
    }

    Thanks to Chouby 🙂

    This works almost good 🙂 Maybe I missed something but apparently the bug with special characters has not been fixed yet. I need to handle strings like :
    … (Cont’d) →
    string “custom_read_more”
    Atahualpa Version 3.7.9
    Polylang Version 0.9.2.
    Thanks in advance

    Plugin Author Chouby

    @chouby

    and with the modification below?

    if (function_exists('pll_register_string')) {
      foreach ($bfa_ata as $key=>$str){
        if (in_array($key, $pll_ata_strings)) {
    	if (is_admin())
    	    pll_register_string('atahualpa', $str);
    	else
                $bfa_ata[$key] = pll__($str);
        }
      }
    }


    Parse error: syntax error, unexpected T_FOREACH, expecting T_STRING or T_VARIABLE or ‘$’

    Line

    Plugin Author Chouby

    @chouby

    Maybe something wrong in the modification you did.
    In the code above, I just replace stripslashes($str) by $str. So if the first worked, the second should not create this error.

    Was on my side… I copied and paste again your code successfully.
    No change in the behavior when trying to handle the string
    <a href="%permalink%">… (Cont'd) →</a>
    It just roll back to defaut value

    Plugin Author Chouby

    @chouby

    Oh! I understand now. This is not a problem with the special characters. But with html code. Generally, WordPress does not allow html code in strings such as widget titles. And to be able to translate this correctly Polylang does not allow html too.

    This is not part of a widget… this is part of Atahualpa customization : read more set-up.
    This does’nt make sense to have a post extract without the ability to ask for the full post by using a link in the read more set-up.

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘[Resolved] [Plugin: Polylang] Multilingual theme options’ is closed to new replies.
Skip to toolbar