4

What are the native tools for string transliteration from Russian to English in Simfony2?

UPD i need transliteration, not translation, example

б => b, ю => yu
привет => privet

I need to convert any string of Russian language in the English alphabet

Stiig
  • 1,265
  • 13
  • 19

3 Answers3

5

There is no native tools for Symfony, but there is "native" PHP tools in Intl library.

For example

$transliterator = \Transliterator::create('Any-Latin');
$transliteratorToASCII = \Transliterator::create('Latin-ASCII');
$transliterateTitle = $transliteratorToASCII->transliterate($transliterator->transliterate($title));

In first place we transliterate Russian to Latin, then we transliterate it to ASCII.

If you don't like this method, you just can take something like in this example http://htmlweb.ru/php/example/translit.php. Just create class with such method end register it as service.

sergeylunev
  • 66
  • 1
  • 2
2

In Symfony 5 was introduced new component String You can transliterate and convert, splice, change case and other

https://symfony.com/doc/current/components/string.html#methods-added-by-codepointstring-and-unicodestring

Maksim Fedorov
  • 221
  • 2
  • 4
-3

Please consider looking at the symfony translation documentation at http://symfony.com/doc/current/book/translation.html

saamorim
  • 3,855
  • 17
  • 22