WordPress.org

Forums

Polylang
[resolved] pll_e() / pll__() on functions.php = KO (11 posts)

  1. marcreig
    Member
    Posted 2 years ago #

    Hi!

    I've a problem:

    - I load via AJAX a group of posts when "load more posts" button is pressed.
    The function defined on functions.php to handle the ajax request, returns an HTML block with the fresh loaded posts. This HTML is basically the same that appears on my index.php, on my theme. So posts loaded on index.php and the ones returned via functions.php have the very same structure and code.

    Problem is:

    - On index.php, functions from polylang work properly. But in functions.php, they don't.
    I'm still having my registred words in english instead of spanish.

    Why is that?

    Thanks.

    PS: fact is, that in functions.php I've some defined filters (like one to short the excerpt words number to 15 words) and they doesn't work at all too. What is going on?

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

  2. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    There are in fact two questions:

    1. Can we use pll__ and pll_e in functions.php?
    Yes, but you must wait for the language to be set. In your polylang settings, you can choose two options: setting the language from content or from url. In the first casse, the language is set quite late. See at then end of http://polylang.wordpress.com/documentation/documentation-for-developers/general/

    2. Does Polylang load correctly when doing ajax on frontend?
    Not by default. You must set the variable 'pll_load_front' in your ajax request for Polylang to detect what to do. See the same page in the documentation.

  3. marcreig
    Member
    Posted 2 years ago #

    Well then, I've done this:

    1) Changed option to number 2, which is appending the language on every single URL.
    Nothing changed. Keep recieving block in English when I'm working in Spanish on web's home.

    2) On AJAX request, I've added on data block for the POST request the variable "pll_load_front".
    And I've tried like this:

    `$.post(AdminAjax.ajaxurl, { action: "loadMorePosts", cont: cont, ptype: ptype, pclass: pclass, offset: offset, pll_load_front: true }).done(function(data) {
    //alert("Data Loaded: " + data);
    button.remove();
    $(".loadmorepostsimg").remove();

    $("."+cont).append(data);
    });

    And I've tried like "pll_load_front: 'pll_load_front'" too.
    Nothing happened.

    Keep recieving in both cases texts in english.

    So, could you explain me the exact steps I should take to make it work please?

    Thank you so much! :)

    -----------------------------

    EDIT:

    Since I've added on ajax request pll_load_front: 1, now when I push the button to load more posts, I get this error:

    Fatal error: Call to undefined method Polylang_Core::register_string() in .......

    So I guess that adding pll_load_front: 1 has done something at last (I've cleared the cache to see that it was really doing something). But now, it works no more. If I remove pll_load_front: 1, then everything works normally.

    Thanks!

  4. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    The fatal error should be fixed in the current development version (1.0.1.6)
    http://downloads.wordpress.org/plugin/polylang.zip

    Is your theme freely downloadable?

  5. marcreig
    Member
    Posted 2 years ago #

    Well, yes. I've used the STARKERS empty (blank base) theme, to do and create my own theme. From very scratch.

    So everything is ok, I think so.

    So right now, what should I do?
    I mean, can I recieve translated posts or not?

    Will you publish the update without being a development unit, soon?

    Thanks.

  6. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    Can you send me your theme that I can try to find out where's the issue? You can post a link (or your email) here

  7. marcreig
    Member
    Posted 2 years ago #

    http://viewportindustries.com/products/starkers/

    I've changed nothing. I've created my index and whatever... but I've not modified anything in general.

    So you try! :)

    Thanks!

  8. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    Yes. I already downloaded it. Google is my friend ;-) But if I well understood, your problem is that Polylang does not act as you expect with the modifications you made (what you did to get posts in ajax). So I can't find out what's wrong by testing only the unmodified theme.

  9. marcreig
    Member
    Posted 2 years ago #

    Nop.
    I've modified nothing at all...
    I've just made a JS file with the respective jQuery $.post(...) call, with some data which I've showed you before, and that's it!
    On functions.php, I've the function which does the WP_Query call and it's over!

    :(

  10. marcreig
    Member
    Posted 2 years ago #

    Hey!
    Anything new?

    As I said, I've made no modification to original theme.
    Just functions.php with the function to be called and the call on a site.js. That's it.

    Oh and for if it's useful, I've this over the function:

    add_action( 'wp_ajax_nopriv_loadMorePosts', '_loadMorePosts' );
    add_action( 'wp_ajax_loadMorePosts', '_loadMorePosts' );

    edit:

    Oh wow man! I've recently seen that there was a new Polylang update! And you know what? Now it works!! No more PHP error there! :_)
    Thanks man! Don't know what you've resolved (I guess file dependencies on load time...) but now it works wonderfully! ;)

  11. marcreig
    Member
    Posted 2 years ago #

    It's over! :)

    It was the update what resolved it!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Polylang
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic