How to read both locale and country consistently using Azure B2C Custom Page with JavaScript?

lbartolic 1 Reputation point

Azure B2C provides a way to define custom page layouts and make use of JavaScript for various reasons. One of these is detecting user's locale and country. Using window.SETTINGS object, we can read a lot of settings exposed by B2C, and one of the objects is locale.

One of our requirements is to be able to detect user's language and country based on the preferences (either by providing ui_locales as the part of the URL or based on the browser's settings). However, we are having issues in getting window.SETTINGS.locale values consistently.
For an example:

  • when ui_locales with the value of it-CH is passed, locale object returns {lang: 'it', country: 'CH'}
  • when ui_locales value is not passed through the URL, but the user has Italian (Switzerland) selected as the preferred locale and country (through the browser settings), then locale object returns {lang: 'it'}

In the second case, even the country is provided and exposed by the browser, B2C does not make it available through window.SETTINGS.locale.

Is there a way to read these settings consistently using one single method so that both lang and country can be retrieved in case those are present either through ui_locales or browser settings?


Azure Active Directory External Identities
No comments
{count} votes