wordpress, atahualpa, xLanguage and widget titles translation

Posted on Feb 6, 2010 in All Articles, Linux and Open Source, Programming

My site is implemented in wordpress. I use the very nice atahualpa theme from bytesforall and a special plugin for multilingual websites, xLanguage from Sam Wong.

Multilingual support is very important for many people and I hope wordpress will support directly multilingual sites in the future. Currently xLanguage is the best approach in my opinion and I have tried most -if not all- multilingual wordpress plugins.

Of course nothing is perfect and the atahualpa and xLanguage combination do not escape from this rule. There are some small problems when you use them together, some titles (widget titles for example) do not get translated. The fix is considered simple but if you have no knowledge of php or coding in general it will give you a hard time. This is especially true since nobody has posted a solution on the internet. As my moto goes, if it isn’t on the internet then someone should put it there, I will give you an example of how I fixed this for the BFA Recent Comments widget as can be seen at my home page.

The Fix

It all starts with a “light” read – you can skip it though. Sam Wong explains at his blog how you can add xLanguage support to themes and widgets that do not work out the box. Just rollover to the widget title customization section.

You may have noticed that the easy way (adding hooks from your site’s admin panel) does not work. We have to go for the second easiest way and that includes a text editor. Yay!

I will show you how to do it for the BFA Recent Comments widget and hopefully you will manage to do it for the rest of your widgets.

First you have to find where the php function file for the widget you want to fix rests. This is easy. Just look in the functions directory in atahualpa’s catalog. In your wordpress installation that would be:

wordpress_directory/wp-content/themes/atahualpa/functions

The file we need is not surpisingly called bfa_recent_comments.php. If you manage your site remotely just download the file to your computer. Also now would be a good time to back up this file, just in case.

Open bfa_recent_comments.php with your text editor. It is php code alright but no need to get alarmed. Move down until you reach the section with the Fetch our parameters comment. This is for my version at line 61. After that some variables assignments take place. What we are interested in is the $bfa_rc_title variable. In this variable our widget title is stored.  Had we opened the bfa_popular_posts.php file which implements the BFA Popular Posts widget, the variable we would look for would be $bfa_pp_title so I hope you get the point.

The critical line looks like this:

$bfa_rc_title = $bfa_rc_options['bfa_rc_title'];

What we need to do is to apply the localization filter as Sam Wong describes at his site. Just change the line to look like this:

$bfa_rc_title = apply_filters('localization',$bfa_rc_options['bfa_rc_title']);

That’s it! Save the file and upload it to your site (if needed) to replace the original one. Now your BFA Recent Posts widget title supports xLanguage translation!

Share

5 Comments

  1. I have same problem.
    thanks for this article.

  2. hi Marios,

    i’m also using atahualpa as a theme and just installed the plugin xLanguage, but the span element doesn’t seem to work: a “test” page with the 2 languages (spans included all over) shows both.. what am i doing wrong?

    And a second problem i’d like to fix: the homepage of the site (i’m not using wordpress as a ‘real’ blog) is a certain static page. Since xLanguage is installed, the home-button in the page menu bar as well as the language button on the homepage refers to the most recent post.. and that’s not what i want in this case! How can i change that?

    i’m hoping soooo much that you can help me out..
    thanks already!

  3. Hello! I am not sure if I can help since xLanguage worked out of the box for me (except the widget titles) but I will try.

    Since you refer to spans I take it you checked the HTML version of your posts in the editor to check for the code xLanguage added. Any text (or content) not in a language span will be displayed for all available languages.

    Other things that could go wrong is if in the options page of the plugin you changed the composing settings (ie you set the parser to use square bracket and the toolbar XHTML) or you deleted some hooks.

    I can’t think of anything else.

    As for the second problem I don’t think that it is xLanguage’s fault. It isn’t logical for xLanguage to change your links. Could it be a problem with permalinks (you have to setup xLanguage accordingly in the options page)?

    As you see I use a different theme now and with both Atahualpa and the current one I never experienced such problems.

  4. How do you have that permalink with xlanguage? you have thedomain.com/en and my problem is that xlanguage make me: thedomain.com/lang/en

  5. I switched to qTranslate a couple months ago.
    The main reasons were that xLanguage seemed dead as a project (or with very slow progress) and the editor was far from consistent from me.

    I liked xLanguage because I could fairly easy translate my theme and plugins by editing their source code. Of course this was a major mistake, since I couldn’t upgrade them that easily.

    So for now, I suggest qTranslate. It didn’t need any source code editing for my current site layout.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>