Shopping Basket

 x 
Cart empty


Popular Items

Find Us Elsewhere

Using Language Files With Joomla Extensions

Joomla! is popular around the world, and is used to build websites in many languages other than English. So a good question is, is there a way to make an extension translatable into other languages, without needing to hack the extension code? The good news is that the answer is 'yes'. That is what language files are for.

Language Files

Language files are stored in the Joomla language folder, there is one of these in both the frontend and backend of your site. If you look in the language folder you will see that it contains a folder named according to the language of your site. For example, if your site uses Polish, there will be a folder called pl-PL. This will contain the Polish files for your site. It should contain a file for each extension that your site uses, named after the language, and then the extension. For example the English language file for the Joomla content component is called en-GB.com_content.ini.


The format of a language file is fairly strict. Firstly it must be a plain text file which uses the UTF-8 multi-byte character encoding. If you don't save any language files that you create or edit in that format then you will have problems.

The file itself consists of a set of keys, followed by an equals sign, then the language translation for the key. In Joomla 1.5 the key could contain spaces, but in Joomla 1.6 and 1.7 this is not allowed, also the language translation must be enclosed in double quotes ("). See http://docs.joomla.org/Specification_of_language_files for further information on this. Comments must be preceded by a semi-colon (;).

For example the content component in English contains entries like the following:-

COM_CONTENT_ARTICLE_VOTE_SUCCESS="Thank You for rating this Article."
COM_CONTENT_ARTICLE_VOTE_FAILURE="You already rated this Article today!"

Using Language Files in an Extension

To use language files in your own extension you need to specify the file in the xml installation manifest, for example:-

 <languages folder="languages-front">
   <language tag="en-GB">en-GB/en-GB.com_myExtension.ini</language>
   <language tag="pl-PL">pl-PL/pl-PL.com_myExtension.ini</language>
 </languages>
  

The 'folder' attribute is used to specify the folder in the installation package which contains the files. The example shown is for frontend language files, if you are using administration language files then include a similar entry inside the <administration> tag of the xml file.

Then it is very straightforward to use these to make your extension translateable. The JText class (defined in libraries/joomla/methods.php) is used to do this. Instead of using literal text in your extension, such as:-

"Thank You for rating this Article."

you can use

<?php echo JText::_('COM_CONTENT_ARTICLE_VOTE_SUCCESS'); ?>

The appropriate language translation will be substituted for the key upon output. This may seem like a lot of effort to go to at first, but it will make life hugely easier for anyone who wants to use your extension in a foreign language, or indeed who simply wants to modify the text without diving into the code, and will help to make your extension popular with users.

Notice that in the content component example quoted above the language key is prefixed with the name of the component 'COM_CONTENT'. While this is not compulsory at the moment it does make good sense to follow this convention in order to avoid naming conflicts with other extensions.

Language Overrides

Since Joomla 1.6 the Joomla language folder has also contained an 'overrides' folder, this allows you to create your own language overrides. The main reason to do this is if you wish to modify the Joomla core language files. In the past you could do this, but you could end up losing your edits when you updated your Joomla installation, if the update package included the language file that you had edited.

Now you can put a file in the language overrides folder name after your language, for example 'en-GB.override.ini', this will contain any overrides that you wish to make. Remember that the file must be saved using the UTF8 character encoding.

For example if you want to change the mod login username and password reminder text you can put something like

MOD_LOGIN_FORGOT_YOUR_PASSWORD="Password Reminder?"
MOD_LOGIN_FORGOT_YOUR_USERNAME="Username Reminder?"

instead of the default definitions in en-GB.mod_login.ini:-

MOD_LOGIN_FORGOT_YOUR_PASSWORD="Forgot your password?"
MOD_LOGIN_FORGOT_YOUR_USERNAME="Forgot your username?"

 

Author Profile