From 11f9e6494e100602069624b196b2f423f6189f83 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Tue, 21 Nov 2023 21:17:21 +1100 Subject: [PATCH 1/2] Add Str::transliterate to Stringable --- src/Illuminate/Support/Stringable.php | 12 ++++++++++++ tests/Support/SupportStringableTest.php | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 7d3558c0fdc9..c394147c1b14 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -88,6 +88,18 @@ public function ascii($language = 'en') return new static(Str::ascii($this->value, $language)); } + /** + * Transliterate a string to its closest ASCII representation. + * + * @param string|null $unknown + * @param bool|null $strict + * @return static + */ + public function transliterate($unknown = '?', $strict = false) + { + return new static(Str::transliterate($this->value, $unknown, $strict)); + } + /** * Get the trailing name component of the path. * diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 39506394a044..5cf433fa4973 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -527,6 +527,12 @@ public function testAscii() $this->assertSame('u', (string) $this->stringable('ΓΌ')->ascii()); } + public function testTransliterate() + { + $this->assertSame('HHH', (string) $this->stringable('πŸŽ‚πŸš§πŸ†')->transliterate('H')); + $this->assertSame('Hello', (string) $this->stringable('πŸŽ‚')->transliterate('Hello')); + } + public function testNewLine() { $this->assertSame('Laravel'.PHP_EOL, (string) $this->stringable('Laravel')->newLine()); From 3f0e5b4f4256977b83f84e2c137adfa91d8f9b0c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Nov 2023 08:37:53 -0600 Subject: [PATCH 2/2] formatting --- src/Illuminate/Support/Stringable.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index c394147c1b14..018416d9ac73 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -88,18 +88,6 @@ public function ascii($language = 'en') return new static(Str::ascii($this->value, $language)); } - /** - * Transliterate a string to its closest ASCII representation. - * - * @param string|null $unknown - * @param bool|null $strict - * @return static - */ - public function transliterate($unknown = '?', $strict = false) - { - return new static(Str::transliterate($this->value, $unknown, $strict)); - } - /** * Get the trailing name component of the path. * @@ -809,6 +797,18 @@ public function title() return new static(Str::title($this->value)); } + /** + * Transliterate a string to its closest ASCII representation. + * + * @param string|null $unknown + * @param bool|null $strict + * @return static + */ + public function transliterate($unknown = '?', $strict = false) + { + return new static(Str::transliterate($this->value, $unknown, $strict)); + } + /** * Convert the given string to title case for each word. *