Support » Plugin: Polylang » [Plugin: Polylang] How to internationalize a theme ?

  • ResolvedPlugin Author Chouby


    There are still a lot of themes which are not internationalized by their author πŸ™

    Here is the procedure to do it… It is quite long but it could be worth it if you really like your (not yet internationalized) theme.

    First step : declare the domain

    Open the file functions.php and add these lines:

    add_action( 'after_setup_theme', 'setup' );
    function setup() {
    	load_theme_textdomain('your_theme', get_template_directory());

    Replace your_theme by whatever you want (no space)

    Second step : make your strings translatable

    Edit all your php files and look for all strings, for example
    'Read the rest of this entry »'
    strings are either found between single quotes or double quotes. Take care that not everything between quotes is a string that will be display.
    Then replace the string by :
    __('Read the rest of this entry »'), 'your_theme'
    Take care : there are 2 undescores. Replace ‘your_theme’ by the name you chose in functions.php

    Once you have edited all your strings, your theme is ready for translation !

    More information can be found in the codex

    Third step : Translate your strings using either poedit or the plugin codestyling localization.

    The .po and .mo have to be placed in your theme directory and must be called locale.po and in which locale is to be replaced by the WordPress locale in which you are translating your theme (for example : fr_FR, es_ES or lv)

    Hope it will help !

Viewing 7 replies - 1 through 7 (of 7 total)
  • This is very interesting and useful!
    However, I am looking for something very similar but not exactly the same.

    I would like to add to my theme some custom strings with translation. In theory, I would like to have the possibility to add more strings to the “String translation” page of polylang.

    Example: suppose on my theme initial page I have a greeting that can be modified by the user using the theme: “Welcome, my dear user!”
    It would be nice to have in the theme option page, the possibility for the user to add user customized tranlsation of thet string.

    Do you know the easiest way to do that?

    Plugin Author Chouby


    You have to register your string on the admin side with pll_register_string and display it on frontend either with pll__ or pll_e.

    More information is available in the Polylang documentation (found in polylang/doc directory) and in this topic:

    thank you for the reply. At the end, it worked perfectly. The plugin works in a beautiful way.
    I found out that I could not understand 100% the working of the plugin even after reading the documentation.
    So, if I can give a suggestion, I would add some descriptione to the documentation, add some examples and so on. The plugin is so cool that is a pity one can not use it at its full potentiality because of the documentation.

    I have had the text of my English blog translated into Greek and Chinese by people who speak those languages.

    I just realised that WordPress/Polylang does not support the Greek and Chinese characters which I copy and paste into the forms of my WordPress dashboard (e.g. adding new Posts). Characters such as “ε…³δΊŽ” just show up as “??”.

    Is there a way for me to simply copy the .mo files for these languages into the theme’s directory so that the text shows up? A “poor man’s” translation without the WordPress strings fully translated.

    I am hoping to launch ‘readable’ Greek/Chinese versions of my blog in a hurry. I would then take my time to use Codestyling Localization to fully translate the site/theme.

    Let me know if this will work πŸ™‚

    Also, what exactly do you mean by ‘declare the domain’ in the original post?

    Plugin Author Chouby


    Unfortunately I am not a specialist of non latin characters. Maybe you should try to get help from Greek or Chinese forums as your issue may come from elsewhere (I copied and pasted the Chinese characters in the tagline and one of its translation of my WordPress test site and it works perfectly). Maybe a database encoding issue ?

    Declaring the domain is just adding the few lines of code in the file functions.php as suggested.

    Just wanted to point out that the third code example in the original post of this thread should read: __('Read the rest of this entry »', 'your_theme') and not __('Read the rest of this entry »'), 'your_theme'

    Plugin Author Chouby


    Of course you are right. Thanks for correcting this !

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Polylang] How to internationalize a theme ?’ is closed to new replies.