mccrodp / gatsby-starter-contentful-i18n Goto Github PK
View Code? Open in Web Editor NEWi18n support and language switcher for Contentful starter repo
Home Page: https://gatsby-starter-contentful-i18n.netlify.com
i18n support and language switcher for Contentful starter repo
Home Page: https://gatsby-starter-contentful-i18n.netlify.com
Include standard commands via npm
and the gatsby
related commands.
gatsby new contentful-i18n https://github.com/mccrodp/gatsby-starter-contentful-i18n
Was wondering if you might have an idea on how to use slugs for the urls instead of the contentful_id. The contentful_id is the common thing between two posts in different languages but the urls are rather ugly and not very SEO friendly. Is there any way to translate the slugs yet keep them "connected" using the contentful_id? I've seen a few approaches in other repos but nothing that really solves it. Mostly it's just having a json file with all the translated paths which may work for a small site but not really for site where content is added frequently.
This repo currently splits the node.id
string in a few locations: gatsby.node.js
and the layouts / templates so that we have a common slug for the paths for both languages:
const commonId = edge.node.id.substr(0, 23)
Eg:
So, until a better / more unique string such as a slug comes up as available, we'll use this.
From Gatsby i18n plugin I've brought over the TemplateWrapper to this repo from here.
Whereas the "Using Contentful" repo uses a React.Component as shown here.
I've used the TemplateWrapper from the i18n plugin as I need to pass those arguments for the i18n strings. There's probably a way I can do this with the Component method?
Also, this method has issue as it's designed to work with the static pages, not dynamic content from a CMS that uses templates, so in that way, our dynamic content: Products and Categories that use templates do not pass the i18n strings, so I need to do a hack for them here: https://github.com/mccrodp/gatsby-contentful-i18n/blob/master/src/layouts/index.js#L21
if (i18nMessages === undefined) {
if (langKey === 'de') {
i18nMessages = messagesDe
} else {
i18nMessages = messagesEn
}
}
I would love to see if it is possible to handle ui-strings translation via contenful as well, and if yes how to do so.
Noticing a strange error exclusively on built/hosted versions that seems to be related to earlier issues with dynamic pages from Contentful -
To reproduce:
Navigate directly to the page in question, i.e.
https://gatsby-starter-contentful-i18n.netlify.com/de/products/c5ksdbwsexy6qegucyaoacs/
The necessary content ("Wählen Sie Ihre Sprache") will display briefly before reverting to "selectLanguage"
The messages are getting appropriately sent to IntlProvider, but children components that have injectIntl wrappers don't seem to be getting the appropriately set locale.
When I select 'de' the content on this page changes. However, when I navigate to a different oage via the link, my language setting isn't persistent, ie I have to select what language I want for every single page.
I should be able to select the language once and have this stay the same for me across teh entire website.
I see that there's an index.de.js
and index.en-US.js
here. The only difference seems to be in the query associated with each file (as was the original).
Just wondering if there was a way to consolidate into one file and minimizing the need to copy/paste across two files.
I have installed with
"gatsby new project https://github.com/mccrodp/gatsby-starter-contentful-i18n.git"
but it runs in to problems:
UNMET PEER DEPENDENCY for:
react@^16.4.2
react-dom@^16.4.2
and warnings:
[email protected] requires a peer of react@^0.14.0 || ^15.0.0 but none was installed.
npm WARN [email protected] requires a peer of react@^16.4.2 but none was installed.
npm WARN [email protected] requires a peer of react-dom@^16.4.2 but none was installed.
npm WARN [email protected] requires a peer of react@^0.14.9 || ^15.0.0 || ^16.0.0 but none was installed.
npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.0 || ^16.0.0 but none was installed.
npm WARN [email protected] requires a peer of react-dom@^0.14.0 || ^15.0.0 || ^16.0.0 but none was installed.
npm WARN [email protected] requires a peer of react@^15.0.0 || ^16.0.0 but none was installed.
npm WARN @reach/[email protected] requires a peer of [email protected] || 16.x || 16.4.0-alpha.0911da3 but none was installed.
npm WARN @reach/[email protected] requires a peer of [email protected] || 16.x || 16.4.0-alpha.0911da3 but none was installed.
npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.0 || ^16.0.0 but none was installed.
npm WARN [email protected] requires a peer of react@>=15.0.0 but none was installed.
npm WARN [email protected] requires a peer of react@^0.13.0 || ^0.14.0 || ^15.0.0 || ^16.0.0 but none was installed.
do we have to install everything one by one? Is there a quick way to solve this?
Thanks for help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.