Skip to content

Commit

Permalink
Rename language to locale
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Apr 16, 2024
1 parent fdc5f7e commit ed828a8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,10 @@ Options:
- `-v` - display absolute times
- `--timezone` (or `-tz`) - display times in specified timezone instead of one used by application
- e.g. `--tz=UTC`
- `--explain[=<language>]` - explain whole expression, including [seconds](#seconds) and [timezones](#timezones)
- `--explain[=<locale>]` - explain whole expression, including [seconds](#seconds) and [timezones](#timezones)
- [Explain command](#explain-command) with `--id` parameter can be used to explain specific job
- e.g. `--explain`
- e.g. `--explain=en` (to choose language)
- e.g. `--explain=en` (to choose locale)

### Worker command

Expand Down Expand Up @@ -767,7 +767,7 @@ Explain cron expression syntax
bin/console scheduler:explain
bin/console scheduler:explain --id="job id"
bin/console scheduler:explain --expression="0 22 * 12 *"
bin/console scheduler:explain --expression="* 8 * * *" --seconds=10 --timezone="Europe/Prague" --language=en
bin/console scheduler:explain --expression="* 8 * * *" --seconds=10 --timezone="Europe/Prague" --locale=en
bin/console scheduler:explain -e"* 8 * * *" -s10 -tz"Europe/Prague" -len
```

Expand All @@ -778,7 +778,7 @@ Options:
- `--expression=<expression>` (or `-e`) - explain expression
- `--seconds=<seconds>` (or `-s`) - repeat every n seconds
- `--timezone=<timezone>` (or `-tz`) - the timezone time should be displayed in
- `--language=<language>` (or `-l`) - explain in specified language
- `--locale=<locale>` (or `-l`) - explain in specified locale

## Lazy loading

Expand Down
8 changes: 4 additions & 4 deletions src/Command/BaseExplainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function __construct(?CronExpressionExplainer $explainer, ?ClockInterface
parent::__construct();
}

protected function getSupportedLanguages(): string
protected function getSupportedLocales(): string
{
$string = '';
$languages = $this->explainer->getSupportedLanguages();
$last = array_key_last($languages);
foreach ($languages as $code => $name) {
$locales = $this->explainer->getSupportedLocales();
$last = array_key_last($locales);
foreach ($locales as $code => $name) {

Check warning on line 36 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ $string = ''; $locales = $this->explainer->getSupportedLocales(); $last = array_key_last($locales); - foreach ($locales as $code => $name) { + foreach (array() as $code => $name) { $string .= "{$code} ({$name})"; if ($code !== $last) { $string .= ', ';

Check warning on line 36 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ $string = ''; $locales = $this->explainer->getSupportedLocales(); $last = array_key_last($locales); - foreach ($locales as $code => $name) { + foreach (array() as $code => $name) { $string .= "{$code} ({$name})"; if ($code !== $last) { $string .= ', ';
$string .= "$code ($name)";

Check warning on line 37 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "Assignment": --- Original +++ New @@ @@ $locales = $this->explainer->getSupportedLocales(); $last = array_key_last($locales); foreach ($locales as $code => $name) { - $string .= "{$code} ({$name})"; + $string = "{$code} ({$name})"; if ($code !== $last) { $string .= ', '; }

Check warning on line 37 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "Assignment": --- Original +++ New @@ @@ $locales = $this->explainer->getSupportedLocales(); $last = array_key_last($locales); foreach ($locales as $code => $name) { - $string .= "{$code} ({$name})"; + $string = "{$code} ({$name})"; if ($code !== $last) { $string .= ', '; }
if ($code !== $last) {

Check warning on line 38 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "NotIdentical": --- Original +++ New @@ @@ $last = array_key_last($locales); foreach ($locales as $code => $name) { $string .= "{$code} ({$name})"; - if ($code !== $last) { + if ($code === $last) { $string .= ', '; } }

Check warning on line 38 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "NotIdentical": --- Original +++ New @@ @@ $last = array_key_last($locales); foreach ($locales as $code => $name) { $string .= "{$code} ({$name})"; - if ($code !== $last) { + if ($code === $last) { $string .= ', '; } }
$string .= ', ';

Check warning on line 39 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "Assignment": --- Original +++ New @@ @@ foreach ($locales as $code => $name) { $string .= "{$code} ({$name})"; if ($code !== $last) { - $string .= ', '; + $string = ', '; } } return $string;

Check warning on line 39 in src/Command/BaseExplainCommand.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.1)

Escaped Mutant for Mutator "Assignment": --- Original +++ New @@ @@ foreach ($locales as $code => $name) { $string .= "{$code} ({$name})"; if ($code !== $last) { - $string .= ', '; + $string = ', '; } } return $string;
Expand Down
30 changes: 15 additions & 15 deletions src/Command/ExplainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ protected function configure(): void
$this->addOption('seconds', 's', InputOption::VALUE_REQUIRED, 'Repeat every n seconds');
$this->addOption('timezone', 'tz', InputOption::VALUE_REQUIRED, 'The timezone time should be displayed in');
$this->addOption(
'language',
'locale',
'l',
InputOption::VALUE_REQUIRED,
"Translate expression in given language - {$this->getSupportedLanguages()}",
"Translate expression in given locale - {$this->getSupportedLocales()}",
);
}

Expand All @@ -69,21 +69,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$expression = $options['expression'];
$seconds = $options['seconds'];
$timezone = $options['timezone'];
$language = $options['language'];
$locale = $options['locale'];

if ($id !== null) {
return $this->explainJobWithId($id, $output);
}

if ($expression !== null) {
return $this->explainExpression($expression, $seconds, $timezone, $language, $output);
return $this->explainExpression($expression, $seconds, $timezone, $locale, $output);
}

return $this->explainSyntax($output);
}

/**
* @return array{id: string|null, expression: string|null, seconds: int<0, 59>|null, timezone: DateTimeZone|null, language: string|null}|null
* @return array{id: string|null, expression: string|null, seconds: int<0, 59>|null, timezone: DateTimeZone|null, locale: string|null}|null
*/
private function validateOptions(InputInterface $input, OutputInterface $output): ?array
{
Expand Down Expand Up @@ -135,20 +135,20 @@ private function validateOptions(InputInterface $input, OutputInterface $output)
}
}

$language = $input->getOption('language');
assert($language === null || is_string($language));
if ($language !== null) {
if (!array_key_exists($language, $this->explainer->getSupportedLanguages())) {
$locale = $input->getOption('locale');
assert($locale === null || is_string($locale));
if ($locale !== null) {
if (!array_key_exists($locale, $this->explainer->getSupportedLocales())) {
$hasErrors = true;
$output->writeln(
"<error>Option --language expects no value or one of supported languages, '$language' given."
. ' Use --help to list available languages.</error>',
"<error>Option --locale expects no value or one of supported locales, '$locale' given."
. ' Use --help to list available locales.</error>',
);
}

if ($expression === null) {
$hasErrors = true;
$output->writeln('<error>Option --language must be used with --expression.</error>');
$output->writeln('<error>Option --locale must be used with --expression.</error>');
}
}

Expand All @@ -165,7 +165,7 @@ private function validateOptions(InputInterface $input, OutputInterface $output)
'expression' => $expression,
'seconds' => $seconds,
'timezone' => $timezone,
'language' => $language,
'locale' => $locale,
];
}

Expand All @@ -176,7 +176,7 @@ private function explainExpression(
string $expression,
?int $seconds,
?DateTimeZone $timeZone,
?string $language,
?string $locale,
OutputInterface $output
): int
{
Expand All @@ -185,7 +185,7 @@ private function explainExpression(
$expression,
$seconds,
$timeZone,
$language,
$locale,
));
} catch (UnsupportedExpression $exception) {
$output->writeln("<error>{$exception->getMessage()}</error>");
Expand Down
8 changes: 4 additions & 4 deletions src/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function configure(): void
'explain',
null,
InputOption::VALUE_OPTIONAL,
"Explain expression - {$this->getSupportedLanguages()}",
"Explain expression - {$this->getSupportedLocales()}",
false,
);
}
Expand Down Expand Up @@ -212,12 +212,12 @@ private function validateOptions(InputInterface $input, OutputInterface $output)
assert($explain === null || $explain === false || is_string($explain));
if (
is_string($explain)
&& !array_key_exists($explain, $this->explainer->getSupportedLanguages())
&& !array_key_exists($explain, $this->explainer->getSupportedLocales())
) {
$hasErrors = true;
$output->writeln(
"<error>Option --explain expects no value or one of supported languages, '$explain' given."
. ' Use --help to list available languages.</error>',
"<error>Option --explain expects no value or one of supported locales, '$explain' given."
. ' Use --help to list available locales.</error>',
);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/Unit/Command/ExplainCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function provideExplainExpression(): Generator
yield [
[
'--expression' => '* * * * *',
'--language' => 'en',
'--locale' => 'en',
],
<<<'MSG'
At every minute.
Expand Down Expand Up @@ -366,20 +366,20 @@ public function provideInputError(): Generator
yield [
[
'--expression' => '* * * *',
'--language' => 'noop',
'--locale' => 'noop',
],
<<<'MSG'
Option --language expects no value or one of supported languages, 'noop' given. Use --help to list available languages.
Option --locale expects no value or one of supported locales, 'noop' given. Use --help to list available locales.

MSG,
];

yield [
[
'--language' => 'en',
'--locale' => 'en',
],
<<<'MSG'
Option --language must be used with --expression.
Option --locale must be used with --expression.

MSG,
];
Expand All @@ -389,15 +389,15 @@ public function provideInputError(): Generator
'--id' => 'id',
'--seconds' => 'bad seconds',
'--timezone' => 'bad timezone',
'--language' => 'noop',
'--locale' => 'noop',
],
<<<'MSG'
Option --seconds expects an int<0, 59>, 'bad seconds' given.
Option --seconds must be used with --expression.
Option --timezone expects a valid timezone, 'bad timezone' given.
Option --timezone must be used with --expression.
Option --language expects no value or one of supported languages, 'noop' given. Use --help to list available languages.
Option --language must be used with --expression.
Option --locale expects no value or one of supported locales, 'noop' given. Use --help to list available locales.
Option --locale must be used with --expression.

MSG,
];
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Command/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function provideInputError(): Generator
'--explain' => 'noop',
],
<<<'MSG'
Option --explain expects no value or one of supported languages, 'noop' given. Use --help to list available languages.
Option --explain expects no value or one of supported locales, 'noop' given. Use --help to list available locales.

MSG,
];
Expand All @@ -336,7 +336,7 @@ public function provideInputError(): Generator
<<<'MSG'
Option --next expects an int<1, max>, '0' given.
Option --timezone expects a valid timezone, 'bad-timezone' given.
Option --explain expects no value or one of supported languages, 'noop' given. Use --help to list available languages.
Option --explain expects no value or one of supported locales, 'noop' given. Use --help to list available locales.

MSG,
];
Expand Down

0 comments on commit ed828a8

Please sign in to comment.