Question

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.

Was it helpful?

Solution

I've been working on one to convert US English to UK English. As I've discovered it's actually a lot harder to write something to convert the other way but I hope to get around to providing a reverse conversion one day.

This isn't perfect, but it's not a bad effort (even if I do say so myself). It'll convert most US spellings to UK ones but there are some words where UK English retains the US spelling (e.g. "program" where this refers to computer software). It won't convert words like pants to trousers because my main goal was simply to make the spelling uniform across the whole document.

There are also words such as practice and license where UK English uses either those or practise & licence, depending on whether the word's being used as a verb or a noun. For those two examples the conversion tool will highlight them and an explanatory note pops up on the lower left hand of your screen when you hover your mouse over them. All word patterns which are converted are underlined in red, and the output is shown in a side by side comparison with your original input.

It'll do quite large blocks of text quite quickly, but I prefer to go use it just for a couple of paragraphs at a time - copying them in from a Word doc.

It's still a work in progress so if anyone has any comments or suggestions then I'd appreciate feedback I can use to improve it.

http://www.us2uk.eu/

OTHER TIPS

I think if you're thinking of converting from American English to British English, I personally wouldn't bother. Britain is very Americanised anyway, we accept silly yank spellings on the net :)

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.

I had a similar problem recently. I discovered the following tool, called VarCon. I haven't tested it out, but I needed a rough converter for some text data. Here's an example.

echo "I apologise for my colourful tongue ." | ./translate british american
# >> I apologize for my colorful tongue .

It looks like it works for various dialects. Be sure to read the README and proceed with caution.

*note: This will only correct spelling variations.

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?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top