Skip to content

[Emoji][Twig] Add emojify filter #19773

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
Jun 20, 2024
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
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)*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is null, default extension catalog is applied. It's "text" by default in construct.

I don't remember what is text behavior, but we should discribe this default ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text locale must be documented first #19745

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #19919

**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: 👍 #}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rendering of an unknown value for the catalog ?

Adding an example could be great !

{{ ':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
Loading