D
D
Dmitry Sokolov2016-07-12 09:08:33
Yii
Dmitry Sokolov, 2016-07-12 09:08:33

How to create your own transliteration table for aliases (slugs)?

Good afternoon. I would be grateful for help in this matter.
I'm making a slug for urls. To generate aliases I use

$model->alias_name = \yii\helpers\BaseInflector::slug($model->name, $replacement = '-', $lowercase = false);

But the rules by which the letters of the Cyrillic alphabet are replaced by the Latin alphabet are rather strange. I want to make my own table of correspondences.
The BaseInflector class
says,
* @var array fallback map for transliteration used by  when intl isn't available.
     */
    public static $transliteration = [
        'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C',
        'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I',
        'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ő' => 'O',
        'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', 'Ý' => 'Y', 'Þ' => 'TH',
        'ß' => 'ss',
        'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c',
        'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
        'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o',
        'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th',
        'ÿ' => 'y',

It's not clear to me what are these symbols in this table + what is this intl extension and how to make my own table of correspondences and force BaseInflector::slug to replace symbols based on this table.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pogran, 2016-07-12
@Dm-Sok

I can assume that these characters are the correspondence of what will be replaced with what. That is, the string 'ÿ' => 'y' means that the character ÿ will be replaced by y . Make your own helper and inherit from BaseInflector . In it, redefine $transliteration to your variant.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question