News: 1666424710

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

How I made a Chrome extension for converting Reg articles to UK spelling

(2022/10/22)


Hands On The Register began life in London in 1994 and today has journalists and other staff all over the world, which is to say San Francisco, Sydney, Singapore, Berlin, and beyond.

It used to be that our vultures wrote in their local style: Americans used US spellings, the British relied on UK spellings, the Australians were pretty much in UK-mode, too, and everyone else did what felt natural. If an article was, for instance, written by the US team and published in the UK morning, the spelling would often be changed to British.

As we added more writers and editors around the world, and reached more people globally – now about 40 million unique readers a year – across all sorts of time zones, it became necessary for logistical and professional reasons to agree on just one consistent style for the whole site. After The Register moved from a .co.uk to a .com during the pandemic, we chose American spelling.

[1]

Why? Because it honestly reflects the true global nature of our readership. UK spelling may make us appear UK-only. Yes, we grew from Great Britain, but today we cater for as many enterprise tech folks as we can around the planet. We want our flavor of irreverent, informed technology journalism spread far and wide, so that we can do our bit to challenge vendors, explain what's going on, and bite the hand that feeds IT.

[2]

[3]

The US spelling isn't everyone's cup of tea, though, or at least that's the impression we got upon reading brick-centered notes hurled through our digital windows lately.

As an olive branch that passionate segment of our readership with a preference for the King's English, this vulture decided to create a Chrome browser extension to change the words in published articles from US to UK spellings.

[4]

It's called [5]Spellerizer , because I was going for subtly stupid in the hope of standing apart from the sprawling, unrepentant witlessness that is the internet's new normal. Also, the daft name serves as a reminder that the extension does not work all that well. But hey, it's free.

Translation, even between US and UK spellings, is an art that requires consideration of context. Spellerizer is not that artful; it relies on a brute force search-and-replace algorithm that pays no attention to the words around it. So if it sees "check," it will replace the US spelling with "cheque," even if the appropriate UK spelling in that instance also happens to be "check."

Really, I should have relied on a machine learning model to make more informed spelling changes. But then this wouldn't have been a weekend coding project. Feel free to submit improvements via GitHub.

[6]

My hope in creating Spellerizer is to demonstrate that it's reasonably easy to write a browser extension and to encourage those modestly familiar with JavaScript to try their hand at it.

Of course there are similarly approachable options, such as shell, Perl, or Python scripts to fetch, translate, and spit out pages. But the browser is a particularly important bit of software and is worth customizing if you enjoy writing code.

Spellerizer can be downloaded and installed from the [7]Chrome Web Store or from its [8]GitHub repo . The former is a better option if you want it to persist and receive updates – some people [9]report that Chrome removes manually loaded (unpacked) extensions on browser restart [10]as a security precaution . However, that's not been my experience.

As I haven't had an extension in the Chrome Web Store before, you can expect to see a warning – "This extension is not trusted by Enhanced Safe Browsing." – on the chrome://extensions/ page post-installation. Google [11]explains , "For new developers, it generally takes a few months to become trusted."

[12]Google delays execution of doomed Chrome extensions

[13]Serious surfer? How to browse like a pro on Firefox

[14]Ad blockers struggle under Chrome's new rules

[15]Makers of ad blockers and browser privacy extensions fear the end is near

Spellerizer is not officially endorsed by or supported by The Register and its publisher Situation Publishing which makes no warranty about its fitness or function. As the Chrome Web Store listing says, you probably don't need it. But if you want it, [16]if you really really want it , my editors are okay with the extension's existence for the time being.

Google's [17]Chrome Extension API documentation is a good place to get familiar with the quirks of building a browser extension. Once you have a basic sense of how the major components (the manifest file, the service worker, content scripts, and other extension-related web pages) relate to one another, it's worth installing an extension like [18]Chrome extension source viewer (CRX) to view extension source code from the Chrome Web Store prior to download.

It's possible to view the source code of an extension that's already installed but it takes a bit more effort because you have to know the path to Chrome's extension folder ( chrome://version/ -> [Profile Path field] /extensions ) and then recognize the correct 32-character identifier used for the extension's directory name among others that may be present.

Spellerizer is perhaps more complicated than it needs to be because I chose to implement [19]internationalization – a way to replace visible text strings in the extension with translated text based on the browser's set language. The [20]localize.js script gathers text values from HTML page elements marked with the [21]"data-i18n" attribute and then [22]substitutes translations pulled from the [23]messages.json file.

The extension, written using [24]Manifest v3 , functions by loading the service worker, [25]background.js , and showing [26]onboarding-page.html upon installation. Preliminaries out of the way, it adds a listener function to the Spellerizer icon, which if you followed the instructions and [27]pinned to the browser bar , will be visible without poking around the Extensions popup menu.

The listener function attached to the Spellerizer's vulture icon triggers the [28]content-script.js file, which does the bulk of the work. If clicked while viewing a Register page, it fetches the spelling data file, [29]spelling_data.json (made [30]available by developer Heiswayi Nrird under an MIT license), and iterates through all the [31]DOM nodes – a tree structure used to organize the elements on a web page.

The approach I took was not particularly sophisticated – I have since learned that there's a more concise way to iterate DOM nodes using a [32]Treewalker object – but loops within loops get the job done. The scanWords function (line 20, content-script.js) separates display text associated with DOM nodes into individual words and compares each to every one of the 1700 or so US/UK word pairs. If it finds a match, it swaps the US spelling for the UK one, preserving the case of the original.

If the script finds any words to replace, it will update the extension icon's badge with a number representing swapped word count. The badge disappears when you click to a different browser tab. And if you reload a Register page, any changes made disappear as they're only client-side.

There's also an options page that I added to test persisting data via the local storage API. Accessible via a ctrl-click on the Spellerizer icon, the options menu has a single checkbox labeled "World Peace."

As you might imagine, it has no effect. Enjoy. ®

Get our [33]Tech Resources



[1] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/applications&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2Y1O-N0BN4puznnTrkiT2WgAAANM&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0

[2] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/applications&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Y1O-N0BN4puznnTrkiT2WgAAANM&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[3] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/applications&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33Y1O-N0BN4puznnTrkiT2WgAAANM&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[4] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/applications&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Y1O-N0BN4puznnTrkiT2WgAAANM&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[5] https://chrome.google.com/webstore/detail/spellerizer/pdggjggfjmcbkgpgocbnccmpgfdhoaco

[6] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/applications&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33Y1O-N0BN4puznnTrkiT2WgAAANM&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[7] https://chrome.google.com/webstore/detail/spellerizer/pdggjggfjmcbkgpgocbnccmpgfdhoaco

[8] https://github.com/Dotnaught/Spellerizer

[9] https://groups.google.com/a/chromium.org/g/chromium-extensions/c/eEIdDgK0QRQ

[10] https://blog.chromium.org/2013/11/protecting-windows-users-from-malicious.html

[11] https://support.google.com/chrome_webstore/answer/2664769?visit_id=638019774058983139-1375631149&rd=2#10745467&zippy=%2Cinstall-with-enhanced-safe-browsing

[12] https://www.theregister.com/2022/09/30/google_manifestv3_chrome_extensions/

[13] https://www.theregister.com/2022/09/26/firefox_power_user_guide/

[14] https://www.theregister.com/2022/09/08/ad_blockers_chrome_manifest_v3/

[15] https://www.theregister.com/2022/06/08/google_blocking_privacy_manifest/

[16] https://www.youtube.com/watch?v=gJLIiF15wjQ

[17] https://developer.chrome.com/docs/extensions/mv3/

[18] https://chrome.google.com/webstore/detail/chrome-extension-source-v/jifpbeccnghkjeaalbbjmodiffmgedin?hl=en

[19] https://developer.chrome.com/docs/webstore/i18n/

[20] https://github.com/Dotnaught/Spellerizer/blob/main/src/js/localize.js

[21] https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

[22] https://developer.chrome.com/docs/extensions/reference/i18n/

[23] https://github.com/Dotnaught/Spellerizer/blob/main/src/_locales/en/messages.json

[24] https://www.theregister.com/2022/09/30/google_manifestv3_chrome_extensions/

[25] https://github.com/Dotnaught/Spellerizer/blob/main/src/js/background.js

[26] https://github.com/Dotnaught/Spellerizer/blob/main/src/html/onboarding-page.html

[27] https://www.theregister.com/2020/04/07/chrome_hiding_extensions/

[28] https://github.com/Dotnaught/Spellerizer/blob/main/src/js/content-script.js

[29] https://github.com/Dotnaught/Spellerizer/blob/main/src/data/spelling_data.json

[30] https://github.com/heiswayi/spelling-uk-vs-us

[31] https://developer.mozilla.org/en-US/docs/Web/API/Node

[32] https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker

[33] https://whitepapers.theregister.com/



The King's English

Anonymous Coward

Isn't the King of Bastard Viking Descent?

Re: The King's English

UCAP

That line died out long ago. The current monarchy is largely Germanic/Greek descent with other connections to almost all of the rest of Europe.

Re: The King's English

Anonymous Coward

There's a direct line of descent back through the usurper Henry Tudor of a bastard line of John of Gaunt.

Tams

How does using standard American English make your content more accessible to people? And in return, you abandon your roots.

And your answer is a foist an extension on us?

I'm disappointed, to say the least. But hey, mountains and mole hills and all that.

heyrick

I think the broken corporate logic is that there are about seventy million people who know how to spell words in English, and about three hundred odd million that don't. Therefore they'll make the site broken by design. Rather like HTML and bloody "color" and "center".

Anonymous Coward

Because most people who learn English as a second language learn the American spellings

ThatOne

> And your answer is a foist an extension on us?

It's clearly an issue of wounded pride, like "how dare you not consider us as being the standard one and only English!"... :-p

Joke aside, I have a deeper problem with this: The ability to change anything we don't like on Internet. How long till somebody makes an extension which removes all opposing opinions on the Internet, allowing you to live in you very own little confirmation bubble?... We already live in a time where denying reality seems not only legit, but even normal. There is a term in psychiatry for this.

jake

"How long till somebody makes an extension which removes all opposing opinions on the Internet, allowing you to live in you very own little confirmation bubble?"

Killfiles (AKA bozo filters) have been around forever. Where do you think your spam filter(s) came from?

Not wounded pride.

jake

More like lese-majesty.

That version of the language belongs to the King, after all. Inherited it from his Mum, he did.

*article paid for by Google

xyz

At least measurements are proper Reg. I chequed. :) What's happening with dates?

∞↔ ∘ ∘

b0llchit

Is there an extension for (un)splitting the infinitives?

Re: ∞↔ ∘ ∘

Mike 137

The original argument against split infinitives is interesting (and to some extent questionable). It originated in an assumption by classicists that English is grounded in Latin (as indeed some of it is). Because in Latin an infinitive has no particle (as in to spell), it was argued that the infinitive particle in English is unbreakably coupled to the verb. That is valid if you assume that English grammar should always follow Latin grammar rules.

But it's a very narrow view given the immense variety of languages that have really contributed to English. And indeed enforcing it actually diminishes expressiveness in some cases. For example, "she will do it clearly" does not mean exactly the same as "she clearly will do it" or "clearly she will do it" -- the first expresses the manner in which the action will be done, whereas the second expresses the speaker's level of certainty that the action will be done and the third indicates a level of certainty as who will perform the action.

So there's a very good argument for allowing "split infinitives" in some cases, as there is in general for not being excessively pedantic about linguistic "rules" that reduce the capacity to express fine shades of meaning.

Re: ∞↔ ∘ ∘

Primus Secundus Tertius

To neatly split an infinitive is the hallmark of a confident style.

Re: ∞↔ ∘ ∘

b0llchit

Shouldn't that read: "To boldly split where no man has split before"

Re: ∞↔ ∘ ∘

ThatOne

Please use the splittoon.

Spellerizer?

jake

Damn your ise!

But ta. I'll be sure to cheque into it, if I ever get around to trying Chrome.

Have a beer for your efforts. And another, for the hate comments you're going to be getting from the chronically complaining commentards.

Re: Spellerizer?

heyrick

No use to me (I use Firefox), but I respect the motive and the effort, so....

Re: Spellerizer?

Forget It

If it's a web-extension Addon it should also br portable to Firefox.

Re: Spellerizer?

jake

Presumably you are going to get right on that, in your copious free time.

Anonymous Coward

You developed an excellent news website based on British English, humour and values. American and international visitors came anyway. You must have needed some sop to Americans in order to make the change from co.uk and British spelling, but successful IT journalism clearly wasn't the reason.

Like so many other UK IT institutions, you sold out your roots and the Brits who helped you grow in return for the Yankee dollar. In doing so you threw away what was unique and merged in with all the other US-centric IT publications on the internet.

Icon required

Fruit and Nutcase

brick-centered notes hurled through our digital windows lately.

Brick through window icon please.

Re: Icon required

jake

Seconded.

OffBeatMammal

Why not do server-side substitution when rendering the page - default to UK/US spelling based on IP2geo or user preference?

But some of us prefer the Encheferizer.........

Anonymous Coward

......but you need the Unix utility "lex"......and if you can't find John Hagerman's original script....

====

%{

/* chef.x - convert English on stdin to Mock Swedish on stdout

*

* The WC definition matches any word character, and the NW definition matches

* any non-word character. Two start conditions are maintained: INW (in word)

* and NIW (not in word). The first rule passes TeX commands without change.

*

* HISTORY

*

* Apr 26, 1993; John Hagerman: Added ! and ? to the Bork Bork Bork rule.

*

* Apr 15, 1992; John Hagerman: Created.

*/

static int i_seen = 0;

%}

WC [A-Za-z']

NW [^A-Za-z']

%start INW NIW

%%

\\[^ \n]+ ECHO;

{NW} { BEGIN NIW; i_seen = 0; ECHO; }

[.!?]$ { BEGIN NIW; i_seen = 0;

printf("%c\nBork Bork Bork!",yytext[0]); }

"bork"/{NW} ECHO;

"Bork"/{NW} ECHO;

"an" { BEGIN INW; printf("un"); }

"An" { BEGIN INW; printf("Un"); }

"au" { BEGIN INW; printf("oo"); }

"Au" { BEGIN INW; printf("Oo"); }

"a"/{WC} { BEGIN INW; printf("e"); }

"A"/{WC} { BEGIN INW; printf("E"); }

"en"/{NW} { BEGIN INW; printf("ee"); }

"ew" { BEGIN INW; printf("oo"); }

"e"/{NW} { BEGIN INW; printf("e-a"); }

"e" { BEGIN INW; printf("i"); }

"E" { BEGIN INW; printf("I"); }

"f" { BEGIN INW; printf("ff"); }

"ir" { BEGIN INW; printf("ur"); }

"i" { BEGIN INW; printf(i_seen++ ? "i" : "ee"); }

"ow" { BEGIN INW; printf("oo"); }

"o" { BEGIN INW; printf("oo"); }

"O" { BEGIN INW; printf("Oo"); }

"o" { BEGIN INW; printf("u"); }

"the" { BEGIN INW; printf("zee"); }

"The" { BEGIN INW; printf("Zee"); }

"th"/{NW} { BEGIN INW; printf("t"); }

"tion" { BEGIN INW; printf("shun"); }

"u" { BEGIN INW; printf("oo"); }

"U" { BEGIN INW; printf("Oo"); }

"v" { BEGIN INW; printf("f"); }

"V" { BEGIN INW; printf("F"); }

"w" { BEGIN INW; printf("v"); }

"W" { BEGIN INW; printf("V"); }

. { BEGIN INW; ECHO; }

====

Re: But some of us prefer the Encheferizer.........

jake

There are other variations on the theme, including ValSpeak, Jive, Pig Latin, Porn and a few more.

Most are funny, once, but rather dated by today's standards.

Dan 55

As I understand it, if someone want an international audience you should use UK English, as all non-US English variants use UK English or very similar.

Likewise most of the world uses metric measurements, even in the UK which is hybrid metric measurements are understood by a science and engineering audience.

I think you've thrown the baby out with the bathwater here.

Anonymous Coward

Most English as a second language training teaches American English because its more common.

Lars

Not in Europe I would claim.

jake

"As I understand it, if someone want an international audience you should use UK English"

For the spoken word.

However, like it or not, just as written Arabic drove early science, written Latin (Koin Greek, Aramaic, et al) drove early Christianity, written Deutsch drove later science (etc., I won't continue. You are quite welcome), written American English is the lingua franca of tehintrawebtubes, and of the FOSS world. This isn't a good thing, nor is it a bad thing. All it is is an accident of history.

However, it will change over time. If there is one thing that's a dead cert, it's that language mutates. Much to the deep dismay of all those Internet King's English nazis out there.

And of course, running code trumps all.

Please understand Godwin's Law before invoking it, or I shall laugh at you.

Optional

TheProf

I fort the koala-tea of spelin ad gone dawn a bit an noow eye no wy.

Off cource u shud panda two th' masess. Yur a bizzness an hve too mak a scent or free. Spelin is difucult an jus coz it mackes mi brian hrut dunt meen u shundt pleeze de moist poople.

I luk fword too usin ur Crome extenstion an ope itll mack fings on ur sigth mutch ezier tu unnerstand.

Owed to a Spell Checker (was: Re: Optional)

jake

(AKA "Candidate for a Pullet Surprise")

I have a spelling checker,

It came with my PC.

It plane lee marks four my revue

Miss steaks aye can knot sea.

Eye ran this poem threw it,

Your sure reel glad two no.

Its vary polished in it's weigh.

My checker tolled me sew.

A checker is a bless sing,

It freeze yew lodes of thyme.

It helps me right awl stiles two reed,

And aides me when eye rime.

Each frays come posed up on my screen

Eye trussed too bee a joule.

The checker pours o'er every word

To cheque sum spelling rule.

Bee fore a veiling checker's

Hour spelling mite decline,

And if we're lacks oar have a laps,

We wood bee maid too wine.

Butt now bee cause my spelling

Is checked with such grate flare,

Their are know fault's with in my cite,

Of nun eye am a wear.

Now spelling does knot phase me,

It does knot bring a tier.

My pay purrs awl due glad den

With wrapped word's fare as hear.

To rite with care is quite a feet

Of witch won should bee proud,

And wee mussed dew the best wee can,

Sew flaw's are knot aloud.

Sow ewe can sea why aye dew prays

Such soft wear four pea seas,

And why eye brake in two averse

Buy righting want too pleas.

-Mark Eckman and Jerrold H. Zar, early 1990s

None of my business

Lars

But the American spelling is mostly just a bit simpler.

After all, is the "u" in colour that important and is it not the French "connection" sort of.

Most of the differences are similar, making things easier.

I use an English spell checker as it's the way I was taught the language but to be honest, this will not upset me at all.

But please don't go for the silly formats for dates, English or American.

Lowest common denominator

Winkypop

I guess

German-American pseudo-English.

Primus Secundus Tertius

There are more differences than just the spelling.

Hopefully we will not meet with too many dumb examples of bastard German-American pseudo-English.

Re: German-American pseudo-English.

jake

How very dare you. Pennsylvania Dutch is a perfectly cromulant language.

anthonyhegedus

In other words, British spellings imply a British publication, presumably with some integrity. American spellings imply a generic no-country faceless publication with no ‘bent’ towards any particular country.

You’ve sold out. Game over man, game over!

I have a box of telephone rings under my bed. Whenever I get lonely, I
open it up a little bit, and I get a phone call. One day I dropped the
box all over the floor. The phone wouldn't stop ringing. I had to get
it disconnected. So I got a new phone. I didn't have much money, so I
had to get an irregular. It doesn't have a five. I ran into a friend
of mine on the street the other day. He said why don't you give me a
call. I told him I can't call everybody I want to anymore, my phone
doesn't have a five. He asked how long had it been that way. I said I
didn't know -- my calendar doesn't have any sevens.
-- Steven Wright