Tag Archives: i18n

Some hate over Cake’s i18n

I'm really fond of CakePHP's principles, but I'm too tired of its i18n features. For some reason internationalization, although one of the really major requirements for every framework or CMS, is implemented poorly in most of the systems I've worked with. Django had few disadvantages (but few strong points as well) with its django-multilingual, and here it comes Cake with its toolkit for multilingual applications.

Comparing with few Java frameworks + CodeIgniter, I'm pretty aware of using locale-based apps with few languages for dynamic content. It's ugly as hell most of the times.

The beauty of Cake is mostly its 'convention over configuration' and dynamic admin panel generation. Admin panel is pretty neat, although there is no CMS-alike functionality and one should translate/adapt the admin for a project every single time. This is a problem that savant is taking care of, creating a multi-functional and reusable administrative panel. However, nobody has ever thought about creating something advanced like in Django's admin - data filters, field hiding, form populating module etc. Everything is hardcoded (actually spitted from the code generator, which is fine, automagic should be based on something and code must be there at some point) but not flexible at all except if you don't rewrite your admin generator.

The other thing is the multilingual content.

Designing i18n stuff in CakePHP is done by Translate behavior. You define your languages in the core file (or bootstrap in older versions) and you use it for localization. Also, your models actAs Translate behavior and you need to define the fields to be translated.

What is missing here is that because of the database normalization, these fields in question are not in the model table, but in the translation one. For that matter you cannot create a multilingual views for add/edit/view/index, because you miss some of the important fields (usually such as name/content that need to be translated in other languages as well). Also, relations in the previous abstraction level with translate tables are done transparently and using find() with translated fields is pretty hardcore. 

Croogo is a pretty neat CMS based on Cake. Translation there is modified by Fahad and he had done few changes in the main mechanism. Also, in order to add some translation, you do the following:

  • enter the base material and submit
  • view the material
  • click on a 'translate' button
  • select a language to translate in
  • fill data for the language in question

This one ain't bad, but it requires 5 steps for adding one translation. What if we have 5 languages?

Django's multilingual module is better in my opinion. It iterates over the languages and it outputs all translatable fields for every language in one page. When you add content, you could insert the whole data in one window or skip the unnecessary details at first. That's a better one. However, Django has a different approach (the one that jose is taking into consideration - actually creating database over the models and not MVC over a database). This way connection between fields for translation could be predefined in a smarter way. 

Why should all of that be so hard? Cake needs to be rapid and DRY and KISS, but admin needs to be changed every time, translation is tough to configure, administration is not straight-forward with its acl (and tens of auth modules). Croogo does a good job with putting all of that in one package, but it's too heavy sometimes (Cake is not the fastest framework after all). I really need there is a place left for a good i18n module, some killing-auth lib and a better convention definition for even more rapid dev.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Django translations: multilingual, i18n, app names

 Django is a popular web framework written in Python that provides dynamic generated content and allows rapid development for different systems in the Internet. It provides a great interface to other products (via web services), gives ability to design a scalable application and most important, lies on a powerful language as Python (in other words, what you could do in Python, you could somehow reuse it in Django either by a component or by defining a custom logic down there).

In my experience two of the most important things in a web application (no matter the framework, system and language) are the user management and multilingual support. Django has an Auth module that does most of the things you need - provide users and groups, powerful permission API for each model and action down there and many methods to be overriden from the framework to fine tune the filtering if needed. As for the multilingual support, there are few steps to be followed.

Translating the static content

i18n support for Django - in the Django book. You have the uggettext_lazy (and two more) functions to translate the local based strings in your models, views and so on logic python parts. As for the templates, you could use trans and blocktrans tags for the static content down there.

Translating files is easy - via 'makemessages' and 'compilemessages' you get .po files (for PoEdit or any text editor) and then you compile them for Django to interpret.

Translating models and app names

Translating models for the admin is easy - just add the verbose_name and verbose_name_plural in your Meta class and make that visible for the makemessages.

App names is kind of a mystery for me as well. I saw this guy using the __init__.py and adding application names there. It works for me - my application recognizes them and generates the appropriate literals in the .po files.  


A module named django-localeurl could address all your request to a certain subdirectory for a given language - lets say site.com/en , site.com/es and so on. Based on that your content could automatically detect the current language and load the right translation. Nice, huh?

Multilingual content

django multilingual exampleWhat if you need a content translation for every language in your site? Either it is a news portal or a blog, you could add a new language in the settings.py anytime and just get an additional text field in the admin panel for the new language. This is why django-multilingual exists. You define the fields to be multilingual and you get a field for every language. With the help of localeurl you just get the right translation in the end with some automagic in between :)


At the moment I do use a CountryMiddleware to get the country on request via subdomains. I have Country model which has a name (of the country) and subdomain (for the subdomain). 

A trick to retrieve the subdomain of a webpage you could see here. Then all you need is to call your model and use the get_object_or_404 function to add this one to your request (so the country is visible globally).


del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com