Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message context for Yii::t() #5

Open
Deele opened this issue Aug 17, 2016 · 73 comments
Open

Message context for Yii::t() #5

Deele opened this issue Aug 17, 2016 · 73 comments
Assignees
Labels
type:enhancement Enhancement

Comments

@Deele
Copy link

Deele commented Aug 17, 2016

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.

@samdark
Copy link
Member

samdark commented Aug 17, 2016

Getext context is what we know as a category, not an example of usage: https://www.gnu.org/software/gettext/manual/html_node/Contexts.html

@klimov-paul
Copy link
Member

I am against such feature.
Placing some descriptive information around any call of Yii::t() sounds like overkill to me.

Besides how we can control same pair of 'category' and 'message' will have same 'context' at all its invocations? For example:

Yii::t('app', 'Some message', [], 'en', 'Some context');
// ...
Yii::t('app', 'Some message', [], 'en', 'Another context!!!');

Each translation message has unique key, which is a combination of category and message.
If you wish to add some description to them you can use this pair and your own custom wrapper.

@samdark
Copy link
Member

samdark commented Sep 6, 2016

Agree.

@samdark samdark closed this as completed Sep 6, 2016
@Deele
Copy link
Author

Deele commented Sep 9, 2016

@klimov-paul I don't see arguments about such approach being overkill. I already explained how to control/store them. Each message can have multiple contexts as in your example. Nothing changes regarding identifiers.

@samdark
Copy link
Member

samdark commented Sep 9, 2016

@Deele

  1. Not all formats we support allowing for such feature. GetText does not.
  2. There's category to differentiate contexts.
  3. You have to preview your translation somehow anyway. It's not possible to translate 100% perfectly w/o checking actual UI usage because of many factors: context which could not be effectively described in text, UI specifics etc.

@Renkas
Copy link

Renkas commented Sep 9, 2016

  1. GetText supports comments: https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
  2. it's not very descriptive. A freetext comment can be usefull sometimes.
  3. Of course - but translators don't have that possibility usually (at the time of translation).

@cebe cebe reopened this Sep 9, 2016
@samdark
Copy link
Member

samdark commented Sep 9, 2016

OK. If comments are supported in GetText we may introduce it.

@samdark
Copy link
Member

samdark commented Sep 9, 2016

Still, I don't think these descriptions are good to be placed right in the code.

@klimov-paul
Copy link
Member

I don't see arguments about such approach being overkill.

For me internal program code should not contain such information since it does not influence the program logic. You propose to make source code, which will be executed on each(!) program run much heaiver to support translation functionality, which is performed relatively rare.

Yii::t() function serves the functioality purpose, while yii message command is a service. I do not like the idea to mix up functionality with the service.

Each message can have multiple contexts as in your example

And how it should look like in the end? How it should be stored? What it should mean for the interpreter who will work with translations?

One more thing. What you are planning to do in case your interface for the translations management should also provide i18n feature? This will mean that your 'context' should be translated as well. Otherwise it make not much sense then a plain message ID.

@samdark samdark closed this as completed Sep 9, 2016
@klimov-paul
Copy link
Member

GetText supports comments:

GetText instroduce sperated file per each language. So you mean 'context' may vary per each language in your case?
As far I can see 'context' is something universal through all language translations. Saving context inside GetText will just cause a lot of data duplication.

@Renkas
Copy link

Renkas commented Sep 9, 2016

Don't confuse comments with context/category.

@SilverFire
Copy link
Member

SilverFire commented Sep 9, 2016

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 read this and can't find points why the aforementioned is worth than creating a separate dictionary for a specific context. I see the following cons:

  • New entity
  • More code to support
  • More complexity to Yii::t API (passing 4-th argument after two optional)
  • More complexity to messages resolving
  • Need to re-write yii message, as @klimov-paul said in his last message

Therefore I'm standing against this feature request.

@Renkas
Copy link

Renkas commented Sep 9, 2016

xgettext utility works like so:

Comments (starting with ///) placed directly before strings thus marked are made available as hints to translators by helper programs.
https://en.wikipedia.org/wiki/Gettext#Programming

I see the problem having comment in a method call. Couldn't the message parser support some kind of comments markup?

/// Some hint for translators here
echo Yii::t('app', 'Awesome string');

And for inline usage maybe the parser could be smart enough to recognise comment that is inserted immediately after method call?

echo '<b>' . Yii::t('app', 'Awesome string')/* Some hint for translators here */ . '</b>';

Of course the parser should then be able to work when there are two method calls and hints on same line (example for test case ;) ):

echo '<b>' . Yii::t('app', 'Awesome string')/* Some hint for translators here */ . '</b> - <b>' . Yii::t('app', 'Another awesome string')/* Hint for the other string */ . '</b>';

@Renkas
Copy link

Renkas commented Sep 9, 2016

@SilverFire so you dislike the idea because it means someone needs to re-write yii message? Or why did you down vote without any comments? All other points from your earlier post has been addressed in this solution.

Anyway I don't really like the opening and closing of this thread in a short amount of time without waiting for answers to open questions. And down voting from Yii core developer without giving a reason after all the issues have been addressed is a very odd move.

@SilverFire
Copy link
Member

SilverFire commented Sep 9, 2016

Or why did you down vote without any comments

I was disturbed while writing a comment. Then found, that I've confused translators comments and context. 😒 @Renkas sorry

@klimov-paul
Copy link
Member

Anyway I don't really like the opening and closing of this thread in a short amount of time without waiting for answers to open questions. And down voting from Yii core developer without giving a reason after all the issues have been addressed is a very odd move.

We have provided all necessary explanations. We consider this feature is not worth the overcomlication of the code (both yii2 core internal and possible actual project one). We can not accept such changes into the main codebase in near future.

However, you can implement this feature as a separated extension outside the yiisoft scope and use it as you pleased.

@Renkas
Copy link

Renkas commented Sep 9, 2016

@klimov-paul I don't think you read the last posts here ... There's exactly 0 changes to Yii core code. Only thing that needs changing is message extraction and some documentation

@klimov-paul
Copy link
Member

So you consider yii\console\controllers\MessageController is not a part of Yii2???

@Renkas
Copy link

Renkas commented Sep 9, 2016

I haven't said that. If it would not be a part of Yii then there would be no point for this thread would it?

But it's not part of core code as you said - core code would run perfectly fine without it. It's an utility - and quite useful one (at least for me). Support for message hints (should be the proper name for this feature I think?) is currently missing from it. And I don't really see why it could not be a part of the default functionality.

Right now it seems you just try to defend the decision on why the issue is closed and are not even thinking about the new proposal. That's not a very productive way of improving anything (which is what software development is all about I think?).

Anyway I'm not going to debate you on this anymore. If Yii team has made up it's mind then so be it. If I really need it I'll implement it myself - just seems like a thing that would probably be useful for lot's of developers.

@kidol
Copy link

kidol commented Sep 9, 2016

@Renkas Can't you use actual message as descriptive context? What I mean is, set sourceLanguage to some dummy value, then run message command and translate to language.

'Welcome {user} # some context' => "Welcome {user}"`

@Renkas
Copy link

Renkas commented Sep 9, 2016

Of course this is a possible hack and as far as I have seen from forum threads etc some people use it. But it's still kind of a hack.

My projects are all using proper base language as strings as I'm not a fan of this dummy language solution. But that's just my preference ...

@samdark samdark reopened this Sep 9, 2016
@samdark
Copy link
Member

samdark commented Sep 9, 2016

I'd like to discuss it a bit more after some thinking. Adding more functionality to message parser isn't a big problem. The problem is not to complicate default usage which doesn't have this context.

Using comments for the purpose looks a bit like hacking to me and, as @klimov-paul said, it adds load to APC/OpCache requiring more memory to store these.

@Deele, @Renkas do you want these comments to appear strictly in the code or you just want them to be there to be filled later?

@Renkas
Copy link

Renkas commented Sep 9, 2016

Me personally would like the possibility to write some hints/explanations to the translators when needed. In my use case I use parser to generate gettext files that are then synced to external translation service and then synced back to my application (overwriting the parsed .po files).

So what I want is a mechanism for the message parser to get these message hints from my application source code and save it to the generated .po file - which will be synced to the external service and the hints will be available there for translators.

  • These hints are in itself an exception - would only use when really needed - not everywhere.
  • One problem raised before was if the same message has multiple different hints/comments in different places in code.
    • My solution would be to append all of them (dividing them clearly of course).
    • When same string used in multiple places has hint defined only in one place then only that would be used - and there would be no problem
  • Load on APC/OpCache part seems not to be a real problem. In PHP source you have way more comments anyway. If you mean caching .po files then yes there would be some extra lines - but I think that's quite marginal.

Of course there are other message sources to think about. In PHP message source I think they could be used as PHP comments as well? And in DB message source maybe add a extra column?

@Deele
Copy link
Author

Deele commented Sep 10, 2016

The message and category are key fields with limited length and other limitations. I don't want to disturb this behavior, that is why putting more information in category or the message does not really work. I want separate field, that is not keyed and indexed and could be provided within code.

I agree to @klimov-paul that there is a problem of overhead because of descriptions that are parsed in every code execution. That could be handled with use of comments as @Renkas proposed, but that could become ugly for multiple inline Yii::t() calls and even more ugly for parser to recognize.

If it is not possible to provide context description within code itself, then this feature should be handled separately altogether without changes to Yii::t() with separate table/model/solution (using message/category as the key) and this specific discussion is over.

Another idea is to gather and make available other kind of message context information - where exactly in code that specific Yii::t() is called, so that in interface, it would look like list of file names, class names, method names, line numbers and other information (to be able to create a URL to create clickable reference to repository, if application has one), that could be used by technically advanced translators, to use source code as a guide. This is not really user friendly approach, but could be much easier to implement and would not require any changes to Yii::t() syntax.

@samdark
Copy link
Member

samdark commented Sep 10, 2016

I'm against expanding method signature but comments approach looks at least acceptable:

  1. It won't affect code execution much if not used everywhere extensively (number of comments affects how much is saved into memory from APC/OpCache).
  2. It will be backwards compatible.
  3. It would require to change only messages table and the message console command.

Sounds like a plan to me.

@Renkas, @Deele, is that what you want?

@PowerGamer1
Copy link

PowerGamer1 commented May 5, 2017

Here is an idea how to solve the problem of passing a hint for translator on how to translate the message.

Yii::t('app', 'Some message text'); // message without hint
Yii::t('app', '[[When translating this message take into account the following ...]]Another message text');  // message with hint

In the example above the [[ and ]] are some user CONFIGURABLE delimiters that mark the beginning and end of the hint for translator. For simplicity, the hint for translator must always appear at the beginning of the message and cannot contain the delimiters inside itself. Of course, the message may contain no hints.

Yii2 engine code impact:

  • No changes to message extraction machinery or the prototype of Yii::t().
  • The Yii:t() needs to be modified to check if the message starts with a hint and if so remove it completely before further processing the message (the way it processes it now).
  • Add the ability for the user to somewhere configure the delimiters for the hint to be used in the message.

Anyone sees any drawbacks in this approach other than (slight?) performance impact?

@samdark
Copy link
Member

samdark commented May 5, 2017

You're mixing message itself with a hint in a single string. Usually that's not a good thing to do and in this case, while better than previous options, it isn't as well...

@Deele
Copy link
Author

Deele commented May 8, 2017

@lynicidn The context is required because you can have message that is related to the same page, form or block, but still, it requires a bit explanation so that translator can understand better the gist of it. For example, when message string contains variables and translator needs to know what sort of thing is meant to go there.

@PowerGamer1 Message string is used as a key to identify message, making it longer just gives bigger overhead for translation lookup procedure.

@samdark To wrap it up from my point of view, this is what script procedure should look like in order of precedence (correct me if I'm wrong):

1. Multi-line comment right after Yii::t(), but before concatenation dot or semicolon

function foo() {
    $variable = 'Lorem ipsum ' .
        Yii::t('dymmy.category', 'Message yiisoft/i18n#1') /* Hint for "dymmy.category:Message yiisoft/i18n#1" */ .
        'dolor sit amet, ' .
        'consectetur ' .
        'adipiscing elit.';
}

Resulting hint:

Hint for "dymmy.category:Message yiisoft/i18n#1"

Multi-line hint (ignoring leading * (leading white-space, star, white-space) prefix like in PHPDocumentator):

function foo() {
    $variable = 'Lorem ipsum ' .
        Yii::t('dymmy.category', 'Message yiisoft/i18n#1') /*
        Hint for "dymmy.category:Message yiisoft/i18n#1".
        Second line of hint for "dymmy.category:Message yiisoft/i18n#1".
        */ .
        'dolor sit amet, ' .
        'consectetur ' .
        'adipiscing elit.';
    $variable = 'Lorem ipsum ' .
        Yii::t('dymmy.category', 'Message yiisoft/i18n#2') /*
         * Hint for "dymmy.category:Message yiisoft/i18n#2".
         * Second line of hint for "dymmy.category:Message yiisoft/i18n#2".
         */ .
        'dolor sit amet, ' .
        'consectetur ' .
        'adipiscing elit.';
}

Resulting hint for dymmy.category:Message yiisoft/i18n#1:

Hint for "dymmy.category:Message yiisoft/i18n#1"\nSecond line of hint for "dymmy.category:Message yiisoft/i18n#1".

Resulting hint for dymmy.category:Message yiisoft/i18n#2:

Hint for "dymmy.category:Message yiisoft/i18n#2"\nSecond line of hint for "dymmy.category:Message yiisoft/i18n#2".

Multi-line hint in HTML/PHP template:

<div class="row">
    <div class="col-md-6">
        <h2><?= Yii::t('dymmy.category', 'Message yiisoft/i18n#1') /* Hint for "dymmy.category:Message yiisoft/i18n#1" */ ?></h2>
        <p class="text-info"><?= Yii::t('dymmy.category', 'Message yiisoft/i18n#2') /*
    Hint for "dymmy.category:Message yiisoft/i18n#2"
    Second line of hint for "dymmy.category:Message yiisoft/i18n#1".
*/ ?></p>
    </div>
</div>

Resulting hint for dymmy.category:Message yiisoft/i18n#1:

Hint for "dymmy.category:Message yiisoft/i18n#1"

Resulting hint for dymmy.category:Message yiisoft/i18n#2:

Hint for "dymmy.category:Message yiisoft/i18n#2"\nSecond line of hint for "dymmy.category:Message yiisoft/i18n#2".

2. Single-line comment right after Yii::t() and line ending semicolon

function foo() {
    $variable = Yii::t('dymmy.category', 'Message yiisoft/i18n#1'); // Hint for "dymmy.category:Message yiisoft/i18n#1"
}

Resulting hint:

Hint for "dymmy.category:Message yiisoft/i18n#1"

3. Multi-line comment right after Yii::t() and line ending semicolon

function foo() {
    $variable = Yii::t('dymmy.category', 'Message yiisoft/i18n#1'); /* Hint for "dymmy.category:Message yiisoft/i18n#1" */
}

Resulting hint:

Hint for "dymmy.category:Message yiisoft/i18n#1"

Multi-line hint (ignoring leading * (leading white-space, star, white-space) prefix like in PHPDocumentator):

function foo() {
    $variable = Yii::t('dymmy.category', 'Message yiisoft/i18n#1'); /*
    Hint for "dymmy.category:Message yiisoft/i18n#1".
    Second line of hint for "dymmy.category:Message yiisoft/i18n#1".
    */
    $variable2 = Yii::t('dymmy.category', 'Message yiisoft/i18n#2'); /*
     * Hint for "dymmy.category:Message yiisoft/i18n#2".
     * Second line of hint for "dymmy.category:Message yiisoft/i18n#2".
     */
}

Resulting hint for dymmy.category:Message yiisoft/i18n#1:

Hint for "dymmy.category:Message yiisoft/i18n#1"\nSecond line of hint for "dymmy.category:Message yiisoft/i18n#1".

Resulting hint for dymmy.category:Message yiisoft/i18n#2:

Hint for "dymmy.category:Message yiisoft/i18n#2"\nSecond line of hint for "dymmy.category:Message yiisoft/i18n#2".

4. Single-line comment right after Yii::t() and concatenation dot

function foo() {
    $variable = 'Lorem ipsum ' .
        Yii::t('dymmy.category', 'Message yiisoft/i18n#1') . // Hint for "dymmy.category:Message yiisoft/i18n#1"
        'dolor sit amet, ' .
        'consectetur ' .
        'adipiscing elit.';
}

Resulting hint:

Hint for "dymmy.category:Message yiisoft/i18n#1"

5. Single-line comment in previous line, where Yii::t() was used

function foo() {
    // Some other comment
    // Another comment that is ignored
    // Hint for "dymmy.category:Message yiisoft/i18n#1"
    $variable = Yii::t('dymmy.category', 'Message yiisoft/i18n#1');
}

Resulting hint:

Hint for "dymmy.category:Message yiisoft/i18n#1"

Same hint for all messages that are used in same line

function foo() {
    // Some other comment
    // Another comment that is ignored
    // Hint for "dymmy.category:Message yiisoft/i18n#1" and "dymmy.category:Message yiisoft/i18n#2"
    $variable = 'Lorem ipsum ' . Yii::t('dymmy.category', 'Message yiisoft/i18n#1') . 'dolor sit amet, ' . Yii::t('dymmy.category', 'Message yiisoft/i18n#2') . 'consectetur adipiscing elit.';
}

Resulting hint for dymmy.category:Message yiisoft/i18n#1:

Hint for "dymmy.category:Message yiisoft/i18n#1" and "dymmy.category:Message yiisoft/i18n#2"

Resulting hint for dymmy.category:Message yiisoft/i18n#2:

Hint for "dymmy.category:Message yiisoft/i18n#1" and "dymmy.category:Message yiisoft/i18n#2"

6. Multi-line comment in previous line, where Yii::t() was used

function foo() {
    // Some other comment
    // Another comment that is ignored
    /* Hint for "dymmy.category:Message yiisoft/i18n#1" */
    $variable = Yii::t('dymmy.category', 'Message yiisoft/i18n#1');
}

Resulting hint:

Hint for "dymmy.category:Message yiisoft/i18n#1"

Multi-line hint (ignoring leading * (leading white-space, star, white-space) prefix like in PHPDocumentator):

function foo() {
    /* Ignored comment */
    /*
    Hint for "dymmy.category:Message yiisoft/i18n#1".
    Second line of hint for "dymmy.category:Message yiisoft/i18n#1".
    */
    $variable = Yii::t('dymmy.category', 'Message yiisoft/i18n#1');
    // Ignored comment
    /*
     * Hint for "dymmy.category:Message yiisoft/i18n#2".
     * Second line of hint for "dymmy.category:Message yiisoft/i18n#2".
     */
    $variable = Yii::t('dymmy.category', 'Message yiisoft/i18n#2');
}

Resulting hint for dymmy.category:Message yiisoft/i18n#1:

Hint for "dymmy.category:Message yiisoft/i18n#1"\nSecond line of hint for "dymmy.category:Message yiisoft/i18n#1".

Resulting hint for dymmy.category:Message yiisoft/i18n#2:

Hint for "dymmy.category:Message yiisoft/i18n#2"\nSecond line of hint for "dymmy.category:Message yiisoft/i18n#2".

@samdark
Copy link
Member

samdark commented May 8, 2017

How about nested Yii::t() calls?

@Renkas
Copy link

Renkas commented May 8, 2017

How or why would you nest Yii::t() calls? As far as I understand that's a thing you should never do.

@klimov-paul
Copy link
Member

See #8286

@Renkas
Copy link

Renkas commented May 8, 2017

Well message parser handles it - couldn't it handle comments as well?

But in a bigger picture I think it's kind of a edge case that is very easy to write in some other way if you need to add context hints.

@bizley
Copy link
Member

bizley commented May 8, 2017

This long example is a great way of showing how overcomplicated comment hints can become. I would drop this idea in favour of category context mentioned earlier. Or we could always extend signature a bit so category can be optional array with first element being category name itself and second one being a context hint - this way is much easier to track.

@Renkas
Copy link

Renkas commented May 8, 2017

I would drop multi-line comment support and everything would be much easier. There's no need to go the route to support every possible comment markup and position. It would be nice but it's not necessary.

These hint's are optional and good practice would be to use them only where needed.

@Deele
Copy link
Author

Deele commented May 8, 2017

@samdark I disagree for nested calls.

@bizley No, I do not agree that categories are enough for that. They are just like folders and give simple hierarchy while not exactly explaining what variables do or how this text is used.

I think for starters, the 1. Multi-line comment right after Yii::t(), but before concatenation dot or semicolon (ignoring multiple white-space and line endings) would be enough and easiest of all to implement. Others can be added in future, when hints will be already implemented and evaluated by users of framework as a feature.

@samdark
Copy link
Member

samdark commented May 8, 2017

@Deele nested calls are reality. They're used often:

echo Yii::t('app', 'here is {something}', [
    'something' => Yii::t('app', 'another string'),
]);

@Deele
Copy link
Author

Deele commented May 8, 2017

@samdark Oh, sorry, I imagined another thing with "nested calls" - yeah, nested calls are reality and used. But the most important thing here is that they do not help to explain, to give hints about context, they just make work of translators even worse - any kind of chopping up messages and creating more of them, or increasing number of variables in messages increase work.

@bizley
Copy link
Member

bizley commented May 9, 2017

@Deele What about array parameter for category?

@Deele
Copy link
Author

Deele commented May 9, 2017

@bizley What exactly did you mean by "array parameter", show us example. The only alternative to comments I see - fifth argument for the Yii::t() function, that will require providing optional third and fourth argument.

The problem is that translator never sees the code where that specific Yii::t() is used, so the intention is to allow describing message with both category and description, so that they could be interpreted and translated independently from application developers or code.

@bizley
Copy link
Member

bizley commented May 9, 2017

@Deele like I said in my comment. Something like:

Yii::t(['app', 'Hint for this'], 'Original text');

@Deele
Copy link
Author

Deele commented May 11, 2017

@bizley We should avoid changing syntax of existing Yii::t(). I guess, Yii::t() is most used function in any multi-lingual Yii based app, we should avoid adding any more code to it.

@bizley
Copy link
Member

bizley commented May 12, 2017

I think we have listed here all the caveats. Let's wait now for implementation proposal.

@samdark samdark self-assigned this Feb 3, 2018
@samdark samdark transferred this issue from yiisoft/yii2 Nov 3, 2018
@FilipBenco
Copy link

Hi, I drafted implementation of this feature in Yii2 yiisoft/yii2#17137 . Afterwards, I'll port it also to Yii3, but right know I need to use id in Yii2 framework. Thx.

@samdark
Copy link
Member

samdark commented Feb 17, 2019

@FilipBenco than you! Unfortunately, 2.0 doesn't accept enhancements since last year with little exceptions.

@FilipBenco
Copy link

FilipBenco commented Feb 17, 2019

That's a pity. @samdark and if I port this feature also to Yii3? I really would like to have this feature and to be integrated directly into Yii2. This way both version will have this.
Is there any way, I can have this feature even in Yii2? (Besides having to maintain custom Console command)

@machour
Copy link
Member

machour commented Feb 18, 2019

Hi @FilipBenco,

Although we understand your pain here, Yii 2 is officially in feature-freeze mode and we cannot bend that rule now, or else we'll open the door for more requests like that.

You can probably make a separate package for yii2 and share it with other developers. I'll adopt it in my Yii2 projects where I have faced this context problem.

I'm also really interested in seeing this land in Yii 3, don't hesitate to ping me on slack if you need help porting it.

@samdark samdark transferred this issue from yiisoft/yii-core Apr 18, 2019
@samdark
Copy link
Member

samdark commented Sep 17, 2019

yiisoft/yii2#17137

@samdark samdark transferred this issue from yiisoft/i18n Feb 6, 2020
@samdark samdark added the type:enhancement Enhancement label Dec 24, 2020
@samdark
Copy link
Member

samdark commented Dec 24, 2020

In order to add this feature later we need to ensure that extra context could be passed to the message of MessageWriterInterface:

interface MessageWriterInterface
{
    public function write(string $category, string $locale, array $messages): void;
}

That won't affect the interface itself but will affect format of $messages. Likely it needs to be changed to

'key' => ['translation' => 'string', ...]

@samdark
Copy link
Member

samdark commented Dec 24, 2020

Interface part in this package and PHP / DB writers are done.

@samdark
Copy link
Member

samdark commented Dec 24, 2020

The rest should be implemented in the message parsing tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Enhancement
Projects
None yet
Development

No branches or pull requests