Will first try to find a user chosen locale in the user settings.
If none found, it will next try to use the Accept-Language header provided by the browser. This is especially useful in the login screen for multilingual users.
Finally, it will fallback to the global configuration
The use of context string lets tuning translation in special cases, e.g. taking care of gender.
Many languages have different ways of taking plurals into account, from none to 6 plural forms.
The cbtranslation::get() method has full support for context and plurals, among other features.
The basic usage is cbtranslation::get('friend') that will return the value of 'friend' taken from the module cbtranslation values (equivalent to the previous main translation file in include/language).
Next we can pass in the module as we did before with getTranslatedString, cbtranslation::get('friend','Users'), which will return the value of 'friend' taken from the Users module translations entries in the database.
The third parameter is an array with a set of options for the translation.
Some examples would be:
Finally, you can add more parameters to support sprintf formatting like this: cbtranslation::get('friendcountry','Users',array('language'⇒'en_us','context'⇒'female','count'⇒2),2,'England')
You can find a set of examples in our unit test for this module.
Let's say that we have these values
'LBL_USER' => 'User',
'LBL_USER_PLURAL' => 'Users',
'LBL_USER_MALE' => 'Male User',
'LBL_USER_FEMALE' => 'Female User',
'LBL_USER_FEMALE_PLURAL' => 'Many female users',
'LBL_CONNECTED_USERS' => '%d user is connected',
'LBL_CONNECTED_USERS_PLURAL' => '%d users are connected',
Calling cbtranslation::get('LBL_USER', $MODULE) will return 'User'
Calling cbtranslation::get('LBL_USER', $MODULE, array('count'⇒$CONNECTED_USERS_COUNT)) will return 'Users' if $CONNECTED_USERS_COUNT > 1 and 'User' if $CONNECTED_USERS_COUNT = 1
Calling cbtranslation::get('LBL_CONNECTED_USERS', $MODULE, array('count'⇒$CONNECTED_USERS_COUNT),$CONNECTED_USERS_COUNT) will return for instance '10 users are connected'
Calling cbtranslation::get('LBL_USER', $MODULE, array('context'⇒'FEMALE','count'⇒$CONNECTED_USERS_COUNT)) will return 'Female User' if $CONNECTED_USERS_COUNT = 1 and 'Many female users' if $CONNECTED_USERS_COUNT > 1
There is currently no webservice interface to this module's translation services. We could enhance the webservice getTranslatedString method, which, I think, would be the correct way to proceed.
In the mean time, a normal query should get you the translation you need:
select i18n from cbtranslation where translation_key = 'friend' and locale='es_es'
select i18n,Products.productname from cbtranslation where Products.productname = 'Sexy Leggings';
This enhancement to coreBOS is based on the work of @bertrand.wattel.
Thank you very much!! I'm sure vtiger will pay just as much attention to your effort as I did LOL
http://code.vtiger.com/vtiger/vtigercrm/merge_requests/238
http://docs.translatehouse.org/projects/localization-guide/en/latest/guide/start.html
http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms
https://www.i18next.com/plurals.html
https://www.i18next.com/context.html