Multi-language permalink in qtranslate

I am using qtranslate plugin for my WordPress site to make it a multi-language site.

Now I have got a requirement like

Read More

For English the url should look like www.sitename.com/contact-en
For French the url should look like www.sitename.com/fr/contact-fr

How can I accomplish this? (qTranslate is the plugin used)

Note: There should not be any post id coming in-between

As per the post in https://wordpress.stackexchange.com/questions/24061/multilingual-permalinks-qtranslate I tried http://www.3dolab.net/en/qtranslateslug-plugin-widget but ‘page not found’ errors are occurring. It looks like the author has stopped improving that plugin as per the 29th comment in that page.

Related posts

Leave a Reply

3 comments

  1. In qTranslate settings in admin panel open advanced options and check the radio button for using language prefixes after domain name. I assume you have French listed in Languages settings of the plugin correct. You may expect dates shown incorrectly after that, use php date function to fix that in your particular language settings (edit language). Like j F. See primer at minexrussia.com/2011 where ru prefix is placed the same way.
    To avoid en prefix, select english as default language and check setting in Advanced options for not to show prefix for default language. I suggest removing all other languages except en and fr in plugin settings.

  2. Having the “qtranslateslug-plugin-widget” plugin working in the admin side to store slugs in the slug table, I have put my own code in the user side.

    In the wp-blog-header.php page I have added my own code just before the inclusion of wp-load.php file. I took the url from $_SERVER['REQUEST_URI'], and using the slug and language in it, retrieved the post name and assigned the modified URI to $_SERVER['REQUEST_URI'] appropriately.

    For example:

    Before I edit: $_SERVER['REQUEST_URI'] = '/fr/french-slug';

    After I edit: $_SERVER['REQUEST_URI'] = '/post-name';

    Let me explain it in a little more detailed way

    1. Assign $_SERVER['REQUEST_URI'] to a variable

    2. Get the slug exploding it with slash (/)

    3. Check the slug in the slug database table which “qtranslateslug-plugin-widget” plugin is using and get the post id from there

    4. Now using the post id get the post name from the post table.

    5. Implode it in such a way as I have shown in the above example.

    6. Assign it back to $_SERVER['REQUEST_URI']