Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Symfony2 russian transliterator for Sluggable
stof_doctrine_extensions:
class:
sluggable: Your\Bundle\Misc\Misc\SluggableListener
default_locale: en_US
orm:
default:
tree: true
timestampable: true
sluggable: true
translatable: true
loggable: true
<?php
namespace Your\Bundle\Misc;
class SluggableListener extends \Gedmo\Sluggable\SluggableListener
{
public function __construct(){
$this->setTransliterator(array('\Your\Bundle\Misc\Transliterator', 'transliterate'));
}
protected function getNamespace()
{
return parent::getNamespace();
}
}
<?php
namespace Your\Bundle\Misc;
class Transliterator extends \Gedmo\Sluggable\Util\Urlizer
{
private static $table = array(
'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Ѓ' => 'G`',
'Ґ' => 'G`', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'YO', 'Є' => 'YE',
'Ж' => 'ZH', 'З' => 'Z', 'Ѕ' => 'Z', 'И' => 'I', 'Й' => 'Y',
'Ј' => 'J', 'І' => 'I', 'Ї' => 'YI', 'К' => 'K', 'Ќ' => 'K',
'Л' => 'L', 'Љ' => 'L', 'М' => 'M', 'Н' => 'N', 'Њ' => 'N',
'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T',
'У' => 'U', 'Ў' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'TS',
'Ч' => 'CH', 'Џ' => 'DH', 'Ш' => 'SH', 'Щ' => 'SHH', 'Ъ' => '``',
'Ы' => 'YI', 'Ь' => '`', 'Э' => 'E`', 'Ю' => 'YU', 'Я' => 'YA',
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'ѓ' => 'g',
'ґ' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'є' => 'ye',
'ж' => 'zh', 'з' => 'z', 'ѕ' => 'z', 'и' => 'i', 'й' => 'y',
'ј' => 'j', 'і' => 'i', 'ї' => 'yi', 'к' => 'k', 'ќ' => 'k',
'л' => 'l', 'љ' => 'l', 'м' => 'm', 'н' => 'n', 'њ' => 'n',
'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
'у' => 'u', 'ў' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'ts',
'ч' => 'ch', 'џ' => 'dh', 'ш' => 'sh', 'щ' => 'shh', 'ь' => '',
'ы' => 'yi', 'ъ' => "'", 'э' => 'e`', 'ю' => 'yu', 'я' => 'ya'
);
public static function transliterate($text, $separator = '-')
{
$text = strtr($text, self::$table);
if (preg_match('/[\x80-\xff]/', $text) && self::validUtf8($text)) {
$text = self::utf8ToAscii($text);
}
return self::urlize($text, $separator);
}
}
@chetzof

This comment has been minimized.

Copy link
Owner Author

@chetzof chetzof commented Dec 9, 2012

a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment