Giter Site home page Giter Site logo

Comments (11)

sim2github avatar sim2github commented on July 17, 2024 1

Seems like strtolower not work with UTF-8. Last rule cut off capitalized letters.
mb_strtolower works:

function createSlug($text)
{
  $dict = [
    //Russian translit
    'а' => 'a',
    'б' => 'b',
    'в' => 'v',
    'г' => 'g',
    'д' => 'd',
    'ж' => 'zh',
    'з' => 'z',
    'и' => 'i',
    'й' => 'j',
    'е' => 'e',
    'ё' => 'yo',
    'о' => 'o',
    'п' => 'p',
    'р' => 'r',
    'к' => 'k',
    'л' => 'l',
    'м' => 'm',
    'н' => 'n',
    'т' => 't',
    'ч' => 'ch',
    'с' => 's',
    'ц' => 'c',
    'у' => 'u',
    'ф' => 'f',
    'х' => 'h',
    'ш' => 'sh',
    'щ' => 'shch',
    'э' => 'eh',
    'ю' => 'yu',
    'я' => 'ya',
    'ы' => 'y',
    'ь' => '',
    //Ukrainian additional symbols
    'і' => 'i',
    'є' => 'ye',
    'ї' => 'yi',
    //Some of the special characters
    ':' => '-',
    ';' => '-',
    '.' => '-',
    ',' => '-',
    ' ' => '-',
    '\'' => ''
  ];

  $text = strtr(mb_strtolower(str_limit(trim($text), 255, ''), 'UTF-8'), $dict);
  $text = iconv('utf-8', 'ascii//translit', $text);
  return preg_replace('#[^a-z0-9\-]#si', '', $text);
}

from batflat.

sim2github avatar sim2github commented on July 17, 2024 1

@klocus according to the documentation setlocale must be set relative to the value of language (like ["en_english"=>"en_US", "pl_polski" => "pl_PL", ... ]), for 2bytes UTF-8 symbols languages (like Russian, maybe Turkish, Indonesian) need transliteration by dictionary.
So createSlug must have second parameter for LC_ALL set and extend dictionary for supported languages.

Tested:

  • English
  • Polish
  • French
  • Turkish
  • Swedish
  • Russian
  • Italian
  • Spanish
  • Dutch
  • Indonesian

from batflat.

sim2github avatar sim2github commented on July 17, 2024 1

My changes brake compatibility for Polish language at least. So we need cooperate with contributors to fix this issue for supported language and maybe examine with native speakers that`s all works fine.

If you dont plan use not tested languages - patch function manually till problem not fixed. Im not core developer, so i will wait till @klocus say what to do.

from batflat.

sim2github avatar sim2github commented on July 17, 2024

Iconv with hardcoded pl_PL locale in createSlug function don't return translited symbols.

function createSlug($text)

My propose:

function createSlug($text)
{
  $dict = [
    //Russian translit
    'а' => 'a',
    'б' => 'b',
    'в' => 'v',
    'г' => 'g',
    'д' => 'd',
    'ж' => 'zh',
    'з' => 'z',
    'и' => 'i',
    'й' => 'j',
    'е' => 'e',
    'ё' => 'yo',
    'о' => 'o',
    'п' => 'p',
    'р' => 'r',
    'к' => 'k',
    'л' => 'l',
    'м' => 'm',
    'н' => 'n',
    'т' => 't',
    'ч' => 'ch',
    'с' => 's',
    'ц' => 'c',
    'у' => 'u',
    'ф' => 'f',
    'х' => 'h',
    'ш' => 'sh',
    'щ' => 'shch',
    'э' => 'eh',
    'ю' => 'yu',
    'я' => 'ya',
    'ы' => 'y',
    'ь' => '',
    //Ukrainian additional symbols
    'і' => 'i',
    'є' => 'ye',
    'ї' => 'yi',
    //Some of the special characters
    ':' => '-',
    ';' => '-',
    '.' => '-',
    ',' => '-',
    ' ' => '-',
    '\'' => ''
  ];

  $text = strtr(strtolower(str_limit(trim($text), 255, '')), $dict);
  $text = iconv('utf-8', 'ascii//translit', $text);
  return preg_replace('#[^a-z0-9\-]#si', '', $text);
}

Test: Śęłąāčēģšž: .,;ΑαΒβΓγΔδΕεΖζ Ηабвгдеёжзийклмнн -> /Selaacegsz------abvgdeyozhzijklmn

Greek transliteration also have problems...

from batflat.

KonstantinFromRussia avatar KonstantinFromRussia commented on July 17, 2024

Thank you.
But the decision is not complete.
Now the problem with the tags in Russian, written with a Capital letter.
For example:
tags - тег1 тег2 тег3 - normally saved when editing a post
tags - Тег1 Тег2 Тег3 - not saved
I write a post, add one tag - Пост1, but I can’t add Пост2 tag, when post is saved, Пост1 tag remains.
Tag written with a capital letter - there can be only one !!!

from batflat.

KonstantinFromRussia avatar KonstantinFromRussia commented on July 17, 2024

Sorry
The problem with the tags in Russian with a capital letter was in the original version.

Yes, and there is a problem with transcription of slug too.
In the English version, the slug is set automatically.
In the Russian version, the slug must be set manually.

from batflat.

KonstantinFromRussia avatar KonstantinFromRussia commented on July 17, 2024

Understood!
It should be like this:

function createSlug($text)
{
  $dict = [
    //Russian translit
    'а' => 'a',
    'б' => 'b',
    'в' => 'v',
    'г' => 'g',
    'д' => 'd',
    'ж' => 'zh',
    'з' => 'z',
    'и' => 'i',
    'й' => 'j',
    'е' => 'e',
    'ё' => 'yo',
    'о' => 'o',
    'п' => 'p',
    'р' => 'r',
    'к' => 'k',
    'л' => 'l',
    'м' => 'm',
    'н' => 'n',
    'т' => 't',
    'ч' => 'ch',
    'с' => 's',
    'ц' => 'c',
    'у' => 'u',
    'ф' => 'f',
    'х' => 'h',
    'ш' => 'sh',
    'щ' => 'shch',
    'э' => 'eh',
    'ю' => 'yu',
    'я' => 'ya',
    'ы' => 'y',
    'ь' => '',
    'А' => 'A',
    'Б' => 'B',
    'В' => 'V',
    'Г' => 'G',
    'Д' => 'D',
    'Ж' => 'Zh',
    'З' => 'Z',
    'И' => 'I',
    'Й' => 'J',
    'Е' => 'E',
    'Ё' => 'Yo',
    'О' => 'O',
    'П' => 'P',
    'Р' => 'R',
    'К' => 'K',
    'Л' => 'L',
    'М' => 'M',
    'Н' => 'N',
    'Т' => 'T',
    'Ч' => 'Ch',
    'С' => 'S',
    'Ц' => 'C',
    'У' => 'U',
    'Ф' => 'F',
    'Х' => 'H',
    'Ш' => 'Sh',
    'Щ' => 'Shch',
    'Э' => 'Eh',
    'Ю' => 'Yu',
    'Я' => 'Ya',
    'Ы' => 'Y',
    'Ь' => '',
    //Ukrainian additional symbols
    'і' => 'i',
    'є' => 'ye',
    'ї' => 'yi',
    //Some of the special characters
    ':' => '-',
    ';' => '-',
    '.' => '-',
    ',' => '-',
    ' ' => '-',
    '\'' => ''
  ];

  $text = strtr(strtolower(str_limit(trim($text), 255, '')), $dict);
  $text = iconv('utf-8', 'ascii//translit', $text);
  return preg_replace('#[^a-z0-9\-]#si', '', $text);
}

In this version, both tags and slugs work!

from batflat.

KonstantinFromRussia avatar KonstantinFromRussia commented on July 17, 2024

sim2github - Here, now everything works fine!
Thank you!

from batflat.

KonstantinFromRussia avatar KonstantinFromRussia commented on July 17, 2024

sim2github - How to apply it in practice?
What should the correct code look like?

from batflat.

klocus avatar klocus commented on July 17, 2024

I will fix it soon.

from batflat.

michu2k avatar michu2k commented on July 17, 2024

It won't be fixed in this Bf version, but we will look into this problem in future updates.

from batflat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.