qTranslate support for »Google XML Sitemaps« plugin

Having qTranslate, multilingual WordPress plugin, installed, brings some problems – between them are slower performance and incompatibility with other plugins. It is said, that having a XML sitemap helps you climb on Google rankings. And you can find a few plugins which support this. One of them is Google XML Sitemaps but it has a broken qTranslate support. This was fixed by a forked Google XML Sitemaps with qTranslate Support, but unfortunately it is not up to date and doesn’t translate categories and tags.

So, some coding was needed. To transfer the enhancement to the original plugin, I wrote two functions, which are stored in a separate file, so the new code does not intermingle with the original one. I also enhanced the functionality, so that besides URLs for home page and posts, the URL is translated for categories, tags, archives and author pages. It also works as correctly for enabling/disabling qTranslate’s “hide_default_language” option.

Download the latest version of »Google XML Sitemaps for qTranslate« plugin. Zip file contains the original and modified file “sitemap-core.php” and a new one “sitemap-qtranslate.php”.

To do: translation of URLs for subposts, static pages, taxonomy pages.

Update on 3rd of June: Corrected display of “last modification time” in “sitemap-qtranslate.php”.
Update on 4th of June: Corrected URL translations when not using qTrasnlate option “URL Modification Mode” set to “Use Pre-Path Mode”.
Update on 19th of August: The code was packed as an official WordPress plugin.

34 Comments.

  1. Daniel Henrique

    Hi.

    This patched version is generating an extra ‘/’.

    Expected:

    http://techdm.com/grails/?p=323&lang=en

    Generated:

    http://techdm.com/grails/?p=323/&lang=en

    Thanks.

    Best regards,

    Daniel.

    • Daniel Henrique

      $qt[“url_mode”] = $q_config[‘url_mode’];

      // Add an extra permalink url for every non-default qTranslate language
      if ($qt[“url_mode”] != 1) {
      $permalink = trailingslashit($permalink);
      }

      ============================================
      — sitemap-qtranslate.php.old 2011-06-04 15:27:23.000000000 -0300
      +++ sitemap-qtranslate.php.new 2011-06-04 15:46:08.000000000 -0300
      @@ -26,6 +26,7 @@
      $qt[“default_language”] = $q_config[‘default_language’];
      $qt[“enabled_languages”] = $q_config[‘enabled_languages’];
      $qt[“hide_default_language”] = $q_config[‘hide_default_language’];
      + $qt[“url_mode”] = $q_config[‘url_mode’];
      }
      return $qt;
      }
      @@ -46,7 +47,9 @@
      $languages = $qt[“enabled_languages”];
      }
      // Add an extra permalink url for every non-default qTranslate language
      – $permalink = trailingslashit($permalink);
      + if ($qt[“url_mode”] != 1) {
      + $permalink = trailingslashit($permalink);
      + }
      foreach ($languages as $language) {
      if ($qt[“hide_default_language”] == 1 && $qt[“default_language”] == $language) {
      $sitemap->AddUrl($permalink, $modified_time, $change_freq, $priority);

    • Daniel Henrique

      diff -u sitemap-qtranslate.php.old sitemap-qtranslate.php.new

      http://pastie.org/2019363

      Patched version

      http://pastie.org/2019360

      Thanks.

    • Thank you for reporting and correcting this problem. I made a little different solution: removed the “trailingslashit” function from “sitemap-qtranslate.php” and added it for translating only the home URL.

  2. Rodrigo Barona

    Hi DSmidge;

    Thnaks a lot for your plugin is soo interesting, but y¡the donwload link is broken.

    Can you fix it?

    I want to test it! 🙂

  3. Rodrigo Barona

    It works perfect! thanks a lot!

  4. Lembit Kivisik

    Hello, your patch looks promising. Any chance it does also work with “qTranslate slug with widget” sub-plugin which allows for translating the slugs of qT-translated posts/pages and stores the extra slugs in an extra, custom DB table?

  5. I really don’t now. I suggest you try it. Just install the patch and browse http://yoursite.com/sitemap.xml for your translation. If it doesn’t work I’ll look into it if a quick fix is possible.

  6. Thanks a LOT.
    Its work just great!!!
    Exactly the solution I’ve looked for!

  7. Lembit Kivisik

    Hi DSmidge, I tried but no luck. I also looked at the code of ‘qtranslate-slug-with-widget.php’ and tried to use filters it registers, e.g. qTranslateSlug_page_link() with your patch, but no luck either. Instead of digging deeper, I decided to generate the other language sitemaps separately for this one site where I need this. I still would like to thank you for your work with this useful patch: works like a charm w/ default qTranslate slugs. Cheers.

  8. Hi there,
    I’m also trying to get this work with “qTranslate slug with widget”… without any success. Did you guys manage to make it work?

  9. Hi,
    use “qTranslate” and “Google XML Sitemaps v3 for qTranslate”
    also use the plugin “qTranslate slug with Widget” the latter crete a permalink post or page in multiple languages ​​through the title.
    But it does not work with your plugin, takes the title of the default language.
    how can you fix this problem?

  10. Hi,
    I’ve the same problem as Lembit Kivisik and Dominick. I made “qTranslate slug with Widget” work for categories (http://wordpress.org/support/topic/plugin-qtranslate-slug-with-widget-categories-dont-have-multiple-slugs?replies=6#post-2335517) but don’t know how to have the full translation of permalinks in the sitemap.

    I think this is an “on the fly” implementation, but as now is, the “translated” Sitemap isn’t that useful. Basically, at least for me, creates 404 urls.

    Thanks!

  11. Hi,

    I also have the problem that the Google XML Sitemaps for qTranslate does not work correctly with the qTranslate slug plugin. The sitemap is generated but it does not generate the URLs inserted into the qTranslate slug plugin correctly. Also the chosen language of the WP Admin tool affects the sitemap creation.

    E.g. if my qTranslate primary language is chosen (Finnish) the sitemap URLs for the page /kissa/ look like this:
    http://www.domain.com/kissa/
    http://www.domain.com/en/kissa/ -> Should be http://www.domain.com/en/cat/

    If I Change the Admin language to English the sitemap URLs for the page /kissa/ look like this:
    http://www.domain.com/en/cat/ -> Should be http://www.domain.com/kissa/
    http://www.domain.com/en/cat/

    I only use pages for this site so I don’t whether the plugins work for posts etc.

    I have the following istallation:
    – WordPress 3.2.1
    – qTranslate 2.5.24
    – qTranslate slug with Widget 0.4
    – Google XML Sitemaps for qTranslate 3.2.5.1

    Has anyone had similar problems and if so how did you overcome them? What did you change and where?

    Thanks!

    Pirkka

  12. Same problem of Pirkka here.

  13. Same here, problem with slugs in sitemap :/

  14. Hi,

    I tried this version of the plugin but still I don’t get the different permalinks for different language versions of my posts on the sitemap. Just the different versions of the index.php page.

    I believe I have the same problem as the 3 users above.

    Could you fix this please?

    Thanks!

  15. No support?

    • I’m sorry I don’t reply sooner. As it is stated on the page, this plugin is a fork of “Google XML Sitemaps”. I only added features I needed and I don’t have lot of spare time to enhance the plugin further.

      Do you use “qtranslate-slug-with-widget”?

  16. Yes, I do… unfortunately the plug-in doesn’t support it and I can’t find a hack anywhere. I was hoping you’d have it working.

    • I’ll look into in on the weekend. I make no promises it will get fixed.

    • Unfortunately, I wasn’t successful with enabling slugs translation support. In my installation the categories don’t work (it doesn’t save the slugs), tags are not yet supported. I didn’t look at the pages yet.

      The changes I made trying to translate slugs on posts can be downloaded here. I called “qTranslateSlug_post_link” but all it did was translating the links to default language. Any suggestions?

  17. Hi , this is really a great thing having qtranslate and xml sitemap work together . but can I ask what is the reason to leave it like a fork ? why not integrate it as a native support on the original xml sitemap plugin ?

  18. hi im working in this project but i cant make the sitemap.xml en more than 1 lang… how does the plugin work? cant find any difference with the standard xml generator. thanks.

    • Sorry for the late answer. This plugin is modified to work with qTranslate – a plugin which enables you to write posts in multiple languages. With a generic XML Sitemaps plugin, the sitemap will only contain entries for default language.

  19. Please add “static” in functions to avoid “PHP Strict Standards”

    Thk.

  20. Hi DSmidge and all,
    Any update with regards to having sitemap for qTranslate with qTranslate slugs with widget?
    I am still not able to find any solution for this.
    Kindly help

  21. Daniel López Azaña

    I created a workaround for this problem wich allows posts, categories and tags to be translated correctly: http://www.daniloaz.com/en/google-xml-sitemaps-v3-for-qtranslate-doesnt-work-with-qtranslate-slug/.

    Hope this helps. I went crazy to fix this issue!