cocur / slugify

Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.
MIT License
2.88k stars 251 forks source link

There is any options to convert in Unicode symbols to description #276

Closed ShivPandey closed 3 years ago

ShivPandey commented 3 years ago

Input: 'unicode ♥' Output: 'unicode-love'

florianeckerstorfer commented 3 years ago

In theory this would be possible by adding a rules for Emoji or other unicode characters. However, we do not have such a list at the moment, because I think there would be a lot of discussion around what is the correct name. Just looking at your example, you would translate ❤️ into love, some people would translate it into heart and the official description is red heart.

florianeckerstorfer commented 3 years ago

I'm closing this issue, if you're interesting you can create a rule set which you can use just for your project (here is a database with emoji names) and you can create a PR and we will take it under consideration.

ausi commented 3 years ago

@ShivPandey you can use the following code with the https://github.com/ausi/slug-generator library:

$slugGenerator = new SlugGenerator([
    'preTransforms' => [
        ':: [:Symbol:]; :: Any-Name; \'\N{\' > \' \'; \'}\' > \' \';',
    ],
]);

$slugGenerator->generate('💩'); // pile-of-poo
$slugGenerator->generate('🙃'); // upside-down-face

$slugGenerator->generate('unicode ♥'); // unicode-black-heart-suit
$slugGenerator->generate('unicode ❤'); // unicode-heavy-black-heart
$slugGenerator->generate('unicode ❤️'); // unicode-heavy-black-heart
$slugGenerator->generate('unicode 👍'); // unicode-thumbs-up-sign

This converts symbols to their unicode names, but as you can see in the examples above they might not be the exact names you are looking for.