A gatsby starter for search-engine friendly, multilanguage websites with i18next and sanity.io
- I18next for snippet translation
- Code-split translation resources by language and namespace
- Sanity.io to create dynamic, translated pages
- Localized URLs (SEO friendly)
- Context-sensitive language switching (keeps current page)
- Alternate-links and language-attributes
- sitemap.xml with language information
- Localized 404 pages
-
Create a Gatsby site.
Use the Gatsby CLI to create a new site, specifying the i18next sanity starter.
# create a new Gatsby site using the default starter gatsby new my-starter https://github.com/johannesspohr/gatsby-starter-i18next-sanity
-
Start developing.
Navigate into your new site’s directory and start it up.
cd my-starter/ gatsby develop
-
Open the source code and start editing!
Your site is now running at
http://localhost:8000
!Note: You'll also see a second link:
http://localhost:8000/___graphql
. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the Gatsby tutorial.Open the
my-starter
directory in your code editor of choice and editsrc/templates/Home.js
. Save your changes and the browser will update in real time!
All page urls are translated, so there are no pages like in other Gatsby projects. All pages are dynamically generated (see gatsby-node.js
) from the templates
folder.
For every page, the language is set in the pageContext
along with the translation resources, so they get bundled in the page data. For every template, the translation namespaces are defined.
The schema generated by sanity.io is extended to provide a translate functions, which allows us to only bundle the translations for one language.
You can find further information in this blog post: https://dev.to/jospohr/proper-i18n-with-gatsby-i18next-and-sanity-io-5g8a