This Website requires your browser to be JavaScript enabled.

Make Your Website Multilingual Using WordPress Plugin – qTranslate

thumb_translate

When I redesigned this blog, I mentioned that I haven’t added one function that I wanted to use yet. Today I finally added it! Yes, I start to post in English as well! Woohoooo! It took for 2 years since my friends told they wanted to read in English. Thank you for waiting! In this article I’m going to show you how to use WordPress plugin “qTranslate” to translate your WordPress blog.

qTranslate General Setting

Download qTranslate and activate the plugin through the ‘Plugins’ menu in WordPress. Let’s get started from settings > Language menu.

qTranlate General Setting

Languages are displayed with flags below. Enable languages that you want to use.

Check the radio button that you want to use as a default

Click “Save Changes”. You’ll see languages that you chose. Check the radio button that you want to use as a default and save it.

Add new

Go to Post > Add new. There are title and content area with multiple languages.

category name or tag name

You can also translate category name or tag name.

URL

You can choose one of 3 Modes to make your URLs pretty and SEO-friendly.

  1. Query Mode (http://webcreatorbox.com/?lang=en)
  2. Pre-Path Mode (http://webcreatorbox.com/en) *Default
  3. Pre-Domain Mode (http://en.webcreatorbox.com/)

I chose Pre-Path Mode. It seems additional configuration is needed for Pre-Domain mode.

Customize Your Theme

Date formatting

After I enabled the plugin, I noticed a date formatting was something weird. I fixed it by using <?php the_date(); ?> instead of <?php the_time(); ?>.
You also have a look “Date Format” which you’ll find from Settings > Language > Languages and click “Edit” in a language list.

Language Switcher

Language Switcher

Display a language switcher anywhere you want. You can choose from text, image, both, dropdown.

<?php echo qtrans_generateLanguageSelectCode('text'); ?>

If you want to display the only language that is not currently used, you need to customize a bit. Add the following code to functions.php.

function curPageURL() {
    $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {
        $pageURL .= "s";
    }
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
          $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     }
    else {
          $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
return $pageURL;
}

function langlist () {
   if (qtrans_getLanguage() == 'en') {
      echo '<a href="' . qtrans_convertURL(curPageURL(), 'ja') . '">日本語</a>';
   } elseif (qtrans_getLanguage() == 'ja') {
      echo '<a href="' . qtrans_convertURL(curPageURL(), 'en') . '">English</a>';
   }
}

Translate Theme Files

You can use the following useful code to translate texts in theme files. It would be good to use to short texts such as navigation menu or headings.

<?php _e("<!--:en-->english<!--:--><!--:ja-->にほんご<!--:-->"); ?>

If there are many areas that you need to translate or you want to use different files by the language, you can use qtrans_getLanguage(). I used it to load “en.css” for English page.

<?php if (qtrans_getLanguage() == 'en') { // English ver ?>
   <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/en.css">
<?php } ?> 

All in One SEO Plugin

All in One SEO Plugin

You can translate texts with the code above image says for All in One SEO Pack.

Something Weird When You Tweet

I’m using WordTwit to automatically tweet when I published a new post. But It was tweeted like this:

Webクリエイターボックス:<!–:ja–>Twitter 人気のつぶやき 1/14~1/20 2012<!–:–> tinyurl.com/7x6rbje

You’ll see tags…

Since __() is the localization module for the translation of strings, I edited plugin file “wordtwit.php” on line 887 from

$message = str_replace( '[title]', $my_post->post_title, $message );

to

$message = str_replace( '[title]', __($my_post->post_title), $message );

There is also popular plugin “WPML” to translate your blog. I used both and I like qTranslate better because it’s very easy to customize and it’s free! (WPML is not but they offer 30 days money-back guarantee) The best way is to test both plugins by yourself.

Translating… It would be not easy but I’ll enjoy :)

Source: What is the qTranslate lang switch code?

Advertisement

Related Posts

Share

  • このエントリーをはてなブックマークに追加

Comments

  • Ivo

    Hey there, thank you for this extensive info, exactly what I was looking for.

    I only got one question: Where exactly do I put the language selection code in my header.php to make the text selection appear as part of my menu?

    Can you help me with that? I tried it for hours and can’t get it to work.

    Thank you so much

    Ivo

  • http://webcreatorbox.com Webクリエイターボックス

    I haven’t tested, but following code should work:

    ”)); ?>

    Don’t forget to add

    add_theme_support(‘menus’);

    to your functions.php to enable a custom menu feature.

    I hope it helps you!

  • Alejandro Robles

    Hi Mana, thanks for your great article… helped me at last to be able to add a language selector to a website I’m developping… My issue is that when I put the selector in ‘text’, ‘both’ or ‘flag’ mode it appears in my theme organized in bullets instead of all options (i’m using 3 languages) in a same row… this pushes the content down makeing a big and ugly space where bothe side where the selector is… Have any idea how I can but the ‘selections’ in one single row as it appears in your example images?

    Thanks!

  • Joe Kingman

    Hi guys,
    does anyone know how to make a multilingual site title? The header?
    Please share some advice.
    The website is atomsredmash.ru
    Thanks!
    George

General / News

More

Tutorials

More

Inspiration / Design

More

Search Within a Site

About Me

About Me

My name is Mana and I am a web designer based in London, UK. After I worked as a graphic designer for 2 years in Japan, I graduated from web designing institute in Vancouver and worked as a web designer there and in Sydney, Australia. Check this page if you want to know further information and also you can follow me on Twitter.

  • Random
  • New