I think most of Joomla! users came across extensions with parameters and options like ja or sì and you figure it's yes from the context or by trial! Is it just OK to ignore internationalization/translation and assume that the user will figure it out himself? It's Sì beside No so it's apparent it means Yes! If you think so; Think again!
Recently I was working on a website using Dutch as a default language. I logged in to the administration panel and started to work. The backend was in Dutch but I assumed everything will be OK since I work with Joomla almost everyday!! So I know the location of every thing and the icons will help etc ... I thought "It's OK, I will figure it out!". Three minutes later I was frustrated and took more time to do simple tasks. I logged out then logged in after choosing English instead of default; Work became easier after that.
Internationalization isn't hard, it's one more step you do to make your users happier. I am not talking about translating your work; just provide them with the solid ground they can use to make their own translations. When I started Calendar Stamp I got translations for 3 languages on the first week!
So if you want to take that step, 3 things you have to deal with:
- XML files (configuration).
- Extension Out-put (mostly in PHP files).
- Database Entries. (like translating contents using Joomfish. It will be discussed in a separate entity)
Text output in .xml
Consider this:
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5">
<name>Jobline Latest Jobs</name>
<author>Ahmad Alfy</author>
<creationDate>September 2009</creationDate>
<copyright>(C) 2009</copyright>
<license>Non-Commercial</license>
<authorEmail>ahmadalfy[at]gmail[dot]com</authorEmail>
<authorUrl>www.alfystudio.com</authorUrl>
<version>1.0</version>
<description>Display the latest jobs posted on Jobline.</description>
<files>
<filename module="mod_jl_listing">mod_jl_listing.php</filename>
<filename module="mod_jl_listing">helper.php</filename>
<filename module="mod_jl_listing">tmpl/_job.php</filename>
<filename module="mod_jl_listing">tmpl/default.php</filename>
<filename module="mod_jl_listing">tmpl/list.php</filename>
</files>
<params>
<param name="number" type="text" default="3" label="Number" description="Number of jobs to display" />
<param name="random" type="radio" default="0" label="Random" description="Random Review">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="view" type="list" default="default" label="View" description="Layout">
<option value="default">Default</option>
<option value="list">List</option>
</param>
</params>
</install>
It's a baisc xml file for Jobline Latest Entries (the module we created on the previous tutorials). We are going to provide internationalization for parts the output text to the user. In this case description and label attributes and the options the user will choose from. Take a look at this:
<params>
<param name="number" type="text" default="3" label="PARAM_NUMBER" description="PARAM_NUMBER_DESCRIPTION" />
<param name="random" type="radio" default="0" label="PARAM_RANDOM" description="PARAM_RANDOM_DESCRIPTION">
<option value="0">NO</option>
<option value="1">YES</option>
</param>
<param name="view" type="list" default="default" label="PARAM_VIEW" description="PARAM_VIEW_LAYOUT Layout">
<option value="default">DEFAULT</option>
<option value="list">LIST</option>
</param>
</params>
Note: code stripped for similcity.
As you can see the values of the label and description attributes are replaced with the prefix PARAM_ and the parameter name all uppercase. It's good practice to code it this way to make it easier in managing translations. The options are changed to uppercase too. You can use your own prefix if you want but we keep it that way for simplicity.
Now let's create the INI file. The name of the file should be like:
language(en-GB).the type of extension this file is used for(com_, mod_ or plg_).file name(same as the extension's name).ini
In this example it should be like : en-GB.mod_jl_listing_1.5.ini
Note: when creating language file for plugins, the plugin type should be mentioned on the name (plg_content, plg_system ... etc).
# @author Your Name
# @package Extension's Name
# @Language English
# @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# @version Translation Version
PARAM_NUMBER=Number
PARAM_NUMBER_DESCRIPTION=Number of jobs to display
PARAM_RANDOM=Random
PARAM_RANDOM_DESCRIPTION=Random Review
YES=Yes
NO=No
DEFAULT=Default
LIST=List
And you're done! It may look repetitive but it will help translators to create their own versions.
Text output in .php
Use the JText method every time you want to output text. This will output the requested string according to the active language. For Example:
<?php
echo JText::_('JOBLINE_INTRO');
?>
Adding languages to the extension installer
The last thing to do is to add the language file on the XML file for your extension:
<languages>
<language tag="en-GB">en-GB.mod_jl_listing_1.5.ini</language>
</languages>
That's all! Hope you found it simple and I will be glad to receive your comments and recommendations! Have a nice day.
|