From 0875668934a56138c533742e09a2a2cec2117640 Mon Sep 17 00:00:00 2001 From: Mohamed El Mrabet Date: Fri, 14 Aug 2026 17:48:28 +0100 Subject: [PATCH] fix(arabic): add missing letters, harakat, tatweel and Arabic-Indic digits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Arabic ruleset was missing nine letters, including the plain alif — the most frequent letter in the language — and the ta marbuta. An unmapped character is not transliterated: it falls through to the separator regexp and becomes a dash, so words were cut at arbitrary points. The two existing Arabic test cases documented that behaviour as expected: هذه هي اللغة العربية -> hthh-hy-llgh-laarby مرحبا العالم -> mrhb-laa-lm Both are updated to the corrected output. Added: - Alif and its variants: ا إ آ ٱ - Ta marbuta ة -> ah, alef maksura ى -> a - Carried hamza ؤ -> o and ئ -> a; standalone hamza ء is dropped, it carries no sound of its own - Harakat/tashkeel (U+064B..U+0652, U+0670) are removed rather than left to become dashes, so a vocalised word and its bare spelling slug identically - Tatweel/kashida U+0640 removed: decorative elongation, never lexical - Arabic-Indic digits ٠-٩, which previously produced an empty slug Transliteration choices were reviewed by a native Arabic speaker. Existing rules are left untouched, so no current slug changes except for the characters that produced no output at all. --- Resources/rules/arabic.json | 31 +++++++++++++++++++++++- src/RuleProvider/DefaultRuleProvider.php | 29 ++++++++++++++++++++++ tests/SlugifyTest.php | 15 ++++++++++-- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/Resources/rules/arabic.json b/Resources/rules/arabic.json index e46915f1..d87601cc 100644 --- a/Resources/rules/arabic.json +++ b/Resources/rules/arabic.json @@ -26,5 +26,34 @@ "ن" : "n", "ه" : "h", "و" : "o", - "ي" : "y" + "ي" : "y", + "ا" : "a", + "إ" : "a", + "آ" : "a", + "ٱ" : "a", + "ة" : "ah", + "ى" : "a", + "ؤ" : "o", + "ئ" : "a", + "ء" : "", + "ً" : "", + "ٌ" : "", + "ٍ" : "", + "َ" : "", + "ُ" : "", + "ِ" : "", + "ّ" : "", + "ْ" : "", + "ٰ" : "", + "ـ" : "", + "٠" : "0", + "١" : "1", + "٢" : "2", + "٣" : "3", + "٤" : "4", + "٥" : "5", + "٦" : "6", + "٧" : "7", + "٨" : "8", + "٩" : "9" } diff --git a/src/RuleProvider/DefaultRuleProvider.php b/src/RuleProvider/DefaultRuleProvider.php index 252af6f1..280e0666 100644 --- a/src/RuleProvider/DefaultRuleProvider.php +++ b/src/RuleProvider/DefaultRuleProvider.php @@ -58,6 +58,35 @@ class DefaultRuleProvider implements RuleProviderInterface 'ه' => 'h', 'و' => 'o', 'ي' => 'y', + 'ا' => 'a', + 'إ' => 'a', + 'آ' => 'a', + 'ٱ' => 'a', + 'ة' => 'ah', + 'ى' => 'a', + 'ؤ' => 'o', + 'ئ' => 'a', + 'ء' => '', + 'ً' => '', + 'ٌ' => '', + 'ٍ' => '', + 'َ' => '', + 'ُ' => '', + 'ِ' => '', + 'ّ' => '', + 'ْ' => '', + 'ٰ' => '', + 'ـ' => '', + '٠' => '0', + '١' => '1', + '٢' => '2', + '٣' => '3', + '٤' => '4', + '٥' => '5', + '٦' => '6', + '٧' => '7', + '٨' => '8', + '٩' => '9', ), 'armenian' => array ( diff --git a/tests/SlugifyTest.php b/tests/SlugifyTest.php index 84cfa7c9..9d3010b6 100644 --- a/tests/SlugifyTest.php +++ b/tests/SlugifyTest.php @@ -243,8 +243,19 @@ public function defaultRuleProvider() ['драма', 'drama'], ['Ύπαρξη Αυτής η Σκουληκομυρμηγκότρυπα', 'iparxi-autis-i-skoulikomirmigkotripa'], ['Français Œuf où à', 'francais-oeuf-ou-a'], - ['هذه هي اللغة العربية', 'hthh-hy-llgh-laarby'], - ['مرحبا العالم', 'mrhb-laa-lm'], + ['هذه هي اللغة العربية', 'hthh-hy-allghah-alaarbyah'], + ['مرحبا العالم', 'mrhba-alaaalm'], + ['مدرسة', 'mdrsah'], + ['مَدْرَسَة', 'mdrsah'], + ['مدرســـة', 'mdrsah'], + ['فاطمة', 'fatmah'], + ['على', 'aala'], + ['ماء', 'ma'], + ['مسؤول', 'msool'], + ['رئيس', 'rays'], + ['إبراهيم', 'abrahym'], + ['آمن', 'amn'], + ['غرفة ٢٠٥', 'ghrfah-205'], ['Één jaar', 'een-jaar'], ['tiếng việt rất khó', 'tieng-viet-rat-kho'], ['Nguyễn Đăng Khoa', 'nguyen-dang-khoa'],