WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
pll_e best practices - documentation (3 posts)

  1. jjchinquist
    Member
    Posted 8 months ago #

    What is the best practice for using pll_e and pll__ ?

    My goal is that I would like to have many strings inside of my theme be translatable through the admin page. For example "Enter your search term.".

    Ideally I would register all _e('my-theme', 'some-string') and __('my-theme', 'some-string') calls in my theme to the admin interface. The wordpress-seo plugin registers its strings somehow automatically. How does it do that?

    If I simply place pll_e('my-theme', 'Enter your search term.'); in the theme templates, then I create a dependency of the theme on the polylang plugin. This could be bad if I need to disable polylang at any time - which will occur.

    I thought I could wrap all pll_e calls in a theme specific function called mytheme_e_($string) which is defined in function.php and will automatically add the context (e.g. 'my-theme') and check "if polylang is installed, then pll_e(...), otherwise e_(...). This method does create a lot of overhead but would allow me to remain flexible.

    It would be very helpful to add this documentation in the polylang readme or the polylang documentation pages. Thank you in advance!

    Additional resources:
    http://wpml.org/documentation/support/wpml-coding-api/
    http://polylang.wordpress.com/documentation/

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

  2. Chouby
    Member
    Plugin Author

    Posted 8 months ago #

    The wordpress-seo plugin registers its strings somehow automatically. How does it do that?

    That's pretty easy. You store your strings in an option (as you would do without any multilingual plugin), then create a wpml-config.xml file describing the options you want to translate. Thus you don't have to care if Polylang is activated or not.

  3. jjchinquist
    Member
    Posted 8 months ago #

    Thanks for the prompt reply, this is what I needed.

    When I have worked out a good options array for my theme, I will post it.

    It will be helpful in the future if you add it to the documentation site as a "Do this if you want to use the administrative forms to translate common words or phrases in the UI".

Reply

You must log in to post.

About this Plugin

About this Topic