-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Philippe Damen
committed
Jan 30, 2024
1 parent
eed1f3a
commit ebaa4c9
Showing
7 changed files
with
335 additions
and
90 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace NextApps\PoeditorSync\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use NextApps\PoeditorSync\Translations\TranslationManager; | ||
|
||
class CleanupCommand extends Command | ||
{ | ||
protected $signature = 'poeditor:cleanup'; | ||
|
||
protected $description = 'Cleanup unused translations and run update command if translations don\'t exist anymore.'; | ||
|
||
public function handle() : mixed | ||
{ | ||
// remove empty string translations | ||
app(TranslationManager::class)->removeEmptyTranslations(); | ||
|
||
// run poeditor:update command if translations don't exist anymore + ask confirmation | ||
if(app(TranslationManager::class)->translationsDontExistAnymore() | ||
&& $this->confirm('Some translations don\'t exist anymore. Do you want to run poeditor:update command?') | ||
) { | ||
$this->call('poeditor:update'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace NextApps\PoeditorSync\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use NextApps\PoeditorSync\Translations\TranslationManager; | ||
|
||
class ValidateTranslationsCommand extends Command | ||
{ | ||
protected $signature = 'poeditor:validate'; | ||
|
||
protected $description = 'Validate that translations have the same parameters and pluralization'; | ||
|
||
public function handle() : int | ||
{ | ||
$stringVariables = collect(config('app.supported_locales'))->map( | ||
fn ($language) => [ | ||
$language, | ||
app(TranslationManager::class)->countStringVariables($language) | ||
] | ||
); | ||
|
||
$this->info('The following amount of string variables were found per language:'); | ||
$this->table( | ||
['Language', 'String variables'], | ||
$stringVariables->toArray() | ||
); | ||
|
||
if($stringVariables->max(fn ($item) => $item[1]) !== $stringVariables->min(fn ($item) => $item[1])) { | ||
$this->info('It seems there are some string variables that are not available in other languages.'); | ||
|
||
$extraStringVariables = app(TranslationManager::class)->getExtraStringVariables(); | ||
|
||
if($extraStringVariables->isNotEmpty()) { | ||
$this->info('There might be something wrong with the string variables for the following translation keys:'); | ||
$this->table( | ||
['Extra string variables'], | ||
$extraStringVariables->map(fn ($item) => [$item])->toArray() | ||
); | ||
} | ||
} | ||
|
||
$invalidTranslations = app(TranslationManager::class)->getPossibleInvalidTranslations(); | ||
|
||
if($invalidTranslations->isNotEmpty()) { | ||
$this->info('It seems there are some translations that could be invalid in some languages.'); | ||
$this->table( | ||
['Language', 'Translation key', 'Original', 'Translated', 'Missing'], | ||
$invalidTranslations->map( | ||
fn ($item, $key) => [ | ||
$item['locale'], | ||
$item['key'], | ||
$item['original'], | ||
$item['translated'], | ||
$item['missing']->implode(', ') | ||
] | ||
)->toArray() | ||
); | ||
} | ||
|
||
$pluralizationErrors = app(TranslationManager::class)->checkPluralization(); | ||
|
||
if($pluralizationErrors->isNotEmpty()) { | ||
$this->info('There might be something wrong with the pluralization for the following translation key:'); | ||
$this->table( | ||
['Translation key'], | ||
$pluralizationErrors->map( | ||
fn ($item, $key) => [ | ||
$item, | ||
] | ||
)->toArray() | ||
); | ||
} | ||
|
||
$this->info('All checks have been successfully completed.'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.