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

[5.5] Sync Str with Stringy 3.0.1 #18974

Merged
merged 7 commits into from
Apr 28, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Beautify lang check
  • Loading branch information
fernandobandeira committed Apr 27, 2017
commit db7a55bf0aa3fbb1b2b86f3cc6fc73cea5b6fd16
30 changes: 16 additions & 14 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class Str
*/
public static function ascii($value, $language = 'en')
{
$languageSpecific = static::languageSpecificCharsArray();
$languageSpecific = static::languageSpecificCharsArray($language);

if (isset($languageSpecific[$language])) {
$value = str_replace($languageSpecific[$language][0], $languageSpecific[$language][1], $value);
if ($languageSpecific != null) {
$value = str_replace($languageSpecific[0], $languageSpecific[1], $value);
}

foreach (static::charsArray() as $key => $val) {
Expand Down Expand Up @@ -346,11 +346,12 @@ public static function singular($value)
*
* @param string $title
* @param string $separator
* @param string $language
* @return string
*/
public static function slug($title, $separator = '-')
public static function slug($title, $separator = '-', $language = 'en')
{
$title = static::ascii($title);
$title = static::ascii($title, $language);

// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
Expand Down Expand Up @@ -594,21 +595,22 @@ protected static function charsArray()
*
* @see https://github.com/danielstjules/Stringy/blob/3.0.1/LICENSE.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this link to the licence intentional, or should this link to the source file?

Copy link
Contributor Author

@fernandobandeira fernandobandeira Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied it from the other method that graham created, I guess it's intentional to show that we can freely use this code on our project. But we could also link to the source file...

*
* @param string $language
* @return array
*/
protected static function languageSpecificCharsArray()
protected static function languageSpecificCharsArray($language)
{
static $languageSpecific;

if (isset($languageSpecific)) {
return $languageSpecific;
if (!isset($languageSpecific)) {
$languageSpecific = [
'de' => [
['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'],
['ae', 'oe', 'ue', 'AE', 'OE', 'UE'],
],
];
}

return $languageSpecific = [
'de' => [
['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'],
['ae', 'oe', 'ue', 'AE', 'OE', 'UE'],
],
];
return $languageSpecific[$language] ?? null;
}
}