Follow this Blog!

Oct 23, 2012

f Comment

[SOLVED] Setting a Locale in Joomla 2.5!

Amazon This article will teach you how to set a locale in any module or component on Joomla CMS! Setting a locale can be critical to your success if you are developing for a language other than English. In this article we will be setting the locale to Chinese, or 'zh_TW.utf8' which is the locale's representation on my Unix box.

If you don't know how 'zh_TW.utf8' comes from read How Do Unix Locales Work?
First take a look at my Unix and shell's version:

ubuntu@domU-1:~$ cat /etc/issue
Ubuntu 10.04.4 LTS
ubuntu@domU-1:~$ bash -version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

Take a look at my Joomla version
Amazon The following is information shown by going to Site -> System Information.

PHP Built OnLinux ip-10-1-2-3 4.5.6-7-ec2 #18-Ubuntu SMP Mon Oct 18 21:00:20 UTC 2010 i686
Database Version5.1.61-0ubuntu0.10.04.1
Database Collationutf8_general_ci
PHP Version5.3.2-1ubuntu4.14
Web ServerApache/2.2.14 (Ubuntu)
WebServer to PHP Interfaceapache2handler
Joomla! VersionJoomla! 2.5.4 Stable [ Ember ] 2-April-2012 14:00 GMT
Joomla! Platform VersionJoomla Platform 11.4.0 Stable [ Brian Kernighan ] 03-Jan-2012 00:00 GMT
User AgentMozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19

As you can see I use Joomla 2.5.4, but this tutorial applies to every previous version of Joomla. If not let me know!

See if the desired locale is available on your system
First you need to know if the locale you want to set is available on your system. Please read How Do Unix Locales Work? if you don't know how to do it.

Set Locale!
Find the place where you'd like to set the locale. Usually this place is prior to your view that is supposed to use the locale so that it can display the characters correctly.

For example if I am to set the locale to 'zh_TW.utf8' in 'pbbooking' component, a popular appointment component, then I add the following in the entry PHP script of the component which is components/com_pbbooking/views/pbbooking/view.html.php:
defined( '_JEXEC' ) or die( 'Restricted access' );
setlocale(LC_ALL, 'zh_TW.utf8');
That's it. Easy right?

If you have any questions let me know and I will do my best to help you!
Please leave a comment here!
One Minute Information - by Michael Wen
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael