Skip to content

Commit

Permalink
[Emoji][Twig] Add emojify filter
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Jun 20, 2024
1 parent 227275a commit d25c009
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,37 @@ serialize
Accepts any data that can be serialized by the :doc:`Serializer component </serializer>`
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
Expand Down
29 changes: 29 additions & 0 deletions string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
###########################################

Expand All @@ -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 <reference-twig-filter-emojify>`:

.. 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 <string-text-emoji>`, 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
~~~~~~~~~~~~~~~

Expand Down

0 comments on commit d25c009

Please sign in to comment.