Transliteration with Typeahead.js

How to deal with special characters when using typeahead.js

Often in real world web applications we have to deal with words or characters that fall outside of the standard latin-based keyboard character set.

For example lets say we wanted our users to search through a list of torrent clients, a list wouldn’t be complete without including µTorrent, but here we have two problems.

  1. Very few people will know how to type µ or have the inclination to look it up.
  2. If they just type torrent, we presume that most torrent clients will have torrent in their name, so this isn’t going to narrow down the search too much.

The solution is to use tokens in our datum, so where as before we might have just had;

{"value": "µTorrent"}

We would now have;

{
  "value" : "µTorrent",
  "tokens": ["µTorrent", "uTorrent"]
}

Which means if our user types in ‘u’, typeahead.js will know to return µTorrent amongst the results.

I hope this post has helped someone, did you know I have written a book on Typeahead?


Recent posts View all

Freelancing

Why we have ads

We run ads on the site, this article talks about how we try and make them not terrible and why we monetise in the first place

Accessibility

Writing accessible hashtags

Write accessible hashtags by camel casing them. Because ThisReadsBetter thanthisdoes.