Skip to content

Commit 9333df7

Browse files
committed
Reorganize the Emoji component contents
1 parent 48c932d commit 9333df7

File tree

2 files changed

+98
-123
lines changed

2 files changed

+98
-123
lines changed

components/emoji.rst

Lines changed: 0 additions & 122 deletions
This file was deleted.

components/string.rst

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,101 @@ requested during the program execution. You can also create lazy strings from a
507507
// hash computation only if it's needed
508508
$lazyHash = LazyString::fromStringable(new Hash());
509509

510+
Working with Emojis
511+
-------------------
512+
513+
.. versionadded:: 7.1
514+
515+
The emoji component was introduced in Symfony 7.1.
516+
517+
Symfony provides several utilities to work with emoji characters and sequences
518+
from the `Unicode CLDR dataset`_. They are available via the Emoji component,
519+
which you must first install in your application:
520+
521+
.. code-block:: terminal
522+
523+
$ composer require symfony/emoji
524+
525+
The data needed to store the transliteration of all emojis (~5,000) into all
526+
languages take a considerable disk space.
527+
528+
If you need to save disk space (e.g. because you deploy to some service with tight
529+
size constraints), run this command (e.g. as an automated script after ``composer install``)
530+
to compress the internal Symfony emoji data files using the PHP ``zlib`` extension:
531+
532+
.. code-block:: terminal
533+
534+
# adjust the path to the 'compress' binary based on your application installation
535+
$ php ./vendor/symfony/emoji/Resources/bin/compress
536+
537+
.. _string-emoji-transliteration:
538+
539+
Emoji Transliteration
540+
~~~~~~~~~~~~~~~~~~~~~
541+
542+
The ``EmojiTransliterator`` class offers a way to translate emojis into their
543+
textual representation in all languages based on the `Unicode CLDR dataset`_::
544+
545+
use Symfony\Component\Emoji\EmojiTransliterator;
546+
547+
// Describe emojis in English
548+
$transliterator = EmojiTransliterator::create('en');
549+
$transliterator->transliterate('Menus with 🍕 or 🍝');
550+
// => 'Menus with pizza or spaghetti'
551+
552+
// Describe emojis in Ukrainian
553+
$transliterator = EmojiTransliterator::create('uk');
554+
$transliterator->transliterate('Menus with 🍕 or 🍝');
555+
// => 'Menus with піца or спагеті'
556+
557+
558+
The ``EmojiTransliterator`` also provides special locales that convert emojis to
559+
short codes and vice versa in specific platforms, such as GitHub and Slack.
560+
561+
GitHub Emoji Transliteration
562+
............................
563+
564+
Convert GitHub emojis to short codes with the ``emoji-github`` locale::
565+
566+
$transliterator = EmojiTransliterator::create('emoji-github');
567+
$transliterator->transliterate('Teenage 🐢 really love 🍕');
568+
// => 'Teenage :turtle: really love :pizza:'
569+
570+
Convert GitHub short codes to emojis with the ``github-emoji`` locale::
571+
572+
$transliterator = EmojiTransliterator::create('github-emoji');
573+
$transliterator->transliterate('Teenage :turtle: really love :pizza:');
574+
// => 'Teenage 🐢 really love 🍕'
575+
576+
Slack Emoji Transliteration
577+
...........................
578+
579+
Convert Slack emojis to short codes with the ``emoji-slack`` locale::
580+
581+
$transliterator = EmojiTransliterator::create('emoji-slack');
582+
$transliterator->transliterate('Menus with 🥗 or 🧆');
583+
// => 'Menus with :green_salad: or :falafel:'
584+
585+
Convert Slack short codes to emojis with the ``slack-emoji`` locale::
586+
587+
$transliterator = EmojiTransliterator::create('slack-emoji');
588+
$transliterator->transliterate('Menus with :green_salad: or :falafel:');
589+
// => 'Menus with 🥗 or 🧆'
590+
591+
Removing Emojis
592+
~~~~~~~~~~~~~~~
593+
594+
The ``EmojiTransliterator`` can also be used to remove all emojis from a string,
595+
via the special ``strip`` locale::
596+
597+
use Symfony\Component\Emoji\EmojiTransliterator;
598+
599+
$transliterator = EmojiTransliterator::create('strip');
600+
$transliterator->transliterate('🎉Hey!🥳 🎁Happy Birthday!🎁');
601+
// => 'Hey! Happy Birthday!'
602+
603+
.. _string-slugger:
604+
510605
Slugger
511606
-------
512607

@@ -579,7 +674,8 @@ the injected slugger is the same as the request locale::
579674
Slug Emojis
580675
~~~~~~~~~~~
581676

582-
You can transform any emojis into their textual representation::
677+
You can also combine the :ref:`emoji transliterator <string-emoji-transliteration>`
678+
with the slugger to transform any emojis into their textual representation::
583679

584680
use Symfony\Component\String\Slugger\AsciiSlugger;
585681

@@ -648,3 +744,4 @@ possible to determine a unique singular/plural form for the given word.
648744
.. _`Code points`: https://en.wikipedia.org/wiki/Code_point
649745
.. _`Grapheme clusters`: https://en.wikipedia.org/wiki/Grapheme
650746
.. _`Unicode equivalence`: https://en.wikipedia.org/wiki/Unicode_equivalence
747+
.. _`Unicode CLDR dataset`: https://github.com/unicode-org/cldr

0 commit comments

Comments
 (0)