Comments (11)
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.
@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.
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. I
m not core developer, so i will wait till @klocus say what to do.
from batflat.
Iconv with hardcoded pl_PL
locale in createSlug
function don't return translited symbols.
batflat/inc/core/lib/functions.php
Line 56 in bd0387d
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.
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.
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.
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.
sim2github - Here, now everything works fine!
Thank you!
from batflat.
sim2github - How to apply it in practice?
What should the correct code look like?
from batflat.
I will fix it soon.
from batflat.
It won't be fixed in this Bf version, but we will look into this problem in future updates.
from batflat.
Related Issues (20)
- Customizing Summernote HOT 2
- Error 403 Forbidden Access to this resource on the server is denied!
- Integré le blog sur la page d'accueil
- Arbitrary code execution on the backend
- Summernote Image Upload
- Blog et idées
- Replacing Blog module URL
- error 403 przy próbie wysłania formularza
- 403 error when I want to send form HOT 1
- langSwitcher does not change in blogpost
- Form isn´t Spam-Safe
- Two problems Deprecated: str_replace(): & 404 not found in localhost HOT 1
- Batflat Statistics: Countries
- sign up and blog
- Missing WYSIWYG editor from post creation
- How do I include an Subpage in my footer? HOT 8
- Problems with Batflat 1.3.6 on localhost and on commercial server
- how add category in blog
- Stored XSS in module page using description field
- Sad that this project is dead - Do you need a maintainer? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from batflat.