Deterministic function calls always lead to wasted performance. They have to be computed every time but will always return the same boring result. Let’s get rid of them!
Example:
Assume your abstract controller provides a translation function $controller->translate()
$this->translate('helloWorld'); |
$this->translate('helloWorld');
will always return “Hello World”. We can easily replace the function call with the static content.
It’s getting a little more tricky as soon as you pass some parameters to the function.
$this->translate('helloUser', $username); |
$this->translate('helloUser', $username);
The main translation part still is static, so let’s just replace the dynamic part.
sprintf('Salut %1$s', $username); |
sprintf('Salut %1$s', $username);
Built-in functions like sprintf will always be faster than your custom-made translate-and-replace stuff.
Finally store the pre-processed script for each language and let you autoloader choose which one to use.