mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 12:10:10 +08:00
Use Laravel's slugger for basic transliteration
This is better than the current system, as it adds transliteration rules for special characters, rather than just throwing all of them away. For languages that cannot be transliterated to ASCII in a reasonable manner, more possible improvements are outlined in #194.
This commit is contained in:
parent
a330a8fa28
commit
64c702aaf7
|
@ -7,9 +7,9 @@
|
|||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Util\Str;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
'up' => function (Builder $schema) {
|
||||
|
|
|
@ -23,7 +23,7 @@ use Flarum\Notification\Notification;
|
|||
use Flarum\Post\MergeableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use Flarum\Util\Str;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Util;
|
||||
|
||||
class Str
|
||||
{
|
||||
/**
|
||||
* Create a slug out of the given string.
|
||||
*
|
||||
* Non-alphanumeric characters are converted to hyphens.
|
||||
*
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public static function slug($str)
|
||||
{
|
||||
$str = strtolower($str);
|
||||
$str = preg_replace('/[^a-z0-9]/i', '-', $str);
|
||||
$str = preg_replace('/-+/', '-', $str);
|
||||
$str = preg_replace('/-$|^-/', '', $str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user