slug-generator icon indicating copy to clipboard operation
slug-generator copied to clipboard

Cyrillic/Russian generation

Open Sogl opened this issue 3 years ago • 3 comments

For example, I tried to convert name Артём to artyom.

What I tried (under the numbers are code options):

$generator = new SlugGenerator;

//1

$generator = new SlugGenerator((new SlugOptions)->setLocale('ru'));

//2
$str = $generator->generate($str, ['locale' => 'ru']);

//3
$str = $generator->generate($str, ['locale' => 'uk', 'preTransforms' => ['uk-uk_Latn/BGN']]);

Last option from this issue: https://github.com/ausi/slug-generator/issues/19

Wrong result artem in all cases. How to fix?

Sogl avatar Sep 23 '22 22:09 Sogl

Seems that the rules of the unicode library think that ё should be transformed to ё and not to yo see https://github.com/unicode-org/cldr/blob/7825c7bfc1d036b9911e467c620c7cfe224ef45e/common/transforms/Russian-Latin-BGN.xml#L122-L132

Can you point me to the rules that discrible how to transform Артём to artyom?

ausi avatar Sep 24 '22 13:09 ausi

https://en.wikipedia.org/wiki/Romanization_of_Russian#Transliteration_table

ISO 9:1995; GOST 7.79-2000(A) is the closest

Sogl avatar Sep 24 '22 14:09 Sogl

There doesn’t seem to be a matching transform available in the CLDR: https://github.com/unicode-org/cldr/tree/main/common/transforms

But you could still prepend your own rules to achieve the desired result:

$generator->generate($str, ['locale' => 'ru', 'preTransforms' => ['ё>yo;']]);

More information about the rule syntax can be found in the ICU documentation: https://unicode-org.github.io/icu/userguide/transforms/general/rules.html

ausi avatar Oct 01 '22 18:10 ausi