= $this->Text->autoParagraph(h(${{ singularVar }}->{{ field }})); ?>@@ -122,15 +123,15 @@ {%~ set otherSingularVar = alias|singularize|variable %} {%~ set otherPluralHumanName = details.controller|underscore|humanize %}
-
= __('Related {{ otherPluralHumanName }}') ?>
+= {% if useDomain %}__d('{{ plugin }}', {% else %}__({% endif %}'Related {{ otherPluralHumanName }}') ?>
{{ details.property }})) : ?>| = __('{{ field|humanize }}') ?> | += {% if useDomain %}__d('{{ plugin }}', {% else %}__({% endif %}'{{ field|humanize }}') ?> | {%~ endfor %} -= __('Actions') ?> | += {% if useDomain %}__d('{{ plugin }}', {% else %}__({% endif %}'Actions') ?> |
|---|---|---|---|
| - = $this->Html->link(__('View'), ['controller' => '{{ details.controller }}', 'action' => 'view', {{ otherPk|raw }}]) ?> - = $this->Html->link(__('Edit'), ['controller' => '{{ details.controller }}', 'action' => 'edit', {{ otherPk|raw }}]) ?> + = $this->Html->link({% if useDomain %}__d('{{ plugin }}', {% else %}__({% endif %}'View'), ['controller' => '{{ details.controller }}', 'action' => 'view', {{ otherPk|raw }}]) ?> + = $this->Html->link({% if useDomain %}__d('{{ plugin }}', {% else %}__({% endif %}'Edit'), ['controller' => '{{ details.controller }}', 'action' => 'edit', {{ otherPk|raw }}]) ?> = $this->Form->postLink( - __('Delete'), + {% if useDomain %}__d('{{ plugin }}', {% else %}__({% endif %}'Delete'), ['controller' => '{{ details.controller }}', 'action' => 'delete', {{ otherPk|raw }}], [ 'method' => 'delete', - 'confirm' => __('Are you sure you want to delete # {0}?', {{ otherPk|raw }}), + 'confirm' => {% if useDomain %}__d('{{ plugin }}', {% else %}__({% endif %}'Are you sure you want to delete # {0}?', {{ otherPk|raw }}), ] ) ?> | diff --git a/templates/bake/element/Controller/add.twig b/templates/bake/element/Controller/add.twig index 593ae4d4..73c9b83d 100644 --- a/templates/bake/element/Controller/add.twig +++ b/templates/bake/element/Controller/add.twig @@ -28,11 +28,11 @@ if ($this->request->is('post')) { ${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->request->getData()); if ($this->{{ currentModelName }}->save(${{ singularName }})) { - $this->Flash->success(__('The {{ singularHumanName|lower }} has been saved.')); + $this->Flash->success({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'The {{ singularHumanName|lower }} has been saved.')); return $this->redirect(['action' => 'index']); } - $this->Flash->error(__('The {{ singularHumanName|lower }} could not be saved. Please, try again.')); + $this->Flash->error({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'The {{ singularHumanName|lower }} could not be saved. Please, try again.')); } {% set associations = Bake.aliasExtractor(modelObj, 'BelongsTo') %} {% set associations = associations|merge(Bake.aliasExtractor(modelObj, 'BelongsToMany')) %} diff --git a/templates/bake/element/Controller/delete.twig b/templates/bake/element/Controller/delete.twig index bab93c72..70be262f 100644 --- a/templates/bake/element/Controller/delete.twig +++ b/templates/bake/element/Controller/delete.twig @@ -28,9 +28,9 @@ $this->Authorization->authorize(${{ singularName }}); {% endif %} if ($this->{{ currentModelName }}->delete(${{ singularName }})) { - $this->Flash->success(__('The {{ singularHumanName|lower }} has been deleted.')); + $this->Flash->success({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'The {{ singularHumanName|lower }} has been deleted.')); } else { - $this->Flash->error(__('The {{ singularHumanName|lower }} could not be deleted. Please, try again.')); + $this->Flash->error({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'The {{ singularHumanName|lower }} could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']); diff --git a/templates/bake/element/Controller/edit.twig b/templates/bake/element/Controller/edit.twig index 4e0b97d9..564b8033 100644 --- a/templates/bake/element/Controller/edit.twig +++ b/templates/bake/element/Controller/edit.twig @@ -32,11 +32,11 @@ if ($this->request->is(['patch', 'post', 'put'])) { ${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->request->getData()); if ($this->{{ currentModelName }}->save(${{ singularName }})) { - $this->Flash->success(__('The {{ singularHumanName|lower }} has been saved.')); + $this->Flash->success({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'The {{ singularHumanName|lower }} has been saved.')); return $this->redirect(['action' => 'index']); } - $this->Flash->error(__('The {{ singularHumanName|lower }} could not be saved. Please, try again.')); + $this->Flash->error({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'The {{ singularHumanName|lower }} could not be saved. Please, try again.')); } {% for assoc in belongsTo|merge(belongsToMany) %} {%~ set otherName = Bake.getAssociatedTableAlias(modelObj, assoc) %} diff --git a/templates/bake/element/Controller/login.twig b/templates/bake/element/Controller/login.twig index 409f0243..84e11624 100644 --- a/templates/bake/element/Controller/login.twig +++ b/templates/bake/element/Controller/login.twig @@ -27,7 +27,7 @@ $this->request->allowMethod(['get', 'post']); $result = $this->Authentication->getResult(); if ($result->isValid()) { - $this->Flash->success(__('Login successful')); + $this->Flash->success({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'Login successful')); $redirect = $this->Authentication->getLoginRedirect(); if ($redirect) { return $this->redirect($redirect); @@ -36,6 +36,6 @@ // Display error if user submitted and authentication failed if ($this->request->is('post')) { - $this->Flash->error(__('Invalid username or password')); + $this->Flash->error({% if plugin %}__d('{{ plugin }}', {% else %}__({% endif %}'Invalid username or password')); } } diff --git a/tests/TestCase/Command/TemplateCommandTest.php b/tests/TestCase/Command/TemplateCommandTest.php index e730bf0d..15f9c28c 100644 --- a/tests/TestCase/Command/TemplateCommandTest.php +++ b/tests/TestCase/Command/TemplateCommandTest.php @@ -659,6 +659,28 @@ public function testBakeIndexPlugin() $this->assertFileContains('$comment->article->id', $this->generatedFile); } + /** + * test Bake with plugins with __d() translations. + * + * @return void + */ + public function testBakePluginTemplatesWithDomain() + { + $this->_loadTestPlugin('BakeTest'); + $path = Plugin::templatePath('BakeTest'); + + // Setup association to ensure properties don't have dots + $model = $this->getTableLocator()->get('BakeTest.Comments'); + $model->belongsTo('Articles'); + + $this->generatedFile = $path . 'Comments/index.php'; + $this->exec('bake template BakeTest.comments index'); + + $this->assertExitCode(CommandInterface::CODE_SUCCESS); + $this->assertFileExists($this->generatedFile); + $this->assertFileContains('__d(\'BakeTest\', ', $this->generatedFile); + } + /** * Ensure that models in a tree don't include form fields for lft/rght * diff --git a/tests/comparisons/Controller/testBakeWithPlugin.php b/tests/comparisons/Controller/testBakeWithPlugin.php index fb16c6e7..a3f09154 100644 --- a/tests/comparisons/Controller/testBakeWithPlugin.php +++ b/tests/comparisons/Controller/testBakeWithPlugin.php @@ -50,11 +50,11 @@ public function add() if ($this->request->is('post')) { $bakeArticle = $this->BakeArticles->patchEntity($bakeArticle, $this->request->getData()); if ($this->BakeArticles->save($bakeArticle)) { - $this->Flash->success(__('The bake article has been saved.')); + $this->Flash->success(__d('BakeTest', 'The bake article has been saved.')); return $this->redirect(['action' => 'index']); } - $this->Flash->error(__('The bake article could not be saved. Please, try again.')); + $this->Flash->error(__d('BakeTest', 'The bake article could not be saved. Please, try again.')); } $bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all(); $bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all(); @@ -74,11 +74,11 @@ public function edit($id = null) if ($this->request->is(['patch', 'post', 'put'])) { $bakeArticle = $this->BakeArticles->patchEntity($bakeArticle, $this->request->getData()); if ($this->BakeArticles->save($bakeArticle)) { - $this->Flash->success(__('The bake article has been saved.')); + $this->Flash->success(__d('BakeTest', 'The bake article has been saved.')); return $this->redirect(['action' => 'index']); } - $this->Flash->error(__('The bake article could not be saved. Please, try again.')); + $this->Flash->error(__d('BakeTest', 'The bake article could not be saved. Please, try again.')); } $bakeUsers = $this->BakeArticles->BakeUsers->find('list', limit: 200)->all(); $bakeTags = $this->BakeArticles->BakeTags->find('list', limit: 200)->all(); @@ -97,9 +97,9 @@ public function delete($id = null) $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); if ($this->BakeArticles->delete($bakeArticle)) { - $this->Flash->success(__('The bake article has been deleted.')); + $this->Flash->success(__d('BakeTest', 'The bake article has been deleted.')); } else { - $this->Flash->error(__('The bake article could not be deleted. Please, try again.')); + $this->Flash->error(__d('BakeTest', 'The bake article could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']);