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);
}

Comments
Comment #2
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 commentedComment #6
balagan commentedComment #7
balagan commentedComment #10
balagan commentedComment #11
balagan commentedComment #13
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 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 commentedSome screenshots to help with the review:
Comment #16
maxocub commentedComment #17
balagan 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.phpit 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
alexpottTranslateis 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\FieldUiLocalTaskfor how this is done.Comment #21
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 commentedComment #31
gábor hojtsyYay, thanks!
Comment #33
maxocub commented