sunsetsystems wrote on Friday, June 27, 2014:
In my recent work with WordPress I’ve noticed some parallels between that and OpenEMR about how translations are handled. They use a “__()” function that is analagous to our “xl()”, and variations of that similar to ours. This looks like something we can learn from.
Unlike our custom tools to build and load translations into the database, they use the Gettext libraries and tools. Language constants are loaded into “.pot” files, translations into “.po” files, and the .po files are compiled into “.mo” files for fast access by the code. The database is not involved. More info here for those interested:
http://codex.wordpress.org/I18n_for_WordPress_Developers
One immediate idea we can borrow is use of the PHP sprintf() function to translate strings that include a variable. For example, instead of:
echo xlt(‘You have’) . " $count " . xlt(‘messages’);
you should write:
echo text(sprintf(xl(‘You have %d messages’), $count));
Thus there is only one string to translate and the translations can be better adapted to their context.
There’s lots more detail and thoughts about best practices at the above links.
Food for thought.