Search code examples
phpyii2slug

Why Inflector::slug in Yii2 generates wrong latin string from cyrillic?


Inflector::slug in Yii2 generates not correct string from cyrillic.

Example: автоматизация -> avtomatizacia, but it must be avtomatizaciya; зачислить -> zacislit, but it must be zachislit. How to fix it?

I use this for SEO urls. Can this influence if search engines will not recognise the correct keyword to improve SEO results for my website?


Solution

  • Because it uses ISO 9 for handling cyrillic and aparently its ISO 9:1995 version. Now when I put:

    echo \yii\helpers\Inflector::transliterate('автоматизация', 'Cyrillic;  Any-Latin');
    echo yii\helpers\Inflector::transliterate('зачислить', $a);
    

    I get:

    avtomatizaciâ 
    začislitʹ
    

    Which is as in ISO 9:1995. Slug method does conversion to ASCII character to charcter and so for example č gets changed into c.

    You can still do as you want just str-replace where needed. Or you can do the transliteration another way like this.