Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cvzi committed Sep 12, 2024
1 parent 61428a6 commit fc30895
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
19 changes: 16 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,25 @@ EMOJI_DATA
:type: dict
:canonical: emoji.unicode_codes.data_dict.EMOJI_DATA

Contains all emoji as keys and their names, Unicode version and status
Contains all emoji as keys and their names, Unicode version and status.

The data is stored in JSON files: `<https://github.com/carpedm20/emoji/tree/master/emoji/unicode_codes>`_

The names in other languages than English are not loaded by default. They can be loaded with the :func:`config.load_language` function.

.. code-block:: python
EMOJI_DATA = {
'🥇': {
'en' : ':1st_place_medal:',
'status' : emoji.STATUS["fully_qualified"],
'E' : 3
},
...
}
# After config.load_language() to load more languages:
EMOJI_DATA = {
'🥇': {
'en' : ':1st_place_medal:',
Expand All @@ -81,7 +96,6 @@ EMOJI_DATA
...
}
**Source code:** `emoji/unicode_codes/data_dict.py <https://github.com/carpedm20/emoji/raw/master/emoji/unicode_codes/data_dict.py>`_ **(2MB)**
Emoji status
------------
Expand Down Expand Up @@ -136,4 +150,3 @@ the "Data File Comment" column:
:end-before: """
:caption: Unicode/Emoji Version (emoji/unicode_codes/data_dict.py)
:dedent: 2

15 changes: 15 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ Spanish (``'es'``), Portuguese (``'pt'``), Italian (``'it'``), French (``'fr'``)

..
If you want to access the emoji names of a language directly,
you can load the language data and then access it in the :data:`EMOJI_DATA` dict
by using the language code as a key:

.. doctest::

>>> emoji.config.load_language('es')
>>> print(emoji.EMOJI_DATA['👍']['es'])
:pulgar_hacia_arriba:

..
Note: Not all emoji have names in all languages


Extracting emoji
^^^^^^^^^^^^^^^^

Expand Down
16 changes: 11 additions & 5 deletions emoji/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ class config:

@staticmethod
def load_language(language: Union[List[str], str, None] = None):
"""Load one or multiples languages.
"""Load one or multiple languages into memory.
If no language is specified, all languages will be loaded.
This makes language data accessible in the EMOJI_DATA dict,
for example `emoji.EMOJI_DATA['🏄']['fr']` to access a French emoji name.
This makes language data accessible in the :data:`EMOJI_DATA` dict.
For example to access a French emoji name, first load French with
Available languages are listed in emoji.LANGUAGES"""
``emoji.config.load_language('fr')``
and then access it with
``emoji.EMOJI_DATA['🏄']['fr']``
Available languages are listed in :data:`LANGUAGES`"""

languages = (
[language]
Expand Down Expand Up @@ -213,7 +219,7 @@ def analyze(
) -> Iterator[Token]:
"""
Find unicode emoji in a string. Yield each emoji as a named tuple
:class:`Token` ``(chars, EmojiMatch)`` or `:class:`Token` ``(chars, EmojiMatchZWJNonRGI)``.
:class:`Token` ``(chars, EmojiMatch)`` or :class:`Token` ``(chars, EmojiMatchZWJNonRGI)``.
If ``non_emoji`` is True, also yield all other characters as
:class:`Token` ``(char, char)`` .
Expand Down

0 comments on commit fc30895

Please sign in to comment.