• Resolved ypeynaud

    (@ypeynaud)


    Hi there,

    Chouby, first thanks for the great and powerful plugin! I selected it from all other solutions (including WPML) and it seems to work great and be both simple and flexible. 🙂

    However, there is something I have been unable to achieve yet: I have a proprietary theme (a child theme of Elegant Theme DIVI) generating multiple pages from various data stored in WP tables. I mean that no manual editing is done on such pages, there are completely generated by code.

    If relevant, the URLs of these pages follow the following format: “mysite.com/subdir1/subdir2/page_slug”. The default language is english. I am now adding French as a second language and I need to be able to display such pages either in English or French, without modifying the URL across languages. For that, all the strings have been properly prepared for translation in the code with __() and _e() functions, the .po and .mo files have been generated, etc.

    I have understood that the current language is set by Polylang from a cookie (or alternatively from the browser language preference setting). So the behavior I would expect and I need is that calling the page “mysite.com/subdir1/subdir2/page_slug” would end in displaying the page either in English or in French, depending on the current language. For example, I also use Buddypress and it automagically displays the user profile in English or French from a single url such as “mysite.com/members/username/”.

    However it doesn’t work for my theme. Calling a “mysite.com/subdir1/subdir2/page_slug” page ends in always displaying it in English, whatever the language of the previous visited pages or the browser language preference can be.

    What do I miss? How could I make it working?

    Many thanks in advance,
    Yves.

    https://wordpress.org/plugins/polylang/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter ypeynaud

    (@ypeynaud)

    OK, no response, so maybe I was unclear in expressing my problem, sorry. :/

    So let’s try it differently. Fundamentally, my question is:

    could a given page (with a given single id) can display its content indifferently in several languages provided that all its content is php-generated with proper esc_html__(‘string’, ‘text-domain’) calls and that all traductions are provided in .mo files?

    Thanks in advance anybody for your response! I really need to know if Polylang is the right plugin or not for my site.
    Yves.

    Hi ypeynaud & Chouby!

    I am having a similar problem. I have created a custom footer and inserted the proper php code so the strings would translate, but the links in the footer always go to the English version of the page and not the Spanish. I have been searching for solutions…
    Any help Chouby?

    My test site is: test.bcnwellwoman.com
    Here is a snippet of the footer code:
    <li><a href="http://test.bcnwellwoman.com/en/services/acupuncture/"><?php _e("Acupuncture", "wellnesscenter-child"); ?></a></li>

    Thanks you for helping me find a solution!
    Best,
    Rachel

    Thread Starter ypeynaud

    (@ypeynaud)

    Hello Rachel,

    In your case, your link is hardcoded to your english page (you have the /en/ slug embedded in your url). So you have no chance to go to Spanish.

    I see two solutions for your footer:

    • either you use some php code for retrieving the id of the correct page depending on the current language.
    • or you define a Spanish menu which is different to the English menu and includes the correct Spanish urls, and you insert the menus in your footer. This possibility may depend on your theme.

    And regarding my question, I am afraid I have the answer: a given page is assigned a language so it can’t display the content in several languages. Actually the Buddypress example is different as these are not real pages.

    Hope this helps,
    Yves.

    Yves,

    Thank you for your kind reply! I finally figured it out with the help of another forum friend, this is the function that worked in my footer.php:

    a href="<?php echo get_permalink( pll_get_post (6668) ); ?>">
    <?php
    if ( 'en_US' == get_locale() )
        echo 'Acupuncture';
    else
        echo 'Acupuntura'; ?></a>
    Thread Starter ypeynaud

    (@ypeynaud)

    Rachel, you might prefer this code, more compact and flexible if you further want to increase the number of languages:

    <?php
    echo '<a href="' . get_permalink( pll_get_post (6668) . '">' . esc_html__(  'acupuncture', 'your_text_domain' ) . '</a>';
    ?>

    Cheers,
    Yves.

    Thread Starter ypeynaud

    (@ypeynaud)

    For anyone interested by my initial question, I just discovered this tread which gives the full dimension of the problem I addressed (and also a workaround worth testing).

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting different page translations from a single URL’ is closed to new replies.