Project

emojivert

0.0
No commit activity in last 3 years
No release in over 3 years
Translate emoji from one encoding to another.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

Emojivert

This is a tool to translate Emoji Unicode codepoints from one encoding to another.

Why?

Emoji can be encoded in several ways:

  • Unified
  • DoCoMo
  • KDDI
  • SoftBank
  • Google

This utility lets you convert from one to the other.

I personally ran into this issue because Facebook uses the Google encoding in their Graph API. To get them to show up properly on OS X/iOS, you need to convert them to unified Unicode.

Usage

The methods you'll need for translation are of the form:

Emojivert.FROMENCODING_to_TOENCODING(string)

Conversions are available from the four private use to unified Unicode (and vice versa):

  • docomo_to_unified and unified_to_docomo
  • kddi_to_unified and unified_to_kddi
  • softbank_to_unified and unified_to_softbank
  • google_to_unified and unified_to_google

In addition there is an "encoding" for HTML. It creates HTML classes for use with CSS/Images (not supplied, see caveat)

  • unified_to_html and html_to_unified

There are also methods for getting the Unicode name from a Unified code point and vice versa.

  • unified_to_name and name_to_unified

The following shows the basic usage, starting with JSON as an example.

json = '"All work and no play, makes \ud83d\ude0e\ a dull boy \udbba\udf59."'
=> "\"All work and no play, makes \\ud83d\\ude0e\\ a dull boy \\udbba\\udf59.\""

str = ActiveSupport::JSON.decode(json)
=> "All work and no play, makes 😎 a dull boy σΎ­™."

Emojivert.google_to_unified(str)
=> "All work and no play, makes 😎 a dull boy πŸ’€."

Working with Unicode names:

Emojivert.name_to_unified('PILE OF POO')
=> "πŸ’©"
Emojivert.unified_to_name("πŸ’©")
=> "PILE OF POO"

Caveats

I used the mappings from the rails-emoji project and I didn't check them. The standards may change (or might have already). I personally have only used the google_to_unified translation, your mileage may vary on the rest.

There are methods to convert to an HTML representation of emoji for use with CSS and image sprites. I've included the methods, but not the CSS / images necessary to make use of them. Again, check out the rails-emoji project if you to pursue this. There are several other emoji libraries that may be useful for rendering emoji with images, see the list below.

Installation

Add this line to your application's Gemfile:

gem 'emojivert'

And then execute:

$ bundle

Or install it yourself as:

$ gem install emojivert

Credits

The hard work was already done by Uken and the rails-emoji. I simply converted it from an engine to a gem.

Other Emoji Projects

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request