Skip to content

[Intl] Document the emoji transliterator #17088

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
Aug 3, 2022
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 components/intl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This component provides the following ICU data:
* `Locales`_
* `Currencies`_
* `Timezones`_
* `Emoji Transliteration`_

Language and Script Names
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -359,6 +360,35 @@ to catching the exception, you can also check if a given timezone ID is valid::

$isValidTimezone = Timezones::exists($timezoneId);

.. _component-intl-emoji-transliteration:

Emoji Transliteration
~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 6.2

The Empoji transliteration feature was introduced in Symfony 6.2.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a little typo here :) "Emoji"

Copy link
Member

Choose a reason for hiding this comment

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

good catch :) fixed in 863dcbe


The ``EmojiTransliterator`` class provides an utility to translate emojis into
their textual representation in all languages based on the `Unicode CLDR dataset`_::

use Symfony\Component\Intl\Transliterator\EmojiTransliterator;

// describe emojis in English
$transliterator = EmojiTransliterator::create('en');
$transliterator->transliterate('Menus with 🍕 or 🍝');
// => 'Menus with pizza or spaghetti'

// describe emojis in Ukrainian
$transliterator = EmojiTransliterator::create('uk');
$transliterator->transliterate('Menus with 🍕 or 🍝');
// => 'Menus with піца or спагеті'

.. tip::

Combine this emoji transliterator with the :ref:`Symfony String slugger <string-slugger>`
to improve the slugs of contents that include emojis (e.g. for URLs).

Learn more
----------

Expand All @@ -381,3 +411,4 @@ Learn more
.. _`daylight saving time (DST)`: https://en.wikipedia.org/wiki/Daylight_saving_time
.. _`ISO 639-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_639-1
.. _`ISO 639-2 alpha-3 (2T)`: https://en.wikipedia.org/wiki/ISO_639-2
.. _`Unicode CLDR dataset`: https://github.com/unicode-org/cldr
7 changes: 7 additions & 0 deletions components/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ letter A with ring above"*) or a sequence of two code points (``U+0061`` =
u('å')->normalize(UnicodeString::NFD);
u('å')->normalize(UnicodeString::NFKD);

.. _string-slugger:

Slugger
-------

Expand Down Expand Up @@ -486,6 +488,11 @@ another separator as the second argument::
$slug = $slugger->slug('Wôrķšƥáçè ~~sèťtïñğš~~', '/');
// $slug = 'Workspace/settings'

.. tip::

Combine this slugger with the :ref:`Symfony emoji transliterator <component-intl-emoji-transliteration>`
to improve the slugs of contents that include emojis (e.g. for URLs).

The slugger transliterates the original string into the Latin script before
applying the other transformations. The locale of the original string is
detected automatically, but you can define it explicitly::
Expand Down