The International(ization) Incident

By Frank M. Taylor

You wait for five minutes. The Project Manager says nothing.

Uhhhhh… hi?

I'll go ahead and get this emergency sprint retrospective started. You worked on a localization ticket last week that you merged to production last Friday without review. I'm sharing the closed request. Walk us through the code.

You inhale deeply

Wwell, uh, we were just.. working on some translations for our shop. And uh... well... I was .. uhh... parsing some locale strings. Sssometimes we identify the language. And sometimes we identify the language and the locale…

Let's just jump to line 83, shall we? Walk us through line-by-line.


getTranslationKey(i18nKey) {
    
}
                        

… this … takes a locale string as an argument and … it determines which translation to get…

Ambassador to Argentina begins swearing

Go on. Line 84?


getTranslationKey(i18nKey) {
  const [part1, part2] = translationKey
    .toLowerCase()
    .split(/(-|_)/);
}
                        

This … uhh… it converts the string to lowercase…

Ambassador to Great Britain clears his voice

… and then it splits the string into an array on either a hyphen or an underscore.

Ambassador to Cyprus makes a phone call. He is not on mute

Continue, please.


getTranslationKey(i18nKey) {
  const [part1, part2] = translationKey
    .toLowerCase()
    .split(/(-|_)/);
    
    return part1;
}

                        

that ... sends the first part of the array out of the function.

Do you know why locale strings have a lowercase and an uppercase part, even though they're separated by a hyphen?

Uh…no?

Ambassador to Argentina takes a phone call. He is not on mute. He begins shouting.

Because there's overlap between locale names and language names. Have you read the ISO 639-1 and 3166 lists?

Uh... that... was that... in the README?

Pouring a margarita

If you bothered to read the links in my Confluence space, you'd know that the the language code for Welsh is CY

Ambassador to Great Britain stares into your soul

Ok?

Ambassadors begin shouting at aides and assistants

Do you think they speak just one language in a country?

Uh…No?

Ambassadors begin shouting at aides and assistants

Cyprus and Argentina, I'm muting you. Use the hand-raise button.

Calmly

Did you know the Welsh migrated to Argentina in the mid 19th century?

No. But that's neat, I guess?

What's the country code for Argentina?

Oh… that'd be AR, right?

So what would the locale string be for Welsh that's spoken in Argentina?

Ummmm. cy-AR I guess?

Jovially

Right-o old chap. Jolly good. Someone ask him another!

Go Ahead, Cyprus.

And can you think of any countries that might use CY?

Oh! Cyprus!

And what languages might we speak here?

…Welsh?

Goddamnit

Sipping drink

It starts with an "AR" and ends in "abic"

Oh. Arabic.

So what's the locale string for Cypriotic Arabic?

Mortified

Oh. Shit. ar-CY

Standing, gesturing at Ambassadors

And that's how a bunch of pro-independence bumper stickers, flags, and truck nuts ended up in a Cyprus nursing home.

Project Manager has lit a cigarrette

And that's why you use the whole goddamn locale string to look up a translation — instead of splitting it into a string and ignoring case.