DEV Community

Cover image for Browser API's localization: why can't you do this, Chrome?
JavaScript Room
JavaScript Room

Posted on

Browser API's localization: why can't you do this, Chrome?

Hey, devs! I'd like to share an interesting thing I've found, and ask your thoughts about it.

I was playing with Date's toLocaleString() method in order to get a month name translated with the browser's API only. The code looks like this:

const date = new Date();
date.toLocaleString('en-GB', { month: 'long' });

I tested it in my Chrome browser with a few different languages, everything was perfect. The interesting part has appeared when I posted it on Instagram:

I've got a comment from one of my followers trying to apply this technique for getting an Armenian translation of the month name. According to ISO Language Code Table the language code for Armenian language is hy-AM. I've tried that by myself and discovered that it doesn't really work in Chrome browser (you can see it on the head picture). For some reason, it returns M09 (no idea what that means).
But at the same time, it works as expected in Mozilla Firefox:

Alt Text

I've asked Google Chrome team on twitter already:

Let's see if we get any thoughts on this issue from them. Please, feel free to share your ideas too...

Thanks for reading and have an amazing weekend!

Oldest comments (3)

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

It's because Chrome doesn't have data on how to represent dates in Armenian, so it uses a modified short-form ISO 8601 format. If you just specify the locale code and not the formatting options, you'll get back something that looks mostly like a ISO 8601 date and time, but without correct zero padding of fields.

You can see the same behavior with a number of other minority languages, such as Basque ('eu-ES') and Icelandic ('is-IS'), though there are a number where dates get represented in an unmodified US English format as well (such as Divehi ('dv-MV') and Maori ('mi-NZ')).

Collapse
 
room_js profile image
JavaScript Room • Edited

Thank you very much for the explanation! That's sad but good to know. I'm still curious though why Chrome's team made such a decision to include not all the languages? And will the missing languages be included in the future?

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

I'm still curious though why Chrome's team made such a decision to include not all the languages?

Well, to start with there's no point in including all the languages. There are over 7000 natural languages attested throughout the world. Based on data from Ethonlogue (one of the major linguistics authorities), only 21 of those languages are spoken at native or second language proficiency by more than 1% of the world population. In descending order by total speakers: English (wins out over Mandarin because of L2 speakers), Mandarin Chinese, Hindi, Spanish, French, Standard Arabic, Bengali, Russian, Portuguese, Indonesian, Urdu, German, Japanese, Swahili, Marathi, Telugu, Western Punjabi, Wu Chinese, Tamil, Turkish, and Korean. You'll notice that that list of 21 languages, with the exception of Wu Chinese, comprises most of a standard list of supported languages for software that's considered to be very well internationalized. Most of the others you're likely to see on such a list (such as Vietnamese, Thai, Italian or Swedish) are still within 0.1% of the world population in terms of total speakers.

Once you get past a certain point, the language becomes such a minority item that it's not unreasonable to expect people who speak it to be fluent in at least one other language that is spoken by a significantly larger percentage of the world population, and therefore you can realistically assume that they'll be able to use your software in that language instead of their native language. For example, pretty much nobody who speaks Maori these days doesn't also speak at least one other language (usually English) at at least a basic level of proficiency.

And will the missing languages be included in the future?

Probably not would be my guess, at least not unless they suddenly surge in popularity. Armenian is only a little short of that 0.1% mark (roughly 0.087%), but most people who speak the language and would be likely to use Chrome are also diglots or triglots and speak at least one other language that's significantly more widely used (fun fact, a very large percentage of native speakers of Armenian aren't actually in Armenia), so it's not likely to get picked up. Basque (the next most spoken out of the other languages I listed in my first post) is even worse off at less than even 0.0001% with pretty much everybody who speaks the language also speaking either Spanish or French with at least second-language fluency, so it's even less likely that it will be included.