From d25c009b180ca57b0449fad9c285ceae780110e7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 11 Apr 2024 11:53:36 +0200 Subject: [PATCH] [Emoji][Twig] Add `emojify` filter --- reference/twig_reference.rst | 31 +++++++++++++++++++++++++++++++ string.rst | 29 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index fcd95ce9b6e..812b56f8637 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -645,6 +645,37 @@ serialize Accepts any data that can be serialized by the :doc:`Serializer component ` and returns a serialized string in the specified ``format``. +.. _reference-twig-filter-emojify: + +emojify +~~~~~~~ + +.. versionadded:: 7.1 + + The ``emojify`` filter was introduced in Symfony 7.1. + +.. code-block:: twig + + {{ text|emojify(catalog = null) }} + +``text`` + **type**: ``string`` + +``catalog`` *(optional)* + **type**: ``string`` | ``null`` + + The emoji set used to generate the textual representation (``slack``, + ``github``, ``gitlab``, etc.) + +It transforms the textual representation of an emoji (e.g. ``:wave:``) into the +actual emoji (👋): + +.. code-block:: twig + + {{ ':+1:'|emojify }} {# renders: 👍 #} + {{ ':+1:'|emojify('github') }} {# renders: 👍 #} + {{ ':thumbsup:'|emojify('gitlab') }} {# renders: 👍 #} + .. _reference-twig-tags: Tags diff --git a/string.rst b/string.rst index 01752fff9c9..5e18cfcaea3 100644 --- a/string.rst +++ b/string.rst @@ -613,6 +613,8 @@ Convert Slack short codes to emojis with the ``slack-emoji`` locale:: $transliterator->transliterate('Menus with :green_salad: or :falafel:'); // => 'Menus with 🥗 or 🧆' +.. _string-text-emoji: + Universal Emoji Short Codes Transliteration ########################################### @@ -637,6 +639,33 @@ You can convert emojis to short codes with the ``emoji-text`` locale:: $transliterator->transliterate('Breakfast with 🥝 or 🥛'); // => 'Breakfast with :kiwifruit: or :milk-glass: +Inverse Emoji Transliteration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 7.1 + + The inverse emoji transliteration was introduced in Symfony 7.1. + +Given the textual representation of an emoji, you can reverse it back to get the +actual emoji thanks to the :ref:`emojify filter `: + +.. code-block:: twig + + {{ 'I like :kiwi-fruit:'|emojify }} {# renders: I like 🥝 #} + {{ 'I like :kiwi:'|emojify }} {# renders: I like 🥝 #} + {{ 'I like :kiwifruit:'|emojify }} {# renders: I like 🥝 #} + +By default, ``emojify`` uses the :ref:`text catalog `, which +merges the emoji text codes of all services. If you prefer, you can select a +specific catalog to use: + +.. code-block:: twig + + {{ 'I :green-heart: this'|emojify }} {# renders: I 💚 this #} + {{ ':green_salad: is nice'|emojify('slack') }} {# renders: 🥗 is nice #} + {{ 'My :turtle: has no name yet'|emojify('github') }} {# renders: My 🐢 has no name yet #} + {{ ':kiwi: is a great fruit'|emojify('gitlab') }} {# renders: 🥝 is a great fruit #} + Removing Emojis ~~~~~~~~~~~~~~~