Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add Str::transliterate to Stringable #49065

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,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.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down