The Local task button "Translate" for content translation is not translated.
In Drupal\content_translation\Plugin\Derivative\ContentTranslationLocalTasks the local task is added with the getDerivativeDefinitions function. But the t() is not used on the title. Is this necessary here?
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// Create tabs for all possible entity types.
foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
// Find the route name for the translation overview.
$translation_route_name = "entity.$entity_type_id.content_translation_overview";
$base_route_name = "entity.$entity_type_id.canonical";
$this->derivatives[$translation_route_name] = array(
'entity_type' => $entity_type_id,
'title' => 'Translate', // Does this has to be t('Translate') ?
'route_name' => $translation_route_name,
'base_route' => $base_route_name,
) + $base_plugin_definition;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
Comment | File | Size | Author |
---|---|---|---|
#21 | interdiff-14-20.txt | 2.77 KB | maxocub |
#21 | 2651986-20.patch | 3.29 KB | maxocub |
#19 | Screen Shot 2016-03-08 at 7.36.25 PM.png | 143.17 KB | Kristen Pol |
#19 | Screen Shot 2016-03-08 at 7.29.18 PM.png | 136.26 KB | Kristen Pol |
#15 | before.png | 4.45 KB | maxocub |
Comments
Comment #2
Tom Robert CreditAttribution: Tom Robert commentedComment #3
tstoecklerYes, that is a bug! Thanks for finding it and also for the patch!
However, using the
t()
function is discouraged in classes.We should add a
use StringTranslationTrait;
to the top of the class and then instead oft()
we can do$this->t()
.Comment #4
tstoecklerComment #5
balagan CreditAttribution: balagan as a volunteer commentedComment #6
balagan CreditAttribution: balagan as a volunteer commentedComment #7
balagan CreditAttribution: balagan as a volunteer commentedComment #10
balagan CreditAttribution: balagan as a volunteer commentedComment #11
balagan CreditAttribution: balagan as a volunteer commentedComment #13
maxocub CreditAttribution: maxocub commentedI ran the test localy and I have the same errors. Here is the error message:
I think we need to add a mock for string_translation in the test setup.
Comment #14
maxocub CreditAttribution: maxocub commentedHere's an updated patch where I add the string_translation stub to the failing test.
I'm not sure if the translation is actually tested with the stub or if it just pass through.
Any input?
Comment #15
maxocub CreditAttribution: maxocub commentedSome screenshots to help with the review:
Comment #16
maxocub CreditAttribution: maxocub commentedComment #17
balagan CreditAttribution: balagan as a volunteer commentedComment #18
Kristen PolNice patch! Thanks.
I see this is used to allow for $this->t() so this is good.
Nitpick: The other examples in the core code (not many) that are setting this are not creating it as separate variable, e.g. in:
core/modules/node/tests/src/Unit/Plugin/views/field/NodeBulkFormTest.php
it uses:
$container->set('string_translation', $this->getStringTranslationStub());
so I would be inclined to change this to one line like:
\Drupal::getContainer()->set('string_translation', $this->getStringTranslationStub());
but this is not a big deal. Since this pattern of using the stub in the container is used in other tests, then I assume this is ok.
Comment #19
Kristen PolI have tested this with simplytest.me and it is working as expected.
Before patch:
After patch:
I'm marking RTBC because my code review only had a minor nitpick that isn't necessary to change. Thanks!
Comment #20
alexpottTranslate
is an existing string so adding yet another place where it is translated is not adding an strings to translate - therefore I think we can fix this in 8.0.x as well.We should inject the string translation service into the deriver. See
\Drupal\field_ui\Plugin\Derivative\FieldUiLocalTask
for how this is done.Comment #21
maxocub CreditAttribution: maxocub commented@Kristen Pol: I corrected the nitpick ;)
@alexpott: Is that what you mean? I'm not sure.
Comment #22
dawehnerYou no longer have to inject it, because $this->t() just creates an object
Comment #23
alexpottOne second - @dawehner and I are going to discuss this.
Comment #24
alexpott@dawehner and I discussed this in IRC.
so tldr; the latest patch is fine and we have work to do on when and when not to inject this.
Comment #25
Kristen PolPer #24, "so tldr; the latest patch is fine and we have work to do on when and when not to inject this." so moving this back to RTBC since that's what I interpret "the latest patch is fine" to mean.
Comment #26
alexpottCommitted 366380d and pushed to 8.0.x, 8.1.x and 8.2.x. Thanks!
Comment #30
maxocub CreditAttribution: maxocub commentedComment #31
Gábor HojtsyYay, thanks!
Comment #33
maxocub CreditAttribution: maxocub as a volunteer and commented