CiviCRM Internationalisation

Published
2007-04-23 04:13
Written by
CiviCRM is localised into several languages and used by non-English communities around the world. Before it could be localised, though, it had to be internationalised – i.e., it had to be modified to make the localisation possible. My first assignment when working on CiviCRM was to take the English-only application, internationalise it and localise it to Polish. After a bit of thinking we decided to follow the gettext approach (and, actually, used gettext in the end), which means keeing the strings (words, sentences – texts in general) in English across the PHP code and Smarty templates and translating the strings on the fly if CiviCRM ends up being served with a non-en_US (American English) locale. The process of internationalisation consisted of two parts: (a) tagging all of the English strings across the PHP source and the Smarty templates, and (b) writing the translating engine. As the Drupal uses the t() function for their translation calls, we decided to call our translation function ts() and its Smarty counterpart {ts}. After having the strings wrapped in these function/block calls, we created the CRM_Core_I18n class, put the ts() function definition in the global scope, and made Smarty call it for {ts}-tagged blocks. The other end of allowing CiviCRM to be translated to various languages was to extract the strings into their proper POT templates and generate the PO files for all of the supported languages. This is done by the bin/create-pot-files.sh script, which calls the PHP and Smarty exctractors and generate the POT files to the l10n/pot directory (the civicrm-core.pot file contains the CiviCRM strings common to all installations, while the civicrm-modules.pot file contains the strings from the optional modules). The pot directory contains also the JavaScript widget calendar POT file, the POT file for localising Drupal string relating to CiviCRM and the two files for localising country and province names. Localisation of an application is not only the translation, though; it’s also means setting the way some things are being displayed, like dates (month or day first?) or monetary values ($30, but 30 zł). In CiviCRM, these things can be defined in Administer CiviCRM → Global Settings’ Localization and Date Formatting screens.