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

49-translation-texts-starting-with-new-not-translated #50

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- The command will not hang a few seconds without showing progress anymore ([#46](https://github.com/khalyomede/laravel-translate/issues/46)).
- Texts starting with "New" will now be correctly translated ([#49](https://github.com/khalyomede/laravel-translate/issues/49)).

## [0.1.0] - 2023-03-25

Expand Down
5 changes: 4 additions & 1 deletion src/Commands/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use InvalidArgumentException;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
Expand Down Expand Up @@ -477,7 +479,8 @@ private function filterTranslationKeys(ProgressBar $bar, Collection $translation
return false;
}

if ($expression->expr instanceof ConstFetch) {
// instanceof New -> "New account", "New" is parsed as new class keyword
if ($expression->expr instanceof ConstFetch || $expression->expr instanceof New_) {
$bar->advance();

return true;
Expand Down
31 changes: 28 additions & 3 deletions tests/Feature/Commands/TranslateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function testReturnsZeroCodeIfNoNewKeysHaveBeenFound(): void
"test 2" => "",
"test 3" => "",
"Unable to perform anti-bot validation." => "",
"New journey" => "",
], flags: JSON_PRETTY_PRINT);

assert(is_string($content));
Expand Down Expand Up @@ -598,7 +599,7 @@ public function testDisplaysHowManyNewKeysHaveBeenAddedToFile(): void

$this->artisan(Translate::class)
->assertSuccessful()
->expectsOutputToContain("Added 21 new key(s) on each lang files.");
->expectsOutputToContain("Added 22 new key(s) on each lang files.");
}

public function testDisplayOnlyNewKeysAddedToFileWithoutTakingIntoAccountCurrentExistingKeys(): void
Expand Down Expand Up @@ -626,6 +627,7 @@ public function testDisplayOnlyNewKeysAddedToFileWithoutTakingIntoAccountCurrent
"test" => "",
"test 2" => "",
"test 3" => "",
"New journey" => "",
], flags: JSON_PRETTY_PRINT);

assert(is_string($content));
Expand Down Expand Up @@ -672,7 +674,7 @@ public function testDisplayNumberOfKeysInConditionalIfNewKeysHaveBeenFoundWhenUs

assert($command instanceof PendingCommand);

$command->expectsOutputToContain("21 key(s) would have been added (using --dry-run) on each lang files.");
$command->expectsOutputToContain("22 key(s) would have been added (using --dry-run) on each lang files.");
}

public function testDoesNotAddShortKeys(): void
Expand Down Expand Up @@ -915,7 +917,7 @@ public function testDisplaysProgressBarWhenFetchingTranslationKeys(): void

$this->artisan(Translate::class)
->assertSuccessful()
->expectsOutputToContain("12/12");
->expectsOutputToContain("13/13");
}

public function testDisplaysElapsedTimeAndMaxMemoryConsumption(): void
Expand Down Expand Up @@ -965,4 +967,27 @@ public function testCanAddKeysFromTranslatables(): void
"Yellow" => "",
]);
}

public function testCanTranslateTextStartingWithNew(): void
{
$this->app?->useLangPath(__DIR__ . "/../../misc/resources/lang");

config([
"translate" => [
"langs" => [
"fr",
],
"include" => [
"tests/misc/resources/views/about-us"
],
],
]);

$this->artisan(Translate::class)
->assertSuccessful();

$this->assertFileContainsJson(__DIR__ . "/../../misc/resources/lang/fr.json", [
"New journey" => "",
]);
}
}
1 change: 1 addition & 0 deletions tests/misc/resources/views/about-us/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>@lang('New journey')</h1>
Loading