Skip to content

Commit

Permalink
Add basic translation tools
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes committed Jun 12, 2024
1 parent 1b6c9c5 commit 4339752
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Features/Traits/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@

namespace Blumilk\BLT\Features\Traits;

use Behat\Gherkin\Node\TableNode;
use Illuminate\Contracts\Translation\Translator;
use PHPUnit\Framework\Assert;

trait Translations
{
use Application;

private string $input;

/**
* @When I ask to translate :input
* @When I ask for translations of :input
*/
public function askToTranslate(string $input): void
{
$this->input = $input;
}

/**
* @Then I should see the following phrases:
*/
public function assertTranslationMatches(?TableNode $table = null): void
{
$translator = $this->getContainer()->get(Translator::class);

foreach ($table as $row) {
$this->getContainer()->setLocale($row["locale"]);
$translation = $translator->get($this->input);

Assert::assertEquals($row["phrase"], $translation);
}
}
}

0 comments on commit 4339752

Please sign in to comment.