Class: LocaleAPI

LocaleAPI()

Locale API class with method of fetching user's locale for ibm.com.

Constructor

new LocaleAPI()

Source:

Methods

(static) clearCache()

Clears the cache.

Source:

(static) fetchList(cc, lc, resolve, reject)

Fetches the list data based on cc/lc combination.

Parameters:
Name Type Description
cc string

Country code.

lc string

Language code.

resolve function

Resolves the Promise.

reject function

Rejects the promise.

Source:

(async, static) getLang() → {Promise.<Locale>}

Gets the user's locale.

Deprecated:
  • in favor of LocalAPI.getLocale.
Source:
Returns:

Locale object.

Type
Promise.<Locale>
Example
import { LocaleAPI } from '@carbon/ibmdotcom-services';

function async getLocale() {
   const locale = await LocaleAPI.getLang();
}

(async, static) getLangDisplay(locale) → {Promise.<string>}

This fetches the language display name based on locale.

Parameters:
Name Type Description
locale Locale | boolean

(optional) If not given, uses LocaleAPI.getLocale logic.

Source:
Returns:

Display name of locale/language.

Type
Promise.<string>

(async, static) getList(locale) → {Promise.<any>}

Get the country list of all supported countries and their languages if it is not already stored in session storage.

Parameters:
Name Type Description
locale Locale

Locale object.

Properties
Name Type Description
cc string

Country code.

lc string

Language code.

Source:
Returns:

Promise object.

Type
Promise.<any>
Example
import { LocaleAPI } from '@carbon/ibmdotcom-services';

function async getLocale() {
   const list = await LocaleAPI.getList({ cc: 'us', lc: 'en' });
   return list;
}

(async, static) getLocale() → {Promise.<Locale>}

Gets the user's locale.

Grab the locale from the available information on the page in the following order:

  1. DDO
  2. HTML lang attribute
  3. ipcInfo cookie
  4. Browser (navigator.language)
  5. Default (us-EN)
Source:
Returns:

Locale object.

Type
Promise.<Locale>
Example
import { LocaleAPI } from '@carbon/ibmdotcom-services';

async function getLocale() {
  const locale = await LocaleAPI.getLocale();
  return locale;
}

(static) getSessionCache(key)

Retrieves session cache and checks if cache needs to be refreshed

Parameters:
Name Type Description
key string

Session storage key.

Source:

(static) verifyLocale(cc, lc, list) → {object}

Verify that the cc and lc combo is in the list of supported cc-lc combos.

Parameters:
Name Type Description
cc string

Country code.

lc string

Language code.

list object

Country list.

Source:
Returns:

Object with lc and cc.

Type
object
Example
import { LocaleAPI } from '@carbon/ibmdotcom-services';

async function getLocale() {
  const locale = await LocaleAPI.verifyLocale(cc, lc, data);
  return locale;
}