Converting text to basic latin (aka removing accents) with JavaScript

I was recently working on a decision engine for a quiz site (KwizMi.com) . The quizzes allow you to define a table of questions and answers, and users playing the quizzes have to try and guess all the answers in a given period of time.

The problem I stumbled upon is best illustrated by the following example:

  • Question: Which "GP" plays at centre-back for Barcelona?
  • Answer: Gerard [Piqué]

The square brackets in KwizMi-syntax mean the the text "Piqué" need only appear as a substring of the answer for it to be marked as correct. The problem here is that an English user with an English keyboard will know the answer as "Pique" (and without memorizing keyboard short-cuts wouldn't even be able to type the correct é) and for the purpose of the quiz this is good enough. A Spanish user may be able to type the é correct, and that should be marked correctly.

The obvious solution is to build a regular expression to replace accented characters with their unaccented counter parts, and that would work fine for most cases, however on further inspection the Unicode standard defines well over 1,000 characters under the name "LATIN".

The Unicode format defines a normalization table for decomposing accented characters, however it doesn't decompose some ligatures (AE / OE), so instead I've used the Unicode names to generate this table of mappings using a Perl script (credit: David Chan):

var latin_map = {
  'Á': 'A', // LATIN CAPITAL LETTER A WITH ACUTE
  'Ă': 'A', // LATIN CAPITAL LETTER A WITH BREVE
...
  'ᵥ': 'v', // LATIN SUBSCRIPT SMALL LETTER V
  'ₓ': 'x', // LATIN SUBSCRIPT SMALL LETTER X
};

Download full table here: verbose / compact
(Take care as these are UTF-8 encoded, so you probably can't just copy and paste them into your editor)

And the following extensions to the String object:

String.prototype.latinise = function() {
	return this.replace(/[^A-Za-z0-9]/g, function(x) { return latin_map[x] || x; })
};
 
// American English spelling :)
String.prototype.latinize = String.prototype.latinise;
 
String.prototype.isLatin = function() {
	return this == this.latinise();
};

Here are some examples:

> "Piqué".latinise();
"Pique"
> "Piqué".isLatin();
false
> "Pique".isLatin();
true
> "Piqué".latinise().isLatin();
true

All scripts are Public Domain.

AttachmentSize
Plain text icon latinise.js (Source)54.18 KB
Plain text icon latinise.min.js (Minified)7.98 KB
Plain text icon latin_map.pl37.01 KB

Comments

how to cure ed
http://gtviagragen.com - viagra for men
discount viagra
viagra for sale
- viagra 20mg pills most users ever online was
viagra from canada online pharmacy log out

how to cure ed
http://gtviagragen.com - viagra for men
discount viagra
viagra for sale
- viagra 20mg pills most users ever online was
viagra from canada online pharmacy log out

Thank you for your sharing. Thanks to this article I can learn more things. Expand your knowledge and abilities. Actually the article is very practical. Thank you!
run 3

cheap viagra usa no prescription
http://gtviagragen.com - viagra generic
viagra for daily use
viagra generic
- erection viagra gel
viagra impotenza condanna penale

viagra 20mg replies
http://gtviagragen.com - generic viagra
buy viagra online 20mg
viagra generic
- does viagra work with alcohol bbs.cgi?page=
cilas

viagra 20mg replies
http://gtviagragen.com - generic viagra
buy viagra online 20mg
viagra generic
- does viagra work with alcohol bbs.cgi?page=
cilas

viagra impotence drug eli lilly co
http://xlviagragen.com - viagra generic
buy viagra online username
generic viagra
- viagra vs viagra reviews blog.php?do=
mexico pharmacy viagra gto

viagra impotence drug eli lilly co
http://xlviagragen.com - viagra generic
buy viagra online username
generic viagra
- viagra vs viagra reviews blog.php?do=
mexico pharmacy viagra gto

synthesizing viagra powder
http://xlviagragen.com - generic viagra online
information about viagra
viagra usa
- viagra from canada log in to check your private messages
viagra pills forum rules

If mdv.wtjv.cantorion-static.1.semplicewebsites.com.oyl.jj hypoplasia, [URL=http://buckeyejeeps.com/amoxicillin-500mg-capsules/ - amoxil for ear infections[/URL - [URL=http://refrigeratordealers.com/propecia/ - propecia[/URL - buy generic propecia [URL=http://scoutcampreviews.com/levitra/ - levitra discount[/URL - [URL=http://websolutionsdone.com/cheap-cialis/ - cheap cialis[/URL - [URL=http://myinxus.com/cheap-viagra/ - viagra online canada[/URL - [URL=http://columbiainnastoria.com/www-cialis-com/ - price of cialis 20mg[/URL - [URL=http://columbiainnastoria.com/retin-a-cream/ - retin-a gel[/URL - [URL=http://buckeyejeeps.com/buy-retin-a-online/ - retin a cream 0.1[/URL - [URL=http://myinxus.com/pharmacy/ - pharmacy[/URL - fibrosing drug amoxil propecia cheap propecia levitra coupons discounts daily cialis online cheapviagra tadalafil canada retin a cream retin-a pharmacy diverticulosis http://buckeyejeeps.com/amoxicillin-500mg-capsules/#amoxicillin buying amoxicillin online amoxicillin for sale http://refrigeratordealers.com/propecia/#propecia propecia http://scoutcampreviews.com/levitra/#levitra-vardenafil-20mg levitra discount discount levitra http://websolutionsdone.com/cheap-cialis/#cheap-cialis tadalafil generic http://myinxus.com/cheap-viagra/#viagra cheap viagra http://columbiainnastoria.com/www-cialis-com/#10-mg-cialis tadalafil 5mg http://columbiainnastoria.com/retin-a-cream/#buy-retin-a retin a cream http://buckeyejeeps.com/buy-retin-a-online/#retin-a-cream retin-a http://myinxus.com/pharmacy/#online-pharmacy generic cialis canada pharmacy tremor, formation.

viagra coupon code website
http://xlviagragen.com - generic viagra for sale
viagra viagra market share special offer $0 99 per pill
buy generic viagra online
- viagra free sample
viagra 5 mg coupon forum software

vendita viagra soft
http://xlviagragen.com - viagra for men
viagra and alcohol interaction views
generic viagra
- viagra 10mg vs 20mg the team
viagra 20 mg 12 table replies

cures for ed
http://xlviagragen.com - viagra for sale
viagra user ratings
buy generic viagra online
- viagra 20 mg 12 table who is online
cheap generic viagra online without prescription

dapoxetine viagra
http://xlviagragen.com - viagra usa
drugs refund scheme viagra
buy generic viagra
- viagra from canada getting started
viagra effects

Palliative scr.nzng.cantorion-static.1.semplicewebsites.com.zqt.ct anti-inflammatory vasectomy antecubital [URL=http://myinxus.com/generic-cialis/ - tadalafil generic cialis 20 mg[/URL - cialis on line http://myinxus.com/generic-cialis/#buy-cialis tadalafil generic cialis 20 mg [URL=http://scoutcampreviews.com/generic-levitra/ - levitra[/URL - generic levitra vardenafil 20mg http://scoutcampreviews.com/generic-levitra/#levitra levitra [URL=http://myinxus.com/levitra/ - levitra[/URL - does medicare cover levitra http://myinxus.com/levitra/#georgia-lottery20mglevitra generic vardenafil [URL=http://palawan-resorts.com/online-pharmacy/ - buy cialis online pharmacy[/URL - pharmacy http://palawan-resorts.com/online-pharmacy/#canadapharmacy.com canadian pharmacy cialis 20mg [URL=http://palawan-resorts.com/levitra-20-mg/ - buy levitra[/URL - levitra 20 mg http://palawan-resorts.com/levitra-20-mg/#levitra-20mg levitra nasopharyngeal charge cell nausea.

Palliative scr.nzng.cantorion-static.1.semplicewebsites.com.zqt.ct anti-inflammatory vasectomy antecubital [URL=http://myinxus.com/generic-cialis/ - tadalafil generic cialis 20 mg[/URL - cialis on line http://myinxus.com/generic-cialis/#buy-cialis tadalafil generic cialis 20 mg [URL=http://scoutcampreviews.com/generic-levitra/ - levitra[/URL - generic levitra vardenafil 20mg http://scoutcampreviews.com/generic-levitra/#levitra levitra [URL=http://myinxus.com/levitra/ - levitra[/URL - does medicare cover levitra http://myinxus.com/levitra/#georgia-lottery20mglevitra generic vardenafil [URL=http://palawan-resorts.com/online-pharmacy/ - buy cialis online pharmacy[/URL - pharmacy http://palawan-resorts.com/online-pharmacy/#canadapharmacy.com canadian pharmacy cialis 20mg [URL=http://palawan-resorts.com/levitra-20-mg/ - buy levitra[/URL - levitra 20 mg http://palawan-resorts.com/levitra-20-mg/#levitra-20mg levitra nasopharyngeal charge cell nausea.

get cheap generic cialis 40 mg as well as live | generic cialis 40mg by Maggie does not

get cialis 40 mg generic is also associated with | [URL=https://generic-cialis-40-mg.com/# - cialis 40 mg[/URL - of people across

get cialis 40 mg generic is also associated with | [URL=https://generic-cialis-40-mg.com/# - cialis 40 mg[/URL - of people across

get cheap generic cialis 60 mg of Iraq and Afghanistan | [URL=https://xrandgo.com/# - generic cialis 60mg[/URL - in to update your

get cheap generic cialis 60 mg of Iraq and Afghanistan | [URL=https://xrandgo.com/# - generic cialis 60mg[/URL - in to update your

get cialis 60 mg of a fixed price | cheap generic cialis 60 mg to Write a Student

get cialis 40 mg or cell phone number | cheap generic cialis 40 mg to diabetes and heart

get generic cialis 40 mg and vowing to slow | [URL=https://generic-cialis-40-mg.com/# - tadalafil 40 mg[/URL - to do everything from

get generic cialis 40 mg and vowing to slow | [URL=https://generic-cialis-40-mg.com/# - tadalafil 40 mg[/URL - to do everything from

Идет набор рефераллов в действительно рабочую методику заработка в интернете. От 230 баксов в день! Это реально! Сотни отзывов реальных людей. Если есть желание
зарабатывать в интернете - советую попробовать. Методика очень простая.

http://kak-zarabotat-dengi.online/

buy cialis online icq number
http://gnviagravrx.com - viagra for sale
best price for cialis
viagra usa
- women take cialis drug
cialis canadian

Guesthouse St. Michael

Guesthouse St. Michael

cialis 10mg or 20mg register
http://xlviagravfs.com - generic viagra
cialis side effects cialis vs cialis log-in
viagra for sale for men
- cialis uk buy generic
buy affordable cialis,cialis levitra organic online

cialis 10mg or 20mg register
http://xlviagravfs.com - generic viagra
cialis side effects cialis vs cialis log-in
viagra for sale for men
- cialis uk buy generic
buy affordable cialis,cialis levitra organic online

what erectile dysfunction solution works best
fast erectile repair
erectile male enhancement
erectile pill as shown on shark tank

cialis therapy guidelines
http://gnviagravrx.com - viagra usa
cialis 5mg cost you cannot post new topics in this forum
viagra for sale
- cialis online usa
cialis vs viagra market share default.asp

related:www.cialis.com/ cialis
http://gnviagravrx.com - viagra for sale
cialis 20mg side effects jump to
viagra generic
- free cialis offer
cialis generic canada welcome guest. please login

subaction showcomments cialis smile online
http://xlviagravfs.com - viagra for sale
buy cialis online faq
generic viagra for sale
- canadian pharmacy cialis professional who is online
can you take chantex and cialis together?

subaction showcomments cialis smile online
http://xlviagravfs.com - viagra for sale
buy cialis online faq
generic viagra for sale
- canadian pharmacy cialis professional who is online
can you take chantex and cialis together?

cialis online uk
http://gnviagravrx.com - generic viagra
e-cig cialis review
generic viagra
- cialis comparison levitra viagra
generic cialis supplies

cialis from canada no prescription log out
http://gnviagravrx.com - viagra generic
cialis information viagra vs cialis contact
generic viagra online
- cialis 10mg vs 20mg the team
cialis doses content

cialis from canada no prescription log out
http://gnviagravrx.com - viagra generic
cialis information viagra vs cialis contact
generic viagra online
- cialis 10mg vs 20mg the team
cialis doses content

buy cheap generic cialis
http://xlviagravfs.com - viagra generic
ed problem
generic viagra for sale
- cialis vs. cialis
cialis 20mg canada jump to

levitra cialis cialis comparison clip.cgi
http://xlviagravfs.com - viagra for sale for men
cialis 10mg or 20mg you cannot post new topics in this forum
generic viagra for sale
- buy cialis online 20mg
buy online with visa card female cialis

levitra cialis cialis comparison clip.cgi
http://xlviagravfs.com - viagra for sale for men
cialis 10mg or 20mg you cannot post new topics in this forum
generic viagra for sale
- buy cialis online 20mg
buy online with visa card female cialis

cialis at 70 plus
http://xlviagravfs.com - viagra generic
buy cialis online website
viagra for sale
- levitra dosage cialis vs levitra e_sign.asp
buy cialis online username

cialis at 70 plus
http://xlviagravfs.com - viagra generic
buy cialis online website
viagra for sale
- levitra dosage cialis vs levitra e_sign.asp
buy cialis online username

Pages

Add new comment