Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
Browse files Browse the repository at this point in the history
…sync-6e79d088
  • Loading branch information
reactjs-translation-bot committed May 31, 2019
2 parents 7e98cd1 + 6e79d08 commit 03784ae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/components/TitleAndMetaTags/TitleAndMetaTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import Helmet from 'react-helmet';
import React from 'react';
import {urlRoot} from 'site-constants';
// $FlowFixMe This is a valid path
import languages from '../../../content/languages.yml';

const defaultDescription = 'A JavaScript library for building user interfaces';

Expand All @@ -16,6 +19,32 @@ type Props = {
canonicalUrl: string,
};

// only provide alternate links to pages in languages where 95-100% of core content has been translated
// which is determined by status enum of 2
const completeLanguages = languages.filter(language => {
return language.status == 2;
});

const alternatePages = canonicalUrl => {
return completeLanguages.map(language => (
<link
key={('alt-', language.code)}
rel="alternate"
hreflang={language.code}
href={canonicalUrl.replace(
urlRoot,
`https://${
language.code === 'en' ? '' : `${language.code}.`
}reactjs.org`,
)}
/>
));
};

const defaultPage = canonicalUrl => {
return canonicalUrl.replace(urlRoot, 'https://reactjs.org');
};

const TitleAndMetaTags = ({title, ogDescription, canonicalUrl}: Props) => {
return (
<Helmet title={title}>
Expand All @@ -29,6 +58,14 @@ const TitleAndMetaTags = ({title, ogDescription, canonicalUrl}: Props) => {
/>
<meta property="fb:app_id" content="623268441017527" />
{canonicalUrl && <link rel="canonical" href={canonicalUrl} />}
{canonicalUrl && (
<link
rel="alternate"
href={defaultPage(canonicalUrl)}
hreflang="x-default"
/>
)}
{canonicalUrl && alternatePages(canonicalUrl)}
</Helmet>
);
};
Expand Down
6 changes: 5 additions & 1 deletion src/pages/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ const Language = ({code, name, status, translatedName}) => {
}}>
{status === 0 && translatedName}
{status > 0 && (
<a href={`https://${prefix}reactjs.org/`} rel="nofollow">
<a
href={`https://${prefix}reactjs.org/`}
rel="nofollow"
lang={code}
hrefLang={code}>
{translatedName}
</a>
)}
Expand Down

0 comments on commit 03784ae

Please sign in to comment.