Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Chouby

    (@chouby)

    Do you mean you want to translate strings you can enter in the WordPress SEO titles admin page ?

    Thread Starter lucabarbetti

    (@lucabarbetti)

    Exactly Chouby, but not only the titles, also breadcrumbs, rss and all the strings that are defined by the admin/webmaster in WordPress SEO settings. I think that those strings, if defined, should be translated because they either appear in google searches or on the front-end of the website (e.g. the breadcrumbs string “You are here:”) or rss feeds.
    In WordPress SEO plugin there is a WPML.xml which has tags that refer to all those strings, I don’t use WPML but I guess that they are there to make them translatable through WPML.
    Thanks a lot Chouby

    Plugin Author Chouby

    (@chouby)

    In fact, you will have to do manually what WPML is doing automatically thanks to this config file. You can do something like what has been done for the atahualpa theme:
    https://www.ads-software.com/support/topic/plugin-polylang-multilingual-theme-options

    First make a list of all translatable strings:

    pll_wpseo_strings = array(
      "title-home",
      "metadesc-home",
    );

    the wpml config file will help you building the whole list

    then create a function to translate this list:

    function translate_wpseo_strings($options) {
      foreach ($options as $key=>str){
        if (in_array($key, $pll_wpseo_strings)) {
          if (is_admin())
            pll_register_string('wpseo', stripslashes($str));
          else
            $options[$key] = pll__($str);
        }
      }
      return $options;
    }

    and finally filter the wpseo options with the function above

    if (function_exists('pll_register_string')) {
      add_filter('option_wpseo_titles', 'translate_wpseo_strings');
      add_filter('option_wpseo_internallinks', 'translate_wpseo_strings');
      add_filter('option_wpseo_rss', 'translate_wpseo_strings');
    }

    Thread Starter lucabarbetti

    (@lucabarbetti)

    Dear Chouby,
    your code sounds good to me and I tried to use it, unfortunately I am not quite a programmer and I must have put it in the wrong place because now I get only a white screen… on a lighter note, this way I have got nothing to translate! :o)
    I use a custom (twenty ten) child time and I added your code to its functions.php, completing the list of all the WordPress SEO strings that I want to translate, but it doesn’t work.
    Would you please tell me where I have to add that code?
    Thanks a lot, have a good day!

    Plugin Author Chouby

    (@chouby)

    Sorry, I wrote that too quickly and made some typos and errors. The first two code snippets must be combined:

    function translate_wpseo_strings($options) {
      $pll_wpseo_strings = array(
        "title-home",
        "metadesc-home",
      );
    
      foreach ($options as $key=>$str){
        if (in_array($key, $pll_wpseo_strings)) {
          if (is_admin())
            pll_register_string('wpseo', stripslashes($str));
          else
            $options[$key] = pll__($str);
        }
      }
      return $options;
    }

    The $ was missing in two variables. The third snippet is OK.

    The functions.php file would be a possible place in general cases but not with wpseo ?? because wpseo retrieves its options as soon as the plugin is loaded which will prevent to filter them in functions.php which is loaded later.

    Of course, you could add the code directly in wp-seo.php before the call to the function $options = get_wpseo_options(); but it would be removed at each plugin update.

    So it’s better to create a plugin and ensure it is loaded *before* WordPress SEO (thanks to the fact that WordPress sorts plugins by name ?? )

    So create a new php file called pw-my-plugin.php (the name is important and is chosen to make it loaded after Polylang and before WordPress SEO). Add these lines:

    <?php
    /*
    Plugin Name: MyPlugin
    */

    As well as all the code mentionned above. Then upload it in your plugins directory. And Go activate the plugin.

    And finally, you will have to upgrade to Polylang to 0.8.1 (or current development version) (thanks to you, I discovered that previous versions will create duplicate versions of the strings when it is registered several times as it is the case here).

    Thread Starter lucabarbetti

    (@lucabarbetti)

    Hi Chouby,
    this code works much better! In fact I followed your instructions and now all the WordPress SEO strings that I want to traslate appear in the strings page of Polylang settings ready to be translated.
    Since I added accidentally more strings than I needed to (e.g. breadcrumbs separator), I wonder if it is possible to disable those strings. I commented them out from MyPlugin but they still appear in the strings page of Polylang settings. It isn’t a big deal but it would be nice to get rid of those added by mistake or that aren’t used anymore.

    In order to test this combination of plugins I have set up a fresh WordPress 3.3.1 installation with only default plugins, Polylang, MyPlugin and WordPress SEO. As you suggested I updated Polylang to the 0.8.0.5 release (couldn’t find the 0.8.1 though). I have also translated all the (few) posts, pages and categories that I use as a test. Everything seems to work properly but the latest posts page (homepage in this case) doesn’t switch language, it sticks to the default english language.
    Thanks a lot Chouby, I really appreciate it.

    Thread Starter lucabarbetti

    (@lucabarbetti)

    Quick update to my previous post.
    I said:

    Everything seems to work properly but the latest posts page (homepage in this case) doesn’t switch language, it sticks to the default english language.

    Not exactly. In fact I have two languages other than the default one, and I have realized that with one of them the latest posts page works correctly while with the other it is ‘redirected’ to the default language (https://localhost:port), even if the mouseover shows the right link (https://localhost:port/fr/).
    I checked the configuration of the languages, posts, pages and categories and they seem to be the same for both languages.

    Plugin Author Chouby

    (@chouby)

    0.8.1 is not released yet… I have still a few things to correct before releasing it (as trying to understand what’s wrong with your home page), but I upload my development version time to time as it may help some people.

    Could you precise all your Polylang settings ? Your permalink structure ? And if you are using static page as front page (and page for posts) ?

    Thread Starter lucabarbetti

    (@lucabarbetti)

    Hi Chouby,
    Good news, I don’t know what happened, but it seems that restarting my pc fixed the problem of the homepage.
    Anyway I have these settings:

    • three languages;
    • three menus, one for each language;
    • Language switcher at the end of the menu, with flags, hides current language;
    • when the front page is visited, set the language as the browser preference;
    • remove /language/ in pretty permalinks;
    • hide URL language information for default language

    The Permalink structure is localhost:port/post-name/;
    The Front page is the (wordpress default) latest posts page.

    Thanks a lot!

    I’m sorry for bringing this thread up again, but I was looking for exactly this solution and it seems that it is not working for me. If my request is wrong in here, just say it and I’ll put up another thread.

    1. I set up the plugin and the strings finally appeared in the polylang settings->strings menu
    2. I translated the meta description because I think it would be helpful to have meta descriptions in two languages
    3. I realized that WordPress SEO just takes the Meta Description of the default language (English in my case). So even if I had translated the strings, they don’t appear in the source code in another language than the default language.

    Maybe there is a solution anywhere out there I haven’t found yet, but please help me with this. Thanks a lot!

    Plugin Author Chouby

    (@chouby)

    I remade a test and it works fine for me with the code above

    Funny thing, in my WP Test Environment it is still not working, but I implemented it now in my project and it works fine.

    Thanks a lot for your quick reply!

    Is it possible to make similar decision for All in one Seo ?

    Plugin Author Chouby

    (@chouby)

    I am glad to announce that Polylang v1.0 will no more request all these manipulations to be compatible with WordPress SEO ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Polylang and WordPress SEO – string translation’ is closed to new replies.