CakePHP URL-based language switching for i18n and l10n (internationalization and localization)

Update (08/03/2012): Dorin M. has refactored this solution for 2.x series, look for the code here. For details of what’s going on, read on below. ———– I should preface this post by saying that it does not cover the basics of i18n and l10n so, please, first take a look at the manual or one of the helpful cake books on how to get the basics going. To better understand the goal and why some things were done the way they were, I’ll summarize the requirements: The app has to support two languages or more (in this case English and Russian) Default language is English The language switching is based on a URL param The URL format should be: example.com/eng/controller/action Language choice should persist in the session and a cookie Just a note here… there are other ways to determine the language requested by the user, for example it could come from a domain name like eng.example.com or rus.example.com. Hopefully the approach outlined here will also be helpful if other methods of language switching are used in your app… Also, worth while to mention, that having language name in the URL (as opposed to just reading it …