Improve i18n
Compare changes
Files
3@@ -24,7 +24,7 @@ $logsqltm = LoggerManager::getLogger('SQLTIME');
@@ -340,6 +340,8 @@ class PearDatabase{
@@ -351,7 +353,7 @@ class PearDatabase{
@@ -828,7 +830,7 @@ class PearDatabase{
Welcome to Vtiger Community. To gain access for account, please contact [ community @ vtiger.com ]
This update contains :
Vtiger will first try to find a user choosen locale in the user settings.
If none found, it will now try to use the Accept-Language header provided by the browser. It's especially useful in login screen for multilingual users.
Finally, it will still fallback to global configuration
The use of context string lets tuning translation in special cases, e.g. taking care of gender.
Many languages have differents ways of taking plurals in account, from none to 6 plural forms.
The basic one is __(KEY_NAME)
that will return the value of KEY_NAME taken in vtiger.php translations file.
If you use m (__m(KEY_NAME, MODULE_NAME)
), it will return the value of KEY_NAME taken the module translations file (MODULE_NAME.php).
If you use x (__x(KEY_NAME, CONTEXT_STRING)
), it will return the value of KEY_NAME associated to the given CONTEXT_STRING.
If you use n (__n(KEY_NAME, COUNT)
), it will return the value of KEY_NAME linked to the right plural form for COUNT items.
You can mix all of these options : __mx
, __mn
, __xn
, __mxn
For instance, the actual vtranslate
function is the same than __m(KEY_NAME, $MODULE)
.
The pattern used for key naming is the same than JS library I18next (see https://www.i18next.com/plurals.html and https://www.i18next.com/context.html).
The context is simply added after key name separated by an underscore.
Plurals are written like in gettext way. For a language with 2 plural forms, you keep KEY_NAME for singular and KEY_NAME_PLURAL for plural. For a language with 3 or more plural forms, it will be KEY_NAME_0, KEY_NAME_1, ..., KEY_NAME_N for each cases
Mix of both is on the form KEY_NAME_CONTEXT_PLURAL for example.
Let's say that we have these values (totally useless in real life
in languages/en_us/users.php
$languageStrings = array(
'LBL_USER' => 'User',
'LBL_USER_PLURAL' => 'Users',
'LBL_USER_MALE' => 'Mister User',
'LBL_USER_FEMALE' => 'Miss User',
'LBL_CONNECTED_USERS' => '%d user is connected',
'LBL_CONNECTED_USERS_PLURAL' => '%d users are connected',
);
in vtiger.php
$languageStrings = array(
'LBL_USER_MALE_PLURAL' => 'Many main males users',
'LBL_USER_FEMALE_PLURAL' => 'Many main female users',
);
Calling __('LBL_USER')
will return 'LBL_USER' because no key is defined in vtiger.php
Calling __m('LBL_USER', $MODULE)
in a users Module layout will return 'User'
Calling __mn('LBL_USER', $MODULE, $CONNECTED_USERS_COUNT)
in a users module layout will return for instance '10 users are connected'
Calling __mxn('LBL_USER', $MODULE, 'FEMALE', $CONNECTED_USERS_COUNT)
in a users module layout will return 'Miss User' if $CONNECTED_USERS_COUNT = 1 and 'Many main female users' if $CONNECTED_USERS_COUNT > 1 (fallback to main translation file)
Copyright 2023 Vtiger. All rights reserved.