55class DefaultSlugGenerator implements SlugGeneratorInterface
66{
77 const LANG_CHINESE = 'chinese ' ;
8+
89 const LANG_RUSSIAN = 'russian ' ;
10+
911 const LANG_ARABIC = 'arabic ' ;
12+
1013 const LANG_JAPANESE = 'japanese ' ;
11- const LANG_ENGLISH = 'english ' ;
12- const LANG_AUTO = 'auto ' ;
14+
15+ const LANG_ENGLISH = 'english ' ;
16+
17+ const LANG_AUTO = 'auto ' ;
1318
1419 private static $ transliterationRules = [
1520 self ::LANG_CHINESE => 'Han-Latin; Latin-ASCII; Lower() ' ,
@@ -29,15 +34,15 @@ public function generate($text, $language = self::LANG_AUTO, $separator = '-')
2934 // Try transliteration first
3035 if (function_exists ('transliterator_transliterate ' ) && isset (self ::$ transliterationRules [$ language ])) {
3136 $ transliterated = transliterator_transliterate (
32- self ::$ transliterationRules [$ language ],
37+ self ::$ transliterationRules [$ language ],
3338 $ text
3439 );
35-
40+
3641 if ($ transliterated ) {
3742 $ slug = preg_replace ('/[^a-z0-9]+/ ' , $ separator , $ transliterated );
3843 $ slug = trim ($ slug , $ separator );
39-
40- if (!empty ($ slug )) {
44+
45+ if (! empty ($ slug )) {
4146 return $ slug ;
4247 }
4348 }
@@ -58,17 +63,17 @@ private static function detectLanguage($text)
5863 if (preg_match ('/[\x{4e00}-\x{9fff}]/u ' , $ text )) {
5964 return self ::LANG_CHINESE ;
6065 }
61-
66+
6267 // Cyrillic characters (Russian)
6368 if (preg_match ('/[\x{0400}-\x{04FF}]/u ' , $ text )) {
6469 return self ::LANG_RUSSIAN ;
6570 }
66-
71+
6772 // Arabic characters
6873 if (preg_match ('/[\x{0600}-\x{06FF}]/u ' , $ text )) {
6974 return self ::LANG_ARABIC ;
7075 }
71-
76+
7277 return self ::LANG_ENGLISH ; // Default fallback to English
7378 }
7479
@@ -106,13 +111,13 @@ private static function fallbackRussian($text, $separator)
106111 'О ' => 'O ' , 'П ' => 'P ' , 'Р ' => 'R ' , 'С ' => 'S ' , 'Т ' => 'T ' ,
107112 'У ' => 'U ' , 'Ф ' => 'F ' , 'Х ' => 'Kh ' , 'Ц ' => 'Ts ' , 'Ч ' => 'Ch ' ,
108113 'Ш ' => 'Sh ' , 'Щ ' => 'Shch ' , 'Ъ ' => '' , 'Ы ' => 'Y ' , 'Ь ' => '' ,
109- 'Э ' => 'E ' , 'Ю ' => 'Yu ' , 'Я ' => 'Ya '
114+ 'Э ' => 'E ' , 'Ю ' => 'Yu ' , 'Я ' => 'Ya ' ,
110115 ];
111116
112117 $ result = strtr ($ text , $ russianMap );
113118 $ result = preg_replace ('/[^a-zA-Z0-9\s]/ ' , '' , $ result );
114119 $ result = preg_replace ('/\s+/ ' , $ separator , $ result );
115-
120+
116121 return strtolower (trim ($ result , $ separator ));
117122 }
118123
@@ -121,7 +126,7 @@ private static function fallbackChinese($text, $separator)
121126 // Use timestamp-based fallback for Chinese
122127 $ hash = substr (md5 ($ text ), 0 , 8 );
123128 $ timestamp = date ('Ymd ' );
124-
129+
125130 return "content {$ separator }{$ timestamp }{$ separator }{$ hash }" ;
126131 }
127132
@@ -135,7 +140,7 @@ private static function fallbackGeneric($text, $separator)
135140 {
136141 $ result = preg_replace ('/[^a-zA-Z0-9\s]/ ' , '' , $ text );
137142 $ result = preg_replace ('/\s+/ ' , $ separator , $ result );
138-
143+
139144 return strtolower (trim ($ result , $ separator ));
140145 }
141146}
0 commit comments