Making Plugin **** work with qTranslate

Having Problems? Need Help? Post here!

Making Plugin **** work with qTranslate

Postby Qian Qin » Thu Dec 04, 2008 11:05 pm

qTranslate tries to modify every String it can get its hand on, but unfortunately, custom Plugins often don't supply filters nor use Gettext for their Strings, so it is impossible for qTranslate to filter out the correct language. You can fix it by yourself if you have some PHP knowledge, if not, you will need to ask the author of the other plugin to take a look at this page, as I don't have the possibilty to modify their plugins.

There are 2 basic ways to make qTranslate work with your plugin:
  • Use Gettext to filter all output. Wordpress already includes this function, so it can simply be added everywhere.
    Code: Select all
    //So if you have something like this
    do_someoutput("Code");
    // replace it with
    do_someoutput(__("Code"));

  • Use qTranslates internal translation filter. This function will be faster, but you will need to check wether the function exists or not (for non-qTranslate users).
    Code: Select all
    $filtered_string = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($raw_string);

Notice: __('""); will output meta information of the .mo file if called with an empty string! So you should make sure that it is only called with an non-empty string.

My suggestion would be using Gettext for texts that are non-dynamic (Title, Error Message). As for dynamic texts (comment text, blog entry text), I suggest using qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage() instead. Use something like this:
Code: Select all
if(function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) $output = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($output);


qTranslate also modifys the WYSIWYG editor (TinyMCE) are creates a second instance with the corresponding text area (id="qtranslate_textarea_content"). So if your plugin is inserting anything to tinyMCE, you will need to check if there is such a text area and if, insert to the qTranslate text area instead of the default text area.

If you are the author of a plugin and have trouble making your plugin work with qTranslate, feel free to contact me.
Qian Qin
Site Admin
 
Posts: 873
Joined: Thu Jun 19, 2008 12:14 pm
Location: Germany

Return to qTranslate Support Forum

Who is online

Users browsing this forum: MSN [Bot], Yahoo [Bot] and 2 guests