Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/gatsby-theme-i18n-lingui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-theme-i18n-lingui",
"version": "3.0.0",
"version": "3.1.0",
"main": "index.js",
"author": "LekoArts <lekoarts@gmail.com>",
"description": "A Gatsby theme for providing localization support via Lingui. This theme sets up Lingui's context provider so that you can access your translations on every page. Works best together with gatsby-theme-i18n.",
Expand All @@ -10,11 +10,11 @@
"@lingui/react": "^3.13.0"
},
"peerDependencies": {
"@lingui/core": "^3.8.9",
"@lingui/react": "^3.8.9",
"@lingui/core": "^3.13.0",
"@lingui/react": "^3.13.0",
"gatsby": "^4.0.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"keywords": [
"i18n",
Expand Down
10 changes: 5 additions & 5 deletions packages/gatsby-theme-i18n-react-i18next/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "gatsby-theme-i18n-react-i18next",
"version": "3.0.0",
"version": "3.1.0",
"main": "index.js",
"author": "LekoArts <lekoarts@gmail.com>",
"description": "A Gatsby theme for providing localization support via react-i18next. This theme sets up react-i18next's context provider so that you can access your translations on every page. Works best together with gatsby-theme-i18n.",
"license": "MIT",
"devDependencies": {
"i18next": "^20.6.1",
"i18next": "^21.9.1",
"react-i18next": "^11.14.3"
},
"peerDependencies": {
"gatsby": "^4.0.0",
"i18next": "^20.2.1",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"i18next": "^21.2.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-i18next": "^11.8.12"
},
"keywords": [
Expand Down
48 changes: 36 additions & 12 deletions packages/gatsby-theme-i18n/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ exports.onCreateNode = ({ node, actions }, themeOptions) => {
const { defaultLang } = withDefaults(themeOptions)

if (node.internal.type === `Mdx`) {
const name = path.basename(node.fileAbsolutePath, `.mdx`)
const name = path.basename(
node.fileAbsolutePath ?? node.internal.contentFilePath,
`.mdx`
)

const isDefault = name === `index`

const lang = isDefault ? defaultLang : name.split(`.`)[1]
const lang = isDefault ? defaultLang : name.split(`.`)[1] ?? defaultLang

createNodeField({ node, name: `locale`, value: lang })
createNodeField({ node, name: `isDefault`, value: isDefault })
Expand Down Expand Up @@ -157,22 +160,43 @@ exports.onCreatePage = ({ page, actions }, themeOptions) => {
})

languages.forEach((locale) => {
let theFilePath = page.component

const [template, mdxFile] = page.component.split(`?__contentFilePath=`)

// if the mdxFile path possesses a language, let's strip the language to it
// ex: index.de.mdx ==> index.mdx
if (mdxFile) {
//split the filename in three parts split by the dot.
let [thePath, /* lang */, ext] = mdxFile.split(`.`)
if (ext === `mdx`) { //if there's data in the third part, just keep the first and last part, removing the language
theFilePath = `${thePath}.${ext}`
} else { //if there's no content in the third part, it means that there's no language part. No need to remove the language
theFilePath = mdxFile
}

//if we use a non-default language, and the language file is on the disk, then use it
;[thePath, ext] = theFilePath.split(`.`)
if (ext === `mdx` && locale.code !== defaultLang) {
if (fs.existsSync(`${thePath}.${locale.code}.${ext}`)) {
theFilePath = `${thePath}.${locale.code}.${ext}`
}else{
//nothing to render if file doen't exist
theFilePath=''
}
}

theFilePath = `${template}?__contentFilePath=${theFilePath}`
}

const newPage = {
...page,
path: localizedPath({
defaultLang,
prefixDefault,
locale: locale.code,
path: originalPath,
}),
matchPath: page.matchPath
? localizedPath({
defaultLang,
prefixDefault,
locale: locale.code,
path: page.matchPath,
})
: page.matchPath,
component: theFilePath,
context: {
...page.context,
locale: locale.code,
Expand All @@ -190,7 +214,7 @@ exports.onCreatePage = ({ page, actions }, themeOptions) => {

createPage(newPage)
})

// When prefixDefault is set the default development & production 404 pages
// will be deleted but not re-created in the above `languages.forEach` segment
// Thus we'll re-create them manually here
Expand Down
9 changes: 6 additions & 3 deletions packages/gatsby-theme-i18n/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-theme-i18n",
"version": "3.0.0",
"version": "3.1.0",
"main": "index.js",
"types": "index.d.ts",
"author": "LekoArts <lekoarts@gmail.com>",
Expand All @@ -13,8 +13,8 @@
"peerDependencies": {
"gatsby": "^4.0.0",
"gatsby-plugin-react-helmet": "^5.0.0",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-helmet": "^6.1.0"
},
"keywords": [
Expand All @@ -31,5 +31,8 @@
"homepage": "https://github.com/gatsbyjs/themes/tree/master/packages/gatsby-theme-i18n#readme",
"engines": {
"node": ">=14.15.0"
},
"dependencies": {
"gatsby-cypress": "^2.3.0"
}
}
6 changes: 3 additions & 3 deletions starters/example-i18n/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ module.exports = {
{
resolve: `gatsby-plugin-mdx`,
options: {
defaultLayouts: {
default: require.resolve(`./src/components/layout.js`),
},
// defaultLayouts: {
// default: require.resolve(`./src/components/layout.js`),
// },
},
},
],
Expand Down
5 changes: 4 additions & 1 deletion starters/example-i18n/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
frontmatter {
slug
}
internal {
contentFilePath
}
}
}
}
Expand All @@ -27,7 +30,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
blogPosts.forEach(({ childMdx: node }) => {
createPage({
path: node.frontmatter.slug,
component: blogTemplate,
component: `${blogTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
context: {
slug: node.frontmatter.slug,
},
Expand Down
12 changes: 6 additions & 6 deletions starters/example-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"serve": "gatsby serve"
},
"dependencies": {
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"@mdx-js/mdx": "^2.1.3",
"@mdx-js/react": "^2.1.3",
"gatsby": "^4.3.0",
"gatsby-plugin-create-client-paths": "^4.3.0",
"gatsby-plugin-mdx": "^3.3.0",
"gatsby-plugin-mdx": "^4.1.1",
"gatsby-plugin-react-helmet": "^5.3.0",
"gatsby-source-filesystem": "^4.3.0",
"gatsby-theme-i18n": "^3.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"gatsby-theme-i18n": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0"
}
}
11 changes: 3 additions & 8 deletions starters/example-i18n/src/templates/blog-template.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import * as React from "react"
import { graphql } from "gatsby"
import { MDXRenderer } from "gatsby-plugin-mdx"
import Layout from "../components/layout"
import Seo from "../components/seo"

const BlogTemplate = ({ data, pageContext }) => {
const BlogTemplate = ({ data, pageContext, children }) => {
return (
<Layout>
<Seo title={data.mdx.frontmatter.title} />
<Seo title={data.mdx?.frontmatter?.title} />
<h1>Data</h1>
<div>
{data.mdx ? (
<MDXRenderer>{data.mdx.body}</MDXRenderer>
) : (
<div>This page hasn't been translated yet</div>
)}
{children || <div>This page hasn't been translated yet</div>}
</div>
<h1>Context</h1>
<pre>{JSON.stringify(pageContext, null, 2)}</pre>
Expand Down
6 changes: 3 additions & 3 deletions starters/example-lingui/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ module.exports = {
{
resolve: `gatsby-plugin-mdx`,
options: {
defaultLayouts: {
default: require.resolve(`./src/components/layout.js`),
},
// defaultLayouts: {
// default: require.resolve(`./src/components/layout.js`),
// },
},
},
],
Expand Down
5 changes: 4 additions & 1 deletion starters/example-lingui/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
frontmatter {
slug
}
internal {
contentFilePath
}
}
}
}
Expand All @@ -27,7 +30,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
blogPosts.forEach(({ childMdx: node }) => {
createPage({
path: node.frontmatter.slug,
component: blogTemplate,
component: `${blogTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
context: {
slug: node.frontmatter.slug,
},
Expand Down
14 changes: 7 additions & 7 deletions starters/example-lingui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"dependencies": {
"@lingui/core": "^3.13.0",
"@lingui/react": "^3.13.0",
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"@mdx-js/mdx": "^2.1.3",
"@mdx-js/react": "^2.1.3",
"gatsby": "^4.3.0",
"gatsby-plugin-mdx": "^3.3.0",
"gatsby-plugin-mdx": "^4.1.1",
"gatsby-plugin-react-helmet": "^5.3.0",
"gatsby-source-filesystem": "^4.3.0",
"gatsby-theme-i18n": "^3.0.0",
"gatsby-theme-i18n-lingui": "^3.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"gatsby-theme-i18n": "^3.1.0",
"gatsby-theme-i18n-lingui": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0"
},
"devDependencies": {
Expand Down
15 changes: 6 additions & 9 deletions starters/example-lingui/src/templates/blog-template.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import * as React from "react"
import { graphql } from "gatsby"
import { Trans } from "@lingui/macro"
import { MDXRenderer } from "gatsby-plugin-mdx"
import Layout from "../components/layout"
import Seo from "../components/seo"

const BlogTemplate = ({ data, pageContext }) => {
const BlogTemplate = ({ data, pageContext, children }) => {
return (
<Layout>
<Seo title={data.mdx.frontmatter.title} />
<Seo title={data.mdx?.frontmatter?.title} />
<h1>
<Trans>Data</Trans>
</h1>
<div>
{data.mdx ? (
<MDXRenderer>{data.mdx.body}</MDXRenderer>
) : (
{children || (
<div>
<Trans>This page hasn't been translated yet</Trans>
</div>
Expand All @@ -32,10 +29,10 @@ const BlogTemplate = ({ data, pageContext }) => {
export default BlogTemplate

export const query = graphql`
query($locale: String!, $slug: String!) {
query{
mdx(
fields: { locale: { eq: $locale } }
frontmatter: { slug: { eq: $slug } }
fields: { locale: { eq: "en" } }
frontmatter: { slug: { eq: "first-post" } }
) {
frontmatter {
slug
Expand Down
6 changes: 3 additions & 3 deletions starters/example-react-i18next/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ module.exports = {
{
resolve: `gatsby-plugin-mdx`,
options: {
defaultLayouts: {
default: require.resolve(`./src/components/layout.js`),
},
// defaultLayouts: {
// default: require.resolve(`./src/components/layout.js`),
// },
},
},
],
Expand Down
5 changes: 4 additions & 1 deletion starters/example-react-i18next/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
frontmatter {
slug
}
internal {
contentFilePath
}
}
}
}
Expand All @@ -27,7 +30,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
blogPosts.forEach(({ childMdx: node }) => {
createPage({
path: node.frontmatter.slug,
component: blogTemplate,
component: `${blogTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
context: {
slug: node.frontmatter.slug,
},
Expand Down
14 changes: 7 additions & 7 deletions starters/example-react-i18next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"serve": "gatsby serve"
},
"dependencies": {
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"@mdx-js/mdx": "^2.1.3",
"@mdx-js/react": "^2.1.3",
"gatsby": "^4.3.0",
"gatsby-plugin-mdx": "^3.3.0",
"gatsby-plugin-mdx": "^4.1.1",
"gatsby-plugin-react-helmet": "^5.3.0",
"gatsby-source-filesystem": "^4.3.0",
"gatsby-theme-i18n": "^3.0.0",
"gatsby-theme-i18n-react-i18next": "^3.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"gatsby-theme-i18n": "^3.1.0",
"gatsby-theme-i18n-react-i18next": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0"
}
}
Loading