diff --git a/components/intl.rst b/components/intl.rst index 1a8ae2bbf0b..8166a18b1a7 100644 --- a/components/intl.rst +++ b/components/intl.rst @@ -385,9 +385,25 @@ their textual representation in all languages based on the `Unicode CLDR dataset $transliterator->transliterate('Menus with 🍕 or 🍝'); // => 'Menus with піца or спагеті' +The ``EmojiTransliterator`` class also provides two extra catalogues: ``github`` +and ``slack`` that converts any emojis to the corresponding short code in the +respective platforms:: + + use Symfony\Component\Intl\Transliterator\EmojiTransliterator; + + // describe emojis in Slack short code + $transliterator = EmojiTransliterator::create('slack'); + $transliterator->transliterate('Menus with 🥗 or 🧆'); + // => 'Menus with :green_salad: or :falafel:' + + // describe emojis in Github short code + $transliterator = EmojiTransliterator::create('github'); + $transliterator->transliterate('Menus with 🥗 or 🧆'); + // => 'Menus with :green_salad: or :falafel:' + .. tip:: - Combine this emoji transliterator with the :ref:`Symfony String slugger ` + Combine this emoji transliterator with the :ref:`Symfony String slugger ` to improve the slugs of contents that include emojis (e.g. for URLs). Learn more diff --git a/components/string.rst b/components/string.rst index 455ef90eafe..098042f9465 100644 --- a/components/string.rst +++ b/components/string.rst @@ -451,8 +451,6 @@ letter A with ring above"*) or a sequence of two code points (``U+0061`` = u('å')->normalize(UnicodeString::NFD); u('å')->normalize(UnicodeString::NFKD); -.. _string-slugger: - Slugger ------- @@ -488,11 +486,6 @@ another separator as the second argument:: $slug = $slugger->slug('Wôrķšƥáçè ~~sèťtïñğš~~', '/'); // $slug = 'Workspace/settings' -.. tip:: - - Combine this slugger with the :ref:`Symfony emoji transliterator ` - to improve the slugs of contents that include emojis (e.g. for URLs). - The slugger transliterates the original string into the Latin script before applying the other transformations. The locale of the original string is detected automatically, but you can define it explicitly:: @@ -526,6 +519,39 @@ the injected slugger is the same as the request locale:: } } +.. _string-slugger-emoji: + +Slug Emojis +~~~~~~~~~~~ + +.. versionadded:: 6.2 + + The Emoji transliteration feature was introduced in Symfony 6.2. + +You can transform any emojis into a textual representation:: + + use Symfony\Component\String\Slugger\AsciiSlugger; + + $slugger = new AsciiSlugger(); + $slugger = $slugger->withEmoji(); + + $slug = $slugger->slug('a 😺, 🐈‍⬛, and a 🦁 go to 🏞️', '-', 'en'); + // $slug = 'a-grinning-cat-black-cat-and-a-lion-go-to-national-park'; + + $slug = $slugger->slug('un 😺, 🐈‍⬛, et un 🦁 vont au 🏞️', '-', 'fr'); + // $slug = 'un-chat-qui-sourit-chat-noir-et-un-tete-de-lion-vont-au-parc-national'; + +If you want to use a specific locale for the emoji, or to use the shorts code +from `github` or `slack`, use the first argument of ``withEmoji()`` method:: + + use Symfony\Component\String\Slugger\AsciiSlugger; + + $slugger = new AsciiSlugger(); + $slugger = $slugger->withEmoji('github'); // or "en", or "fr", etc. + + $slug = $slugger->slug('a 😺, 🐈‍⬛, and a 🦁'); + // $slug = 'a-smiley-cat-black-cat-and-a-lion'; + .. _string-inflector: Inflector