Interface translation in symfony - tool for teams
Wednesday, July 16th, 2008I mentioned in my previous post how we decouple the translation dictionary completely from the source so that a change in any text does not affect the templates. That has helped us a lot in several large projects.
Another issue which we frequently encountered when multiple people worked on the same project is conflicting and merging of the dictionary files. Since these files have sequential numbers in each <trans-unit> block, if multiple people want to add translations, these suquential numbers almost overlap and have to be rewritten manually while checking in.
So we decided to generate these symfony interface translation dictionary files using a script. So here’s what we do:
- put the translations in a properties file: Create one properties file for each language. So for English we create “translations.en.properties”. This has translations like:
USERNAME_LABEL=Username
PASSWORD_LABEL=Password
This ensures that even when multiple people add translations to these files (using a source control like CVS or SVN) there are no issues.
- Also put the following file createXML.php in the same i18b folder.
- Now you can simply call this script from the command prompt to generate the xml dictionary.
php createXML.php > messages.en.xml
That was pretty simple to do. There are some enhancements this requires, like it should by itself generate all translation files based on the properties files available. But thats for when i get more time to work on it.
