How to implement i18n without performance overhead
i18n is always difficult to implement and costs a lot performance. Normally, implementations use gettext() or a custom t()-function to translate a string. t() searches a INI or XML file for a translation key and returns the value. For example t('setting', 'de'), gives the German translation 'Einstellung'. Typical optimizations use associative arrays (hashmaps) loaded into APC or Memcached. This requires a lot of memory for the array and produces a lot of cpu cycles for calling t() all the time. So the question is, can we do this better? Yes! We use a just-in-time compiler for our PHP files and write the compiled PHP files to disk, so APC can cache them like regular PHP files. An example PHP class looks like this: // example.php <?php class example { public function now() { return '{t}Hello World, now it is:{/t} '.date('{t}m/d/Y g:i a{/t}'); } } The "{t}" and "{/t}" patterns serve as opening and closing tags indi...