Skip to content

Commit be819d4

Browse files
committed
patch: manage argrument positioning of sprintf in translation
see https://www.php.net/manual/en/function.sprintf.php#refsect1-function.sprintf-examples
1 parent 9b6f42f commit be819d4

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

src/Input/Parameter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function desc(bool $withDefault = false): string
8484
return $this->desc;
8585
}
8686

87-
return ltrim(t('%s [default: %s]', [$this->desc, json_encode($this->default)]));
87+
return ltrim(t('%1$s [default: %2$s]', [$this->desc, json_encode($this->default)]));
8888
}
8989

9090
/**

src/Input/Parser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ protected function validate(): void
221221
[$name, $label] = [$item->long(), 'Option'];
222222
}
223223

224-
throw new RuntimeException(t('%s "%s" is required', [$label, $name]));
224+
throw new RuntimeException(t('%1$s "%2$s" is required', [$label, $name]));
225225
}
226226
}
227227

src/Output/ProgressBar.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function current(int $current, string $label = '')
169169

170170
if ($current > $this->total) {
171171
throw new UnexpectedValueException(
172-
t('The current (%d) is greater than the total (%d).', [$current, $this->total])
172+
t('The current (%1$d) is greater than the total (%2$d).', [$current, $this->total])
173173
);
174174
}
175175

tests/ApplicationTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,20 @@ public function test_on_exception()
331331
public function test_default_translations()
332332
{
333333
$this->assertSame('Show version', t('Show version'));
334-
$this->assertSame('Verbosity level [default: 0]', t('%s [default: %s]', ['Verbosity level', 0]));
334+
$this->assertSame('Verbosity level [default: 0]', t('%1$s [default: %2$s]', ['Verbosity level', 0]));
335335
$this->assertSame('Command "rmdir" already added', t('Command "%s" already added', ['rmdir']));
336336
}
337337

338338
public function test_custom_translations(): void
339339
{
340340
Application::addLocale('fr', [
341341
'Show version' => 'Afficher la version',
342-
'%s [default: %s]' => '%s [par défaut: %s]',
342+
'%1$s [default: %2$s]' => '%1$s [par défaut: %2$s]',
343343
'Command "%s" already added' => 'La commande "%s" a déjà été ajoutée'
344344
], true);
345345

346346
$this->assertSame('Afficher la version', t('Show version'));
347-
$this->assertSame('Niveau de verbosite [par défaut: 0]', t('%s [default: %s]', ['Niveau de verbosite', 0]));
347+
$this->assertSame('Niveau de verbosite [par défaut: 0]', t('%1$s [default: %2$s]', ['Niveau de verbosite', 0]));
348348
$this->assertSame('La commande "rmdir" a déjà été ajoutée', t('Command "%s" already added', ['rmdir']));
349349

350350
// untranslated key
@@ -357,7 +357,7 @@ public function test_app_translated()
357357
$app->addLocale('fr', [
358358
'Show version' => 'Afficher la version',
359359
'Verbosity level' => 'Niveau de verbocité',
360-
'%s [default: %s]' => '%s [par défaut: %s]',
360+
'%1$s [default: %2$s]' => '%s [par défaut: %s]',
361361
], true);
362362
$app->command('rmdir');
363363

tests/Output/ProgressBarTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function getIterator(): Traversable
7878
$this->assertNotNull((new Terminal)->height());
7979

8080
$this->expectException(UnexpectedValueException::class);
81+
$this->expectExceptionMessage('The current (2) is greater than the total (1).');
8182
(new ProgressBar(1))->current(2);
8283
}
8384
}

0 commit comments

Comments
 (0)