Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 7549

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T04:52:07+00:00 2024-11-28T04:52:07+00:00

Can you just combine region and language to make a locale?

  • 60k

As I continue to grow my knowledge in internationalization (i18n), I've had the request from internal and external customers to support something strange.

“Hey, can we support the region of “Spain” but avoid taking on translation since translation is costly and requires hiring translators?”

As any developer, I thought “sure, I can do this!”

As it turns out, the more important question is not “can you do it” but “should you do it?”

How I Tried To Solve This

My first attempt to solve this was to look at date-fns since many UI developers use that for formatting. If date-fns had the “en-SA” locale or if it allowed me to pass it anyway, then my journey would be over. Sadly, I quickly found out that their locale support was limited to a pretty small set of countries and it is manually maintained as opposed to taken from a continuously updated source.

So then I started to look for a way to get the most up-to-date locale information. This search brought me to the browser supplied Intl API. Seemed pretty great (at first), except Intl doesn’t allow me to get the formats, which hurts my ability to communicate to the user what they are expected to type into a date input widget. I’ve since submitted this as a feature request, but since support would only come if the ECMAScript spec committee agreed to it and all browsers implement the enhanced spec, it would take a very long time to get a full solution.

After researching it a lot, I finally came to the source of truth, the CLDR. This is actually what the browsers use under the hood with Intl. By using the CLDR data directly, we have an opportunity to:

  • stay continually up-to-date with locales (since new countries/regions form and existing countries/regions change preferences)
  • get access to the formats for each locale’s dates, date/time, etc. so that we can inform screen reader users of the expected string to type (Which again, Intl does not support at this time)
  • get access to the source data so we can finally see if there is data for a locale like “en-SA”

But wait… the CLDR data doesn’t have “en-SA” either! So what should we do?

How Does CLDR Handle Missing Locales

So my immediate finding was: there is no “en-SA” locale, there is only “ar-SA.” In other words, there is Saudi Arabia that speaks Arabic, but no Saudi Arabia that speaks English. This reflects reality. So why would we try to fake “en-SA”?

Let's see what would happen anyway. Luckily, the CLDR Elixir library has a very clear (but less-than-ideal answer):

When validating a locale name, Cldr will attempt to match the requested locale name to a configured locale. Therefore Cldr.Locale.new/1 may return an {:ok, language_tag} tuple even when the locale returned does not exactly match the requested locale name. For example, the following attempts to create a locale matching the non-existent “English as spoken in Spain” local name. Here Cldr will match to the nearest configured locale, which in this case will be “en”.

That one part is so important that it is worth repeating:

the non-existent “English as spoken in Spain” locale name

It doesn't exist.

While I like the clarity of their documentation, I am not pleased with the resolving that happens (i.e. “match to the nearest configured locale, which in this case will be 'en'”). So if you were to pass “en-SA”, you don't get an error, you get an unexpected mutation.

So now that we know that the Elixir library for CLDR will silently resolve our fake “English Saudi Arabia” locale to English, let's see how Intl handles it.

Intl.DateTimeFormat("en-SA").format(new Date()) // '8/11/2023' 
Enter fullscreen mode Exit fullscreen mode

As you can see, it is using English United States standard for date where the month is first. This is NOT how Saudi Arabia prefers dates. They use the d‏/M‏/y pattern as shown in LocalePlanet, which is nearly identical to CLDR in my experience. So Saudi Arabia expects 11/8/2023 and yet if used our “fake locale” approach, we would be accidentally giving them 8/11/2023.

This would not be helpful to the user.

So What Should We Do?

Often the simplest answer is best for the user, and we have a simple answer:

Do not give your user to select a locale that does not exist in the CLDR.

Instead, give them some kind of UX feedback that helps them to find a locale that most closely matches their preferences.

For example, you could even give them a questionnaire.

Which of these number formats looks most normal to you? Which of these date formats look best to you?

Once they click on the radio buttons for that questionnaire, you can give them a list of commonly used locales that utilize those formats. For example, people who like to see months first, often will select “en-GB” for English as it is spoken in Great Britain. By doing this, you've:

  • 🌈 helped your user to get the end result they want
  • 🌈 you didn't have to mislead the user by giving them the false sense that their region/country is supported, which prevents a great many bugs
  • 🌈you didn't have to write a bunch of fancy code just to workaround the problem. This would have led to hacky code.

Ultimately, honesty is the best policy.

codingfrontendjavascriptwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.