{"size": 1678, "ext": "js", "max_stars_repo_path": "src/components/languageSelect.js", "max_stars_repo_name": "nextgentravel/standalone-estimator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/languageSelect.js", "max_issues_repo_name": "nextgentravel/standalone-estimator", "max_issues_repo_issues_event_min_datetime": "2021-02-16T20:11:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T16:21:20.000Z", "max_forks_repo_path": "src/components/languageSelect.js", "max_forks_repo_name": "nextgentravel/standalone-estimator", "max_forks_repo_forks_event_min_datetime": "2022-01-04T04:46:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-04T04:46:30.000Z"}
{"max_stars_count": null, "max_issues_count": 119, "max_forks_count": 1, "avg_line_length": 27.5081967213, "max_line_length": 155, "alphanum_fraction": 0.6466030989}
import React from 'react';
import PropTypes from 'prop-types';
import Link from 'gatsby-link';

import { useIntl } from 'react-intl';

import languages from '../data/languages'
import { globalHistory } from "@reach/router"
import { getLangs, getUrlForLang } from 'ptz-i18n';

import { graphql, useStaticQuery } from 'gatsby'

const SelectLanguage = (props) => {
  const intl = useIntl()
  const url = globalHistory.location.pathname;
  const langKey = intl.locale;
  const { langs } = languages
  const homeLink = `/${langKey}/`
  const langsMenu = getLangs(langs, langKey, getUrlForLang(homeLink, url))

  let locale = `${intl.locale}-ca`;
  const { allPrismicStandaloneestimatorHomepage } = useStaticQuery(graphql`
    {
      allPrismicStandaloneestimatorHomepage {
        nodes {
          data {
            site_other_language_name
          }
          lang
        }
      }
    }
  `)

  let messages = allPrismicStandaloneestimatorHomepage.nodes.find(function(o){ return o.lang === locale }).data;

  const links = langsMenu
    .filter(lang => !lang.selected)
    .map((lang, idx) => {
      return (
        <React.Fragment key={idx}>
          <Link to={lang.link} className="language-link" lang={lang.langKey}>
            <span className="d-none d-sm-block">{messages.site_other_language_name}{' '}</span>
            <abbr title={messages.site_other_language_name} className="d-sm-none language-link mrgn-tp-sm mrgn-bttm-0 text-uppercase">{lang.langKey}</abbr>
          </Link>
        </React.Fragment>
    )});
  

  return (
    <div>
      {links}
    </div>
  );
};

SelectLanguage.propTypes = {
  langs: PropTypes.array
};

export default SelectLanguage;