Forums

Polylang
[resolved] How to translate/switch specific contents on templates (9 posts)

  1. ChowKaiDeng
    Member
    Posted 7 months ago #

    Hi!

    As I said before, the plugin is working perfect for me, but I have a question:

    I'm translating most of the content of my site using different Widgets for each language (combining them with Rich Widget and other stuff), but there are some elements that require a direct translation on my theme/template, for example, a slideshow that I'm using on the home page.

    For now, particulary on the home page, I've managed to use a different slideshow using this function:

    <?php
      $homepage = "/en/";
      $currentpage = $_SERVER['REQUEST_URI'];
      if($homepage==$currentpage):
    ?>
      <div>The slideshow with images in English</div>
    <?php else: ?>
      <div>The slideshow with images in Spanish</div>
    <?php endif; ?>

    ...but that just works well for me on the home page.

    Is there any way to set a function to show different contents on my templates depending on the language selected by the user, using a function like the one from above?

    And I have a second question: Why don't you add a "Donate" button (using something like Paypal) inside the settings page of the plugin? I would be more than happy to collaborate in order to maintain the plugin alive. I don't have too much money (and there are odd rules to control foreign currency in my country) but I could spend at least $10 each time that I use your plugin (right now, I'm using it in two projects).

    Thanks again!

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

  2. yoyurec
    Member
    Posted 7 months ago #

  3. ChowKaiDeng
    Member
    Posted 7 months ago #

    Thanks yoyurec! I'm checking it out, but as far as I can see, I think that would do the job.

    Greetings!

  4. Chouby
    Member
    Posted 7 months ago #

    I have no permanent internet connection these weeks. I can't look at the forum everyday and then a post can stay many days without answer from my side. I may also miss some posts. So I am very happy to see help coming from users rather than me ! Thank you yoyurec for answering this post.

    For the donation link, I will probably include one when the plugin will be more mature. Thank you for your intention.

  5. ChowKaiDeng
    Member
    Posted 7 months ago #

    Hi guys!

    I've tried the solution from the other post sugested by yoyurec and Chouby (using get_locale) but it didn't work for me. But finally, I've found a perfect and similar solution using get_bloginfo, that can print the lang values located in the <html> tag. Here's what it looks like:

    <?php
     $currentlang = get_bloginfo('language');
     if($currentlang=="en-US"):
    ?>
     <div>Content in English</div>
    <?php else: ?>
     <div>Content in Spanish (or other language)</div>
    <?php endif; ?>

    So, basically, you could use that function as many times as you want on a template to get different contents depending of the language selected by the user :)

    I suggest to include this solution as part of the documentation of the plugin as many users may want to use it. What do you think?

    Greetings!

  6. Chouby
    Member
    Posted 6 months ago #

    Thank you for this alternative solution. It's curious that get_locale() does not work. I have still to write the documentation...

  7. ChowKaiDeng
    Member
    Posted 6 months ago #

    Well, is not that get_locale() "didn't work", it was more like "I couldn't make it work" :)

    Greetings!

  8. Chouby
    Member
    Posted 6 months ago #

    I included a documentation in the v0.4. I hope it will help...

  9. gxgl
    Member
    Posted 3 weeks ago #

    Hello everyone!

    As a mix of this post and this post

    You can do the next steps:
    Note: Use Notepad++ and format/encoding pages as UTF-8 for WordPress
    Then add next code as following:

    At top of polylang.php
    ----------------------
    /* Template Language Hack */
    add_action('show_current_language', array(&$this, 'show_current_language'));
    /* End of Template Language Hack */

    At the bottom of polylang.php
    -----------------------------
    /* Language Hack */
    function show_current_language() {
    global $curlang;
    $curlang = $this->curlang->slug;
    }
    /* End of Language Hack */

    In header.php (until the <?php wp_head(); ?>).
    ----------------------------------------------
    <!-- Language Hack -->
    <?php
    $curlang = "none";
    do_action('show_kcurrent_language');
    ?>

    <html <?php language_attributes(); ?>>
    <!-- End of Language Hack -->

    Where needed in pages (for maximum 3 languages):
    ------------------------------------------------
    <!-- Language Hack -->
    <?php $currentlang = get_bloginfo('language');
    if($currentlang=="en-US")
    echo "<div>All rights reserved.</div>";
    elseif ($currentlang=="ru-RU")
    echo "<div>Все права защищены.</div>";
    else
    echo "<div>Toate drepturile rezervate.</div>";
    ?>
    <!-- End of Language Hack-->

    Maybe there can be another option for this to use more than 3 languages (maybe using array or something else), but... I have no clue at this moment :)

    The steps above worked perfectly for me, using wordpress 3.3.2

    Regards to all!

Reply

You must log in to post.

About this Plugin

About this Topic