dts signature
At the BCN2019 sprint we discussed that we want to go forward with the dts
function to translate user data, e.g. civcirm_event.title
.
I would propose the following implementation:
/**
* Short-named function for user data translation, defined in global scope so it's available everywhere.
*
* @param string $entity_type
* String to mark the entity type, e.g. 'civicrm_event'
* @param string $entity_id
* String to mark the entity ID, e.g. 2
* @param string $field_name
* String to mark the relevant field name, e.g. 'title'
* @param string $db_value
* Current value of the field
* @param array $params
* Array an array of additional parameters.
*
* @return string
* the translated string
*/
function dts($entity_type, $entity_id, $field_name, $db_value, $params = []) {
// call the regular translation with the 'civicrm-data' domain
$params['domain'] = 'civicrm-data';
$key = $entity_type . '.' . $entity_id . '.' . $field_name;
$translation = ts($key, $params);
// if no translation has been generated, we use the value
return ($translation == $key) ? $db_value : $translation;
}