How to use the rtl-detect.getLangDir function in rtl-detect

To help you get started, we’ve selected a few rtl-detect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github folio-org / stripes-core / src / loginServices.js View on Github external
export function loadTranslations(store, locale, defaultTranslations = {}) {
  const parentLocale = locale.split('-')[0];

  // react-intl provides things like pt-BR.
  // lokalise provides things like pt_BR.
  // so we have to translate '-' to '_' because the translation libraries
  // don't know how to talk to each other. sheesh.
  const region = locale.replace('-', '_');

  // Update dir- and lang-attributes on the HTML element
  // when the locale changes
  document.documentElement.setAttribute('lang', parentLocale);
  document.documentElement.setAttribute('dir', rtlDetect.getLangDir(locale));

  // Set locale for Moment.js (en is not importable as it is not stored separately)
  if (parentLocale === 'en') moment.locale(parentLocale);
  else {
    import(`moment/locale/${parentLocale}`).then(() => {
      moment.locale(parentLocale);
    }).catch(e => {
      // eslint-disable-next-line no-console
      console.error(`Error loading locale ${parentLocale} for Moment.js`, e);
    });
  }

  return import(`react-intl/locale-data/${parentLocale}`)
    .then(intlData => addLocaleData(intlData.default || intlData))
    // fetch the region-specific translations, e.g. pt-BR, if available.
    // fall back to the generic locale, e.g. pt, if not available.

rtl-detect

Library will help you to detect if the locale is right-to-left language.

BSD-3-Clause
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis

Popular rtl-detect functions