@@ -516,176 +516,10 @@ requested during the program execution. You can also create lazy strings from a
516
516
// hash computation only if it's needed
517
517
$lazyHash = LazyString::fromStringable(new Hash());
518
518
519
- .. _working-with-emojis :
520
-
521
519
Working with Emojis
522
520
-------------------
523
521
524
- .. versionadded :: 7.1
525
-
526
- The emoji component was introduced in Symfony 7.1.
527
-
528
- Symfony provides several utilities to work with emoji characters and sequences
529
- from the `Unicode CLDR dataset `_. They are available via the Emoji component,
530
- which you must first install in your application:
531
-
532
- .. code-block :: terminal
533
-
534
- $ composer require symfony/emoji
535
-
536
- .. include :: /components/require_autoload.rst.inc
537
-
538
- The data needed to store the transliteration of all emojis (~5,000) into all
539
- languages take a considerable disk space.
540
-
541
- If you need to save disk space (e.g. because you deploy to some service with tight
542
- size constraints), run this command (e.g. as an automated script after ``composer install ``)
543
- to compress the internal Symfony emoji data files using the PHP ``zlib `` extension:
544
-
545
- .. code-block :: terminal
546
-
547
- # adjust the path to the 'compress' binary based on your application installation
548
- $ php ./vendor/symfony/emoji/Resources/bin/compress
549
-
550
- .. _string-emoji-transliteration :
551
-
552
- Emoji Transliteration
553
- ~~~~~~~~~~~~~~~~~~~~~
554
-
555
- The ``EmojiTransliterator `` class offers a way to translate emojis into their
556
- textual representation in all languages based on the `Unicode CLDR dataset `_::
557
-
558
- use Symfony\Component\Emoji\EmojiTransliterator;
559
-
560
- // Describe emojis in English
561
- $transliterator = EmojiTransliterator::create('en');
562
- $transliterator->transliterate('Menus with 🍕 or 🍝');
563
- // => 'Menus with pizza or spaghetti'
564
-
565
- // Describe emojis in Ukrainian
566
- $transliterator = EmojiTransliterator::create('uk');
567
- $transliterator->transliterate('Menus with 🍕 or 🍝');
568
- // => 'Menus with піца or спагеті'
569
-
570
- Transliterating Emoji Text Short Codes
571
- ......................................
572
-
573
- Services like GitHub and Slack allows to include emojis in your messages using
574
- text short codes (e.g. you can add the ``:+1: `` code to render the 👍 emoji).
575
-
576
- Symfony also provides a feature to transliterate emojis into short codes and vice
577
- versa. The short codes are slightly different on each service, so you must pass
578
- the name of the service as an argument when creating the transliterator:
579
-
580
- GitHub Emoji Short Codes Transliteration
581
- ########################################
582
-
583
- Convert emojis to GitHub short codes with the ``emoji-github `` locale::
584
-
585
- $transliterator = EmojiTransliterator::create('emoji-github');
586
- $transliterator->transliterate('Teenage 🐢 really love 🍕');
587
- // => 'Teenage :turtle: really love :pizza:'
588
-
589
- Convert GitHub short codes to emojis with the ``github-emoji `` locale::
590
-
591
- $transliterator = EmojiTransliterator::create('github-emoji');
592
- $transliterator->transliterate('Teenage :turtle: really love :pizza:');
593
- // => 'Teenage 🐢 really love 🍕'
594
-
595
- Gitlab Emoji Short Codes Transliteration
596
- ########################################
597
-
598
- Convert emojis to Gitlab short codes with the ``emoji-gitlab `` locale::
599
-
600
- $transliterator = EmojiTransliterator::create('emoji-gitlab');
601
- $transliterator->transliterate('Breakfast with 🥝 or 🥛');
602
- // => 'Breakfast with :kiwi: or :milk:'
603
-
604
- Convert Gitlab short codes to emojis with the ``gitlab-emoji `` locale::
605
-
606
- $transliterator = EmojiTransliterator::create('gitlab-emoji');
607
- $transliterator->transliterate('Breakfast with :kiwi: or :milk:');
608
- // => 'Breakfast with 🥝 or 🥛'
609
-
610
- Slack Emoji Short Codes Transliteration
611
- #######################################
612
-
613
- Convert emojis to Slack short codes with the ``emoji-slack `` locale::
614
-
615
- $transliterator = EmojiTransliterator::create('emoji-slack');
616
- $transliterator->transliterate('Menus with 🥗 or 🧆');
617
- // => 'Menus with :green_salad: or :falafel:'
618
-
619
- Convert Slack short codes to emojis with the ``slack-emoji `` locale::
620
-
621
- $transliterator = EmojiTransliterator::create('slack-emoji');
622
- $transliterator->transliterate('Menus with :green_salad: or :falafel:');
623
- // => 'Menus with 🥗 or 🧆'
624
-
625
- .. _string-text-emoji :
626
-
627
- Universal Emoji Short Codes Transliteration
628
- ###########################################
629
-
630
- If you don't know which service was used to generate the short codes, you can use
631
- the ``text-emoji `` locale, which combines all codes from all services::
632
-
633
- $transliterator = EmojiTransliterator::create('text-emoji');
634
-
635
- // Github short codes
636
- $transliterator->transliterate('Breakfast with :kiwi-fruit: or :milk-glass:');
637
- // Gitlab short codes
638
- $transliterator->transliterate('Breakfast with :kiwi: or :milk:');
639
- // Slack short codes
640
- $transliterator->transliterate('Breakfast with :kiwifruit: or :glass-of-milk:');
641
-
642
- // all the above examples produce the same result:
643
- // => 'Breakfast with 🥝 or 🥛'
644
-
645
- You can convert emojis to short codes with the ``emoji-text `` locale::
646
-
647
- $transliterator = EmojiTransliterator::create('emoji-text');
648
- $transliterator->transliterate('Breakfast with 🥝 or 🥛');
649
- // => 'Breakfast with :kiwifruit: or :milk-glass:
650
-
651
- Inverse Emoji Transliteration
652
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
653
-
654
- .. versionadded :: 7.1
655
-
656
- The inverse emoji transliteration was introduced in Symfony 7.1.
657
-
658
- Given the textual representation of an emoji, you can reverse it back to get the
659
- actual emoji thanks to the :ref: `emojify filter <reference-twig-filter-emojify >`:
660
-
661
- .. code-block :: twig
662
-
663
- {{ 'I like :kiwi-fruit:'|emojify }} {# renders: I like 🥝 #}
664
- {{ 'I like :kiwi:'|emojify }} {# renders: I like 🥝 #}
665
- {{ 'I like :kiwifruit:'|emojify }} {# renders: I like 🥝 #}
666
-
667
- By default, ``emojify `` uses the :ref: `text catalog <string-text-emoji >`, which
668
- merges the emoji text codes of all services. If you prefer, you can select a
669
- specific catalog to use:
670
-
671
- .. code-block :: twig
672
-
673
- {{ 'I :green-heart: this'|emojify }} {# renders: I 💚 this #}
674
- {{ ':green_salad: is nice'|emojify('slack') }} {# renders: 🥗 is nice #}
675
- {{ 'My :turtle: has no name yet'|emojify('github') }} {# renders: My 🐢 has no name yet #}
676
- {{ ':kiwi: is a great fruit'|emojify('gitlab') }} {# renders: 🥝 is a great fruit #}
677
-
678
- Removing Emojis
679
- ~~~~~~~~~~~~~~~
680
-
681
- The ``EmojiTransliterator `` can also be used to remove all emojis from a string,
682
- via the special ``strip `` locale::
683
-
684
- use Symfony\Component\Emoji\EmojiTransliterator;
685
-
686
- $transliterator = EmojiTransliterator::create('strip');
687
- $transliterator->transliterate('🎉Hey!🥳 🎁Happy Birthday!🎁');
688
- // => 'Hey! Happy Birthday!'
522
+ These contents have been moved to the :doc: `Emoji component docs </emoji >`.
689
523
690
524
.. _string-slugger :
691
525
@@ -761,7 +595,7 @@ the injected slugger is the same as the request locale::
761
595
Slug Emojis
762
596
~~~~~~~~~~~
763
597
764
- You can also combine the :ref: `emoji transliterator <string- emoji-transliteration >`
598
+ You can also combine the :ref: `emoji transliterator <emoji-transliteration >`
765
599
with the slugger to transform any emojis into their textual representation::
766
600
767
601
use Symfony\Component\String\Slugger\AsciiSlugger;
@@ -831,4 +665,3 @@ possible to determine a unique singular/plural form for the given word.
831
665
.. _`Code points` : https://en.wikipedia.org/wiki/Code_point
832
666
.. _`Grapheme clusters` : https://en.wikipedia.org/wiki/Grapheme
833
667
.. _`Unicode equivalence` : https://en.wikipedia.org/wiki/Unicode_equivalence
834
- .. _`Unicode CLDR dataset` : https://github.com/unicode-org/cldr
0 commit comments