From 569c4f60c5e7d80d1f6a93cc7f52094bb890120a Mon Sep 17 00:00:00 2001 From: Elinorre Date: Tue, 3 Mar 2020 22:30:55 +0300 Subject: [PATCH] courses localization --- gatsby-node.js | 4 +- src/components/templates/courseTemplate.js | 84 ++++++---- src/pages/content/en/pages/atom.md | 1 + src/pages/content/en/pages/biref.md | 5 +- src/pages/content/en/pages/kotlin.md | 136 ++++++++--------- src/pages/content/en/pages/stat-methods.md | 170 +++++++-------------- src/pages/content/en/pages/subterranean.md | 39 ++--- src/pages/content/ru/pages/atom.md | 1 + src/pages/content/ru/pages/biref.md | 1 + src/pages/content/ru/pages/kotlin.md | 1 + src/pages/content/ru/pages/stat-methods.md | 1 + src/pages/content/ru/pages/subterranean.md | 1 + src/pages/projects/education.js | 2 +- src/styles/main.css | 5 + 14 files changed, 213 insertions(+), 238 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index c8d934c..545451a 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -2,7 +2,7 @@ const path = require('path') exports.createPages = async ({ actions, graphql }) => { const {createPage} = actions; - + const result = await graphql(` { courses: allMarkdownRemark( @@ -46,7 +46,7 @@ exports.createPages = async ({ actions, graphql }) => { courses.forEach(({node}) => { createPage({ path: node.frontmatter.path, - component: courseTemplate + component: courseTemplate, }) }); diff --git a/src/components/templates/courseTemplate.js b/src/components/templates/courseTemplate.js index 6e472d4..9b211ca 100644 --- a/src/components/templates/courseTemplate.js +++ b/src/components/templates/courseTemplate.js @@ -1,29 +1,52 @@ import React from "react" -import { Link, graphql } from "gatsby" +import { graphql } from "gatsby" +import { FormattedMessage, Link, useIntl, injectIntl } from "gatsby-plugin-intl" +import SEO from "../seo" import Layout from "../layout" -export default function Template({data}){ - const {markdownRemark: course} = data; +const Template = (props) => { + const intl = useIntl() + const lang = intl.locale + const course = props.data.course + console.log(course) + let par = 'Физика' - switch (course.frontmatter.parent) { - case 'education': - par = 'Образование'; - break; - case 'math': - par = 'Математика'; - break; - case 'software': - par = 'Программное обеспечение'; - break; - default: - par = 'Физика'; + if (lang == "ru"){ + switch (course.frontmatter.parent) { + case 'education': + par = 'Образование'; + break; + case 'math': + par = 'Математика'; + break; + case 'software': + par = 'Программное обеспечение'; + break; + default: + par = 'Физика'; + }} + else { + switch (course.frontmatter.parent) { + case 'education': + par = 'Education'; + break; + case 'math': + par = 'Maths'; + break; + case 'software': + par = 'Software'; + break; + default: + par = 'Physics'; + } } return( - + +