emoji

repository·master·Indexed 24 days ago

https://github.com/carpedm20/emoji

A Python library for converting emoji characters to text codes (demojizing) and text codes to emoji characters (emojizing). It supports the full Unicode emoji set and various language-specific aliases. Key features include functions to replace, count, and analyze emojis in strings, as well as access to comprehensive emoji metadata via the EMOJI_DATA dictionary.

Tokens
6.6K
Snippets
20
Records
53
Agent score
35%

What's inside emoji

  1. View the emoji overview on GitHub Pages

    master

    The hosted HTML website containing all currently supported emojis and names can be found at the official GitHub Pages URL. This site is automatically updated on every release via the updateGithubPages.yml GitHub Action.

    https://carpedm20.github.io/emoji/
  2. How to handle Non-RGI ZWJ emojis

    master

    Non-RGI (Recommended for General Interchange) ZWJ (Zero Width Joiner) emojis, such as multi-person groups with different skin tones, can be handled in two ways during analysis:

    • Joined: Using join_emoji=True (default), the entire sequence is treated as a single EmojiMatchZWJNonRGI token.
    • Split: Using join_emoji=False, the sequence is broken down into its individual constituent emoji tokens.

    Control this behavior via the join_emoji parameter in emoji.analyze() or through the emoji.config module.

  3. Use different languages for emoji conversion

    master

    The emoji package supports multiple languages for both emojize and demojize. When using emojize, the language parameter determines which set of codes is recognized. When using demojize, it determines the language of the resulting codes.

    Supported language codes:

    • Spanish ('es')
    • Portuguese ('pt')
    • Italian ('it')
    • French ('fr')
    • German ('de')
    • Farsi/Persian ('fa')
    • Indonesian ('id')
    • Simplified Chinese ('zh')
    • Japanese ('ja')
    • Korean ('ko')
    • Russian ('ru')
    • Arabic ('ar')
    • Turkish ('tr')
    • English (default, 'en')
    import emoji
    # Spanish
    print(emoji.emojize('Python es :pulgar_hacia_arriba:', language='es'))
    print(emoji.demojize('Python es 👍', language='es'))
    
    # Portuguese
    print(emoji.emojize("Python é :polegar_para_cima:", language='pt'))
    print(emoji.demojize("Python é 👍", language='pt'))
  4. Add a new language to the emoji repository

    master

    To add support for a new language, you must source data from the Unicode CLDR repository or Emojiterra, generate the necessary JSON files, and register the language in the project's core files.

    1. Source Data

    • Unicode CLDR: Check if the language exists in the Unicode CLDR annotations. Use entries with type="tts" to ensure a single, unambiguous translation. For example, <annotation cp="😼" type="tts">gato haciendo una mueca</annotation> results in :gato_haciendo_una_mueca:.
    • Emojiterra: Use Emojiterra for data like country flags. Extract data from the "Copy and Paste" section URL for the specific language (e.g., https://emojiterra.com/es/teclado/).

    2. Generate JSON Files

    Install dependencies and run the generation scripts:

    python -m pip install -r utils/requirements.txt
    python utils/generate_emoji.py
    python utils/generate_emoji_translations.py

    To add the language to the translation script, modify the languages dictionary in utils/generate_emoji_translations.py:

    languages = {
        'es': extract_names(get_language_data_from_url(github_tag, 'es'), 'es', get_emojiterra_from_url('https://emojiterra.com/es/copiar/')),
    }

    3. Register the Language

    You must manually add the new language code to:

    • The LANGUAGES variable in emoji/unicode_codes/data_dict.py.
    • The languages dict in utils/gh-pages/generatePages.py.
  5. Update emoji data to a newer Unicode version

    master

    To update the repository to a newer Unicode version, modify the version parameters in utils/generate_emoji.py:

       emoji_source = get_emoji_from_url(16.0)
        emoji_sequences_source = get_emoji_variation_sequence_from_url('16.0.0')
  6. Build the documentation using Sphinx

    master

    To build the project documentation locally, clone the repository, navigate to the docs directory, install the required dependencies, and use make html.

    git clone https://github.com/carpedm20/emoji.git
    cd emoji/docs
    python -m pip install -r requirements.txt
    make html
  7. Build emoji overview pages locally

    master

    You can generate the HTML website containing all supported emojis and their names on your local machine by installing the necessary dependencies and running the generation script.

    python -m pip install -r utils/gh-pages/requirements.txt
    python utils/gh-pages/generatePages.py
  8. Migrating to version 2.0.0: Non-English short codes

    master

    In version 2.0.0, emoji names in non-English languages have changed due to an update to the Unicode CLDR data (version 41).

    As a result, some :short-code-emoji: strings using non-English names may no longer work. The emojize function will ignore these old, unsupported codes. If you store emoji shortcodes in a database, you may need to update them to match the new naming convention.