WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Multilingual theme options (28 posts)

  1. AlbertGn
    Member
    Posted 2 years ago #

    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/

  2. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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 ?

  3. AlbertGn
    Member
    Posted 2 years ago #

    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!

  4. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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!

  5. AlbertGn
    Member
    Posted 2 years ago #

    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?

  6. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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 ?

  7. AlbertGn
    Member
    Posted 2 years ago #

    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!

  8. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  9. AlbertGn
    Member
    Posted 2 years ago #

    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 :)

  10. Treeas
    Member
    Posted 1 year ago #

    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

  11. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    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);
        }
      }
    }
  12. Treeas
    Member
    Posted 1 year ago #

    ...
    Parse error: syntax error, unexpected T_FOREACH, expecting T_STRING or T_VARIABLE or '$'

    Line

  13. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  14. Treeas
    Member
    Posted 1 year ago #

    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

  15. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  16. Treeas
    Member
    Posted 1 year ago #

    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.

  17. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Maybe I don't understand what you want to reach. But putting this
    <a href="%permalink%">… (Cont'd) →</a> in Atahualpa 'Read More' option will lead to error in your page. Just use:… (Cont'd) →

  18. Treeas
    Member
    Posted 1 year ago #

    Within Atahualpa customization :
    Atahualpa Theme Options — Post & Pages — Configure EXCERPTS — Custom read more
    I need to have a EN translation for FR String :
    <a href="%permalink%">… (Cont'd) →</a>
    <a href="%permalink%">… (suite) →</a>

    This is not a "nice to have" ;-)

  19. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    I made the test and it works perfect. I wonder. Did you add the option in the list of options to translate?

    $pll_ata_strings = array(
        "multi_next_prev_newer",
        "multi_next_prev_older",
        "custom_read_more", // this one for custom read more
    )
    ;

  20. Treeas
    Member
    Posted 1 year ago #

    I tried to get the fields creating issues, here are my concerns :
    "post_footer_page",
    "custom_read_more",
    "more_tag",
    "comments_next_prev_older",

    Symptom is :
    when saving, if the current page contains one of these fields, there is a re-init of all translation made to initial version (all pages).

  21. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry, I tested all these options and don't reproduce your problem.

  22. Treeas
    Member
    Posted 1 year ago #

    I reapplied WP last update, same for Polylang and I retried…
    Same result.
    Here is a link to a pict showing the symptom. The only solution I see now is to patch the table involved but I need some directions…

  23. Treeas
    Member
    Posted 1 year ago #

    Chouby,

    In the language set-up (Set-Up Tab), I've the following warning :
    Warning: Wrong parameter count for array_unique() in ~/wp-content/plugins/polylang/include/admin.php on line 408

    The line is :
    $terms = array_unique(array_diff($terms, $tr_terms), SORT_NUMERIC); // array_unique to avoid duplicates if a term is in more than one taxonomy

    Sql result of following doesn't show duplicates
    SELECT term_id FROM wp_termmeta WHERE meta_key = '_language' ORDER BY term_id ASC
    Could it be an explanation ?
    …/…

  24. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    I don't think so since this line is not executed for the strings translations list table (however thank you for the bug report linked to the PHP version, I will correct it in the next release).

    EDIT: The problem with array_unique should occur if PHP < 5.2.9
    And WordPress requires PHP 5.2.4
    Could you check PHP version?

  25. Treeas
    Member
    Posted 1 year ago #

    PHP Version is 5.2.6-1
    I'm ready to open an admin access for your investigations.
    Let me know :\

  26. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    You can contact me here

  27. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    There is a big issue in Atahualpa 3.7.9. Atahualpa saves options on frontend. Thus, at first visit in a translated language, the options are saved in the translated language and translations (which are done in only one direction) are broken.

    It seems to occur only when using the function 'bfa_widget_area'. A quick workaround is to comment the line 479 in functions.php

    update_option('bfa_ata4', $bfa_ata);

    I don't know how much it impacts the theme.

    Here is another possible solution which does not modify the theme (possible with 2 languages but difficult to manage with more than 2).

    Polylang does keep all the translations while the checkbox "Clean strings translation database" is kept unchecked. It is then possible to save all the options in the first language and translate them. Then resave all the options in the second language and translate them. Although it won't be "visible", the translation will work in both directions while keeping "Clean strings translation database" unchecked.

    The best solution would be a modification of the theme which must not update the option which contains translatable strings on frontend as it most probably breaks all multilingual plugins.

    NB: v0.9.5 should solve the other issue reported by @Treeas (which was depending on the installation, maybe PHP version)

  28. Treeas
    Member
    Posted 1 year ago #

    For the moment, temporary fix is Ok.
    I notified the option front-end reset issue to Atahualpa support.
    Thanks Chouby.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags