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:
Franz Liedke 2020-01-24 17:40:09 +01:00 committed by Daniël Klabbers
parent 5c3a0e3e6e
commit 03faaaedef
3 changed files with 2 additions and 33 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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;
}
}