How to use locales-detector - 3 common examples

To help you get started, we’ve selected a few locales-detector 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 linkerd / linkerd2 / web / app / js / index.js View on Github external
let defaultNamespace = 'default';
const pathArray = window.location.pathname.split('/');

// if the current URL path specifies a namespace, this should become the
// defaultNamespace
if (pathArray[0] === '' && pathArray[1] === 'namespaces' && pathArray[2]) {
  defaultNamespace = pathArray[2];
// if the current URL path is a legacy path such as `/daemonsets`, the
// defaultNamespace should be "_all", unless the path is `/namespaces`
} else if (pathArray.length === 2 && pathArray[1] !== '' && pathArray[1] !== 'namespaces') {
  defaultNamespace = '_all';
}

const detectedLocales = new LocaleResolver(
  [new DETECTORS.NavigatorDetector()],
  [new TRANSFORMERS.FallbacksTransformer()],
).getLocales();
const catalogOptions = { en: catalogEn, es: catalogEs };
const selectedLocale =
    _find(detectedLocales, l => !_isEmpty(catalogOptions[l])) || 'en';
const selectedCatalog = catalogOptions[selectedLocale] || catalogEn;

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      ...appData,
    };

    this.state.api = ApiHelpers(pathPrefix);
github linkerd / linkerd2 / web / app / js / index.js View on Github external
}

let defaultNamespace = 'default';
const pathArray = window.location.pathname.split('/');

// if the current URL path specifies a namespace, this should become the
// defaultNamespace
if (pathArray[0] === '' && pathArray[1] === 'namespaces' && pathArray[2]) {
  defaultNamespace = pathArray[2];
// if the current URL path is a legacy path such as `/daemonsets`, the
// defaultNamespace should be "_all", unless the path is `/namespaces`
} else if (pathArray.length === 2 && pathArray[1] !== '' && pathArray[1] !== 'namespaces') {
  defaultNamespace = '_all';
}

const detectedLocales = new LocaleResolver(
  [new DETECTORS.NavigatorDetector()],
  [new TRANSFORMERS.FallbacksTransformer()],
).getLocales();
const catalogOptions = { en: catalogEn, es: catalogEs };
const selectedLocale =
    _find(detectedLocales, l => !_isEmpty(catalogOptions[l])) || 'en';
const selectedCatalog = catalogOptions[selectedLocale] || catalogEn;

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      ...appData,
    };
github linkerd / linkerd2 / web / app / js / index.js View on Github external
let defaultNamespace = 'default';
const pathArray = window.location.pathname.split('/');

// if the current URL path specifies a namespace, this should become the
// defaultNamespace
if (pathArray[0] === '' && pathArray[1] === 'namespaces' && pathArray[2]) {
  defaultNamespace = pathArray[2];
// if the current URL path is a legacy path such as `/daemonsets`, the
// defaultNamespace should be "_all", unless the path is `/namespaces`
} else if (pathArray.length === 2 && pathArray[1] !== '' && pathArray[1] !== 'namespaces') {
  defaultNamespace = '_all';
}

const detectedLocales = new LocaleResolver(
  [new DETECTORS.NavigatorDetector()],
  [new TRANSFORMERS.FallbacksTransformer()],
).getLocales();
const catalogOptions = { en: catalogEn, es: catalogEs };
const selectedLocale =
    _find(detectedLocales, l => !_isEmpty(catalogOptions[l])) || 'en';
const selectedCatalog = catalogOptions[selectedLocale] || catalogEn;

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      ...appData,
    };

    this.state.api = ApiHelpers(pathPrefix);
    this.state.pathPrefix = pathPrefix;

locales-detector

Tool for detecting locales of visitors and transform them.

Apache-2.0
Latest version published 4 years ago

Package Health Score

42 / 100
Full package analysis