Skip to content

Commit d54711e

Browse files
committed
Add the documentation for the new emoji-transliterator component
1 parent 95f7525 commit d54711e

File tree

2 files changed

+65
-47
lines changed

2 files changed

+65
-47
lines changed

components/emoji_transliterator.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
The EmojiTransliterator component
2+
=================================
3+
4+
The EmojiTransliterator provides an implementation of :phpclass:`Transliterator` that
5+
can convert emojis to ASCII representations.
6+
7+
Installation
8+
------------
9+
10+
.. code-block:: terminal
11+
12+
$ composer require symfony/emoji-transliterator
13+
14+
.. include:: /components/require_autoload.rst.inc
15+
16+
Usage
17+
-----
18+
19+
The ``EmojiTransliterator`` class provides a utility to translate emojis into
20+
their textual representation in all languages based on the `Unicode CLDR dataset`_::
21+
22+
use Symfony\Component\EmojiTransliterator\EmojiTransliterator;
23+
24+
// describe emojis in English
25+
$transliterator = EmojiTransliterator::create('en');
26+
$transliterator->transliterate('Menus with 🍕 or 🍝');
27+
// => 'Menus with pizza or spaghetti'
28+
29+
// describe emojis in Ukrainian
30+
$transliterator = EmojiTransliterator::create('uk');
31+
$transliterator->transliterate('Menus with 🍕 or 🍝');
32+
// => 'Menus with піца or спагеті'
33+
34+
The ``EmojiTransliterator`` class also provides two extra catalogues: ``github``
35+
and ``slack`` that converts any emojis to the corresponding short code in those
36+
platforms::
37+
38+
use Symfony\Component\Intl\Transliterator\EmojiTransliterator;
39+
40+
// describe emojis in Slack short code
41+
$transliterator = EmojiTransliterator::create('slack');
42+
$transliterator->transliterate('Menus with 🥗 or 🧆');
43+
// => 'Menus with :green_salad: or :falafel:'
44+
45+
// describe emojis in Github short code
46+
$transliterator = EmojiTransliterator::create('github');
47+
$transliterator->transliterate('Menus with 🥗 or 🧆');
48+
// => 'Menus with :green_salad: or :falafel:'
49+
50+
The ``EmojiTransliterator`` class also provides an extra catalogues ``strip``
51+
that removes any emojis::
52+
53+
use Symfony\Component\Intl\Transliterator\EmojiTransliterator;
54+
55+
// Strip emojis from the string
56+
$transliterator = EmojiTransliterator::create('strip');
57+
$transliterator->transliterate('Menus with 🥗 or 🧆');
58+
// => 'Menus with or '
59+
60+
.. tip::
61+
62+
Combine this emoji transliterator with the :ref:`Symfony String slugger <string-slugger-emoji>`
63+
to improve the slugs of contents that include emojis (e.g. for URLs).
64+
65+
.. _`Unicode CLDR dataset`: https://github.com/unicode-org/cldr

components/intl.rst

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ This component provides the following ICU data:
3535
* `Locales`_
3636
* `Currencies`_
3737
* `Timezones`_
38-
* `Emoji Transliteration`_
3938

4039
Language and Script Names
4140
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -357,51 +356,6 @@ to catching the exception, you can also check if a given timezone ID is valid::
357356

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

360-
.. _component-intl-emoji-transliteration:
361-
362-
Emoji Transliteration
363-
~~~~~~~~~~~~~~~~~~~~~
364-
365-
.. versionadded:: 6.2
366-
367-
The Emoji transliteration feature was introduced in Symfony 6.2.
368-
369-
The ``EmojiTransliterator`` class provides a utility to translate emojis into
370-
their textual representation in all languages based on the `Unicode CLDR dataset`_::
371-
372-
use Symfony\Component\Intl\Transliterator\EmojiTransliterator;
373-
374-
// describe emojis in English
375-
$transliterator = EmojiTransliterator::create('en');
376-
$transliterator->transliterate('Menus with 🍕 or 🍝');
377-
// => 'Menus with pizza or spaghetti'
378-
379-
// describe emojis in Ukrainian
380-
$transliterator = EmojiTransliterator::create('uk');
381-
$transliterator->transliterate('Menus with 🍕 or 🍝');
382-
// => 'Menus with піца or спагеті'
383-
384-
The ``EmojiTransliterator`` class also provides two extra catalogues: ``github``
385-
and ``slack`` that converts any emojis to the corresponding short code in those
386-
platforms::
387-
388-
use Symfony\Component\Intl\Transliterator\EmojiTransliterator;
389-
390-
// describe emojis in Slack short code
391-
$transliterator = EmojiTransliterator::create('slack');
392-
$transliterator->transliterate('Menus with 🥗 or 🧆');
393-
// => 'Menus with :green_salad: or :falafel:'
394-
395-
// describe emojis in Github short code
396-
$transliterator = EmojiTransliterator::create('github');
397-
$transliterator->transliterate('Menus with 🥗 or 🧆');
398-
// => 'Menus with :green_salad: or :falafel:'
399-
400-
.. tip::
401-
402-
Combine this emoji transliterator with the :ref:`Symfony String slugger <string-slugger-emoji>`
403-
to improve the slugs of contents that include emojis (e.g. for URLs).
404-
405359
Learn more
406360
----------
407361

@@ -424,4 +378,3 @@ Learn more
424378
.. _`daylight saving time (DST)`: https://en.wikipedia.org/wiki/Daylight_saving_time
425379
.. _`ISO 639-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_639-1
426380
.. _`ISO 639-2 alpha-3 (2T)`: https://en.wikipedia.org/wiki/ISO_639-2
427-
.. _`Unicode CLDR dataset`: https://github.com/unicode-org/cldr

0 commit comments

Comments
 (0)