- b2evolution CMS User Manual
- Advanced Topics
- Translations (i18n/l10n)
- Internationalization (i18n) Guidelines
Internationalization (i18n) Guidelines
General Rule
All strings in PHP that need to be translated to a different language should be included in the T_()
function like this:
T_(’Hello!’)
When using b2evolution in English, this will return Hello!
. When using b2evolution in French for example, this will return Bonjour!
– provided, of course, that the string has been translated in the French language pack.
Javascript
Because JavaScript has different special character escaping requirements than PHP, all strings that are used in JavaScript should use TS_()
instead of T_()
, like this:
TS_(’Hello!’)
Deferred translation
Sometimes you need to assign a string to a variable but you don’t want to translate it right away. This is especially important if the user language is not known at the time you set the variable. In this time you want the string to be extracted from the source so translators wan translate it but you don’t want PHP to translate it right away. You can do this like this:
$var = NT_(’Hello!’)
When you later need to translate the string, you do:
T_( $var )
DO NOT TRANSLATE DEBUG MESSAGES!
As a developer, there are many times when you should NOT use T_()
on your strings. This is the case for:
- Debug messages, including:
- all messages that appear in the debug info at the bottom of the page in debug mode
- the AJAX debug log
- Log messages, including:
- all messages that go to a log file
- reports of scheduled tasks
- all message sin the system log (i7)
Those messages are too complex for translators to understand them and they will translate them wrong in 99% of the cases.
It’s better to have good English debug messages than incorrect translated ones.