Skip to content

[Intl][String] Document emoji #17194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion components/intl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string-slugger>`
Combine this emoji transliterator with the :ref:`Symfony String slugger <string-slugger-emoji>`
to improve the slugs of contents that include emojis (e.g. for URLs).

Learn more
Expand Down
40 changes: 33 additions & 7 deletions components/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down Expand Up @@ -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 <component-intl-emoji-transliteration>`
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::
Expand Down Expand Up @@ -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
Expand Down