CodeIgniter 2.1 internationalization i18n with Subdomains |
[eluser]skunkbad[/eluser]
I have been looking at the i18n library and had made a suggestion that people check out how easy it is to just do it with subdomains, but it seems they either like doing things the hard way, or didn't understand. So I thought I'd post an example of how friggin easy it is. You don't need to mess with routing or any of that nonsense. You don't have to extend any classes. All you need is to set up a subdomain for each language besides the default, all pointing to the same application, and then modify the config/config file. For instance, on my dev machine which is xampp on Windows 7, I set up the domain and "es" subdomain like this (in vhosts conf): Code: <VirtualHost *:80> Notice that both the standard domain and "es" subdomain are pointing to the same location. I tried using cpanel with linux hosting at mddhosting.com to set up the subdomain, and it was even easier because it was all GUI. Again, just point the subdomain to the same location as the standard domain. Then you just put this in config/config below the default language: Code: /* Add languages in the $subdomains array as shown above. When you want to load a language, just use LANG as the second parameter: Code: $this->lang->load('filename', LANG); That's it. The language is loaded because of the subdomain. It couldn't be easier. One last note. If you are rewriting www to non-www, or non-www to www, you will want to make an exception to allow your subdomains. |
Welcome Guest, Not a member yet? Register Sign In |