From a2cc49b1d99f529cd1d9bdb530226fc083dc058d Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 24 Jan 2020 17:40:09 +0100 Subject: [PATCH 1/2] 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. --- ...6_02_04_095452_add_slug_to_discussions.php | 2 +- framework/core/src/Discussion/Discussion.php | 2 +- framework/core/src/Util/Str.php | 31 ------------------- 3 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 framework/core/src/Util/Str.php diff --git a/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php b/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php index 21be8cc26..c34fdd17f 100644 --- a/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php +++ b/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php @@ -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) { diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 9db74c4a7..5d2ecb6ed 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -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 diff --git a/framework/core/src/Util/Str.php b/framework/core/src/Util/Str.php deleted file mode 100644 index e00a6d70e..000000000 --- a/framework/core/src/Util/Str.php +++ /dev/null @@ -1,31 +0,0 @@ - Date: Fri, 24 Jan 2020 17:42:14 +0100 Subject: [PATCH 2/2] Clarify the use-case of the JS slug helper --- framework/core/js/src/common/utils/string.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/core/js/src/common/utils/string.js b/framework/core/js/src/common/utils/string.js index 291e7bc7f..bab89c5e2 100644 --- a/framework/core/js/src/common/utils/string.js +++ b/framework/core/js/src/common/utils/string.js @@ -16,6 +16,10 @@ export function truncate(string, length, start = 0) { * Create a slug out of the given string. Non-alphanumeric characters are * converted to hyphens. * + * NOTE: This method does not use the comparably sophisticated transliteration + * mechanism that is employed in the backend. Therefore, it should only be used + * to *suggest* slugs that can be overridden by the user. + * * @param {String} string * @return {String} */