Skip to content

ToAscii: Some russian texts in Cyrillic (Azbuka) are wrong rewrited #203

Closed

Description

@janbarasek

Hi,

I can speak Russian language and I noticed that the transcription of Cyrillic (Azbuka) to Ascii is sometimes inaccurate.

For example string:

dump(Strings::toAscii('для'));

should be dlja, but not current dla, because char я means ja (Czech) or ya (English).

Sample:

Snímek obrazovky 2019-10-24 v 16 26 54

If my suggestion makes sense I can implement better translation with support for whole syllables and special cases.

Thanks.

Activity

  1. dg commented on Oct 29, 2019

    @dg
    Member

    Do you have enabled Transliterator?

    if ($transliterator === null && class_exists('Transliterator', false)) {
    And what implementation of iconv are you using?
    if (ICONV_IMPL === 'glibc') {

  2. janbarasek commented on Oct 29, 2019

    @janbarasek
    ContributorAuthor

    @dg Yes, Transliterator was instanced and ICONV_IMPL is libiconv.

    I detected it by:

    /**
     * Converts UTF-8 string to ASCII.
     */
    public static function toAscii(string $s): string
    {
    	static $transliterator = null;
    	if ($transliterator === null && class_exists('Transliterator', false)) {
    		$transliterator = \Transliterator::create('Any-Latin; Latin-ASCII');
    	}
    	dump(['transliterator' => $transliterator, 'iconv' => ICONV_IMPL]);

    Dumped:

    Snímek obrazovky 2019-10-29 v 17 43 49

    Thanks.

  3. dg commented on Oct 29, 2019

    @dg
    Member

    Transliterator converts я to â (according to ISO 9 https://cs.wikipedia.org/wiki/ISO_9) and then â to a.

    Probably solution is to add strtr for chars Я я Ю ю and maybe some others.

  4. janbarasek commented on Oct 29, 2019

    @janbarasek
    ContributorAuthor

    I think we can use (for Czech language):

    [
    	'ё' => 'jo',
    	'ъ' => '',
    	'ы' => 'y',
     	'ь' => '', 
    	'э' => 'eh', 
    	'ю' => 'ju',
    	'я' => 'ja',
    ]

    But for correct behavior is very important use target language (which can be loaded from second parameter string $language = 'en').

    And table for English:

    [
    	'ё' => 'jo',
    	'ъ' => '',
    	'ы' => 'y',
     	'ь' => '', 
    	'э' => 'e', 
    	'ю' => 'yu',
    	'я' => 'ya',
    ]
  5. added 2 commits that reference this issue on Jan 3, 2020
    88187c7
    d6cd63d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions