diff --git a/src/ReferenceMessageLocalizer.php b/src/ReferenceMessageLocalizer.php index fd6d9cb6d..aa8550d10 100644 --- a/src/ReferenceMessageLocalizer.php +++ b/src/ReferenceMessageLocalizer.php @@ -25,14 +25,13 @@ class ReferenceMessageLocalizer implements MessageLocalizer { } /** - * Transliterate numerals, add thousands separators and localize the decimal point. - * * @param string $number * * @return string */ - public function formatNum( string $number ) : string { - return $this->language->formatNum( $number ); + public function localizeSeparators( string $number ) : string { + // Filter to make sure characters are never removed + return strtr( $number, array_filter( $this->language->separatorTransformTable() ?: [] ) ); } /** diff --git a/src/ReferencesFormatter.php b/src/ReferencesFormatter.php index ac5b2e4ca..320b04343 100644 --- a/src/ReferencesFormatter.php +++ b/src/ReferencesFormatter.php @@ -265,7 +265,7 @@ class ReferencesFormatter { int $max ) : string { return $this->messageLocalizer->localizeDigits( $base ) . - $this->messageLocalizer->formatNum( '.' ) . + $this->messageLocalizer->localizeSeparators( '.' ) . $this->messageLocalizer->localizeDigits( str_pad( (string)$offset, strlen( (string)$max ), '0', STR_PAD_LEFT ) ); diff --git a/tests/phpunit/unit/FootnoteMarkFormatterTest.php b/tests/phpunit/unit/FootnoteMarkFormatterTest.php index 96b599fd7..b90b6dfb8 100644 --- a/tests/phpunit/unit/FootnoteMarkFormatterTest.php +++ b/tests/phpunit/unit/FootnoteMarkFormatterTest.php @@ -37,7 +37,7 @@ class FootnoteMarkFormatterTest extends \MediaWikiUnitTestCase { } ); $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); - $mockMessageLocalizer->method( 'formatNum' )->willReturnArgument( 0 ); + $mockMessageLocalizer->method( 'localizeSeparators' )->willReturnArgument( 0 ); $mockMessageLocalizer->method( 'localizeDigits' )->willReturnArgument( 0 ); $mockMessageLocalizer->method( 'msg' )->willReturnCallback( function ( ...$args ) use ( $group, $fooLabels ) { diff --git a/tests/phpunit/unit/ReferenceMessageLocalizerUnitTest.php b/tests/phpunit/unit/ReferenceMessageLocalizerUnitTest.php index dbe39e480..559ed3d5f 100644 --- a/tests/phpunit/unit/ReferenceMessageLocalizerUnitTest.php +++ b/tests/phpunit/unit/ReferenceMessageLocalizerUnitTest.php @@ -11,15 +11,15 @@ use Language; class ReferenceMessageLocalizerUnitTest extends \MediaWikiUnitTestCase { /** - * @covers ::formatNum + * @covers ::localizeSeparators * @covers ::__construct */ - public function testFormatNum() { + public function testLocalizeSeparators() { $mockLanguage = $this->createMock( Language::class ); - $mockLanguage->method( 'formatNum' )->willReturn( '10,0' ); + $mockLanguage->method( 'separatorTransformTable' )->willReturn( [ '.' => ',', '0' => '' ] ); /** @var Language $mockLanguage */ $messageLocalizer = new ReferenceMessageLocalizer( $mockLanguage ); - $this->assertSame( '10,0', $messageLocalizer->formatNum( '10.0' ) ); + $this->assertSame( '10,0', $messageLocalizer->localizeSeparators( '10.0' ) ); } /** diff --git a/tests/phpunit/unit/ReferencesFormatterTest.php b/tests/phpunit/unit/ReferencesFormatterTest.php index a03ca0b7f..9eedb858c 100644 --- a/tests/phpunit/unit/ReferencesFormatterTest.php +++ b/tests/phpunit/unit/ReferencesFormatterTest.php @@ -214,7 +214,7 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase { ); $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); - $mockMessageLocalizer->method( 'formatNum' )->willReturnArgument( 0 ); + $mockMessageLocalizer->method( 'localizeSeparators' )->willReturnArgument( 0 ); $mockMessageLocalizer->method( 'localizeDigits' )->willReturnArgument( 0 ); $mockMessageLocalizer->method( 'msg' )->willReturnCallback( function ( ...$args ) { @@ -414,7 +414,7 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase { string $expectedLabel, int $base, int $offset, int $max ) { $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); - $mockMessageLocalizer->method( 'formatNum' )->willReturnArgument( 0 ); + $mockMessageLocalizer->method( 'localizeSeparators' )->willReturnArgument( 0 ); $mockMessageLocalizer->method( 'localizeDigits' )->willReturnArgument( 0 ); /** @var ReferenceMessageLocalizer $mockMessageLocalizer */