Qtranslate tutorial

by Karine in WordPress

Here is a quick Qtranslate tutorial for those who are a bit lost. I don’t know if it’s the best plugin for a multilanguage website, it depends on your needs, but for me, it was by far the best choice!😀

  • Have the same URL for posts (write only one post, not several)
  • Be able to translate everything: categories, templates, etc.
  • Clean URL: /en/postname for example

Cons:

  • The post URL is only in one language => this if fixed with qtranslate-slug plugin

Installation

Install Qtranslate and choose the languages you want to enable/disable or delete.

Qtranslate languages

In the advanced options, you can choose the type of URL you want. I chose pre-path mode because it’s prettier.

Qtranslate url

If you already have categories and tags, you will have to edit them to translate them. When you add new categories, don’t forget their translations !

Qtranslate tags

Usage

Note: I will use x1 and x2 instead of en and fr to not mess up my codes (since Qtranslate recognize them if I put en & fr).

How to change the blog title?

Just write [:x1]English title[:x2]Titre français directly in the blog title input on WordPress. x1 and x2 are your languages of course (en and fr for example). It should also work for widgets and some plugins like All in One SEO Pack.

How to insert multilanguages text in my theme ?

_e('[:x1]English text[:x2]Texte en français');

You can use this code for almost everything. Let’s say a different stylesheet for each language:

_e('[:x1][:x2]');

How to translate WordPress template tags ?

Let’s translate the_content() :

the_content(__('[:x1]Lire la suite[:x2]Read more'));

This code snippet will show the correct translation of the “Read more” text if you have decided to show only excerpts on your blog. An other example with edit_post_link() :

edit_post_link(__('[:x1]Modifier[:x2]Edit'), '', ' | ');

How to display a language chooser with flags ?

Insert this code wherever you want the language chooser to be:

echo qtrans_generateLanguageSelectCode('image');

You can style it with CSS:

.qtrans_language_chooser { list-style-type:none; }
.qtrans_language_chooser li { float : left; margin-right: 20px; }

If you want to only display the flag of the inactive language, add this code to your CSS:

.qtrans_language_chooser li.active { display : none; }

If you don’t want flags and simply text, use this code instead:


echo qtrans_generateLanguageSelectCode('text');

Gửi phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s