I feel that Yii::t() lacks ability to provide context of textual value and when translations start to count in couple hundreds, it starts to be quite hard to understand what was meant with translation.
If we look at popular translation systems like "Crowdin" (example), they allow to provide message context to support translators.
Currently, only way to provide some helpful information using Yii::t() is to write something in "key" area, that in turn defies purpose of "source language", for example, if you write a message "Propose (button in issue tasklist table header)" until I change that translation to "Propose", that message still be visible.
I am guessing, that there is performance issue with long keys, and length limitations does not allow long context descriptions.
For backwards compatability, I would like to suggest 5th optional attribute to Yii::t($category, $message, $params = [], $language = null, $context = null) (but this is not very convenient) that would allow to provide some sort of context description.
Maybe, we could convert Yii::t() to allow passing in first attribute array of attributes, like Yii::t(['category' => 'message.category', 'message' => 'message text', 'params' => [], 'language' => null, 'context' => null]) or even allow shorthand for category and message with numeric keys Yii::t(['message.category', 'message text', 'params' => [], 'language' => null, 'context' => null]).
With \yii\i18n\DbMessageSource, they would be stored in separate table source_message__context, where we would store source message ID and context description with 255 characters long string.
With \yii\i18n\PhpMessageSource, they would be stored in separate file, right next to current message files, in {category}_context.php format, where we would have associative array with source message category as a key, and array with context descriptions, as a value.
I have no experience with \yii\i18n\GettextMessageSource, but I see in their documentation, that they already have an option to provide context descriptions. But I would like to see some suggestions for this solution.
This feature would allow to display all of those context description together with message in interface, to help translator to translate messages and understand context of it.
I feel that
Yii::t()lacks ability to provide context of textual value and when translations start to count in couple hundreds, it starts to be quite hard to understand what was meant with translation.If we look at popular translation systems like "Crowdin" (example), they allow to provide message context to support translators.
Currently, only way to provide some helpful information using
Yii::t()is to write something in "key" area, that in turn defies purpose of "source language", for example, if you write a message "Propose (button in issue tasklist table header)" until I change that translation to "Propose", that message still be visible.I am guessing, that there is performance issue with long keys, and length limitations does not allow long context descriptions.
For backwards compatability, I would like to suggest 5th optional attribute to
Yii::t($category, $message, $params = [], $language = null, $context = null)(but this is not very convenient) that would allow to provide some sort of context description.Maybe, we could convert
Yii::t()to allow passing in first attribute array of attributes, likeYii::t(['category' => 'message.category', 'message' => 'message text', 'params' => [], 'language' => null, 'context' => null])or even allow shorthand forcategoryandmessagewith numeric keysYii::t(['message.category', 'message text', 'params' => [], 'language' => null, 'context' => null]).With
\yii\i18n\DbMessageSource, they would be stored in separate tablesource_message__context, where we would store source message ID and context description with 255 characters long string.With
\yii\i18n\PhpMessageSource, they would be stored in separate file, right next to current message files, in{category}_context.phpformat, where we would have associative array with source message category as a key, and array with context descriptions, as a value.I have no experience with
\yii\i18n\GettextMessageSource, but I see in their documentation, that they already have an option to provide context descriptions. But I would like to see some suggestions for this solution.This feature would allow to display all of those context description together with message in interface, to help translator to translate messages and understand context of it.