Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

British English to American English (and vice versa) Converter

Does anyone know of a library or bit of code that converts British English to American English and vice versa?

I don't imagine there's too many differences (some examples that come to mind are doughnut/donut, colour/color, grey/gray, localised/localized) but it would be nice to be able to provide localised site content.

like image 725
Matt Mitchell Avatar asked Sep 23 '08 07:09

Matt Mitchell


2 Answers

The difference between UK and US English is far greater than just a difference in spelling. There is also the hood/bonnet, sidewalk/pavement, pants/trousers idea.

Guess it depends how far you need to take it.

like image 153
Simon Knights Avatar answered Sep 18 '22 15:09

Simon Knights


I looked forever to find a solution to this, but couldn't find one, so, I wrote my own bit of code for it, using a master list of ~20,000 different spellings that were freely available from the varcon project and the language experts at wordsworldwide:

https://github.com/HoldOffHunger/convert-british-to-american-spellings

Since I had two source lists, I used them each to crosscheck each other, and I found numerous errors and typos (varcon lists "preexistent"'s british equivalent as "preaexistent"). It is possible that I may have accidentally made typos, too, but, since I didn't do any wordsmithing here, I don't believe that to be the case.

Example:

require('AmericanBritishSpellings.php');
$american_british_spellings = new AmericanBritishSpellings();

$text = "Axiomatically ax that door, would you, my neighbour?";
$text = $american_british_spellings->SwapBritishSpellingsForAmericanSpellings(['text'=>$text]);

print($text);   // output: Axiomatically axe that door, would you, my neighbor?
like image 44
HoldOffHunger Avatar answered Sep 18 '22 15:09

HoldOffHunger