Gatsby I18next Sanity.io Starter

A gatsby starter for search-engine friendly, multilanguage websites with i18next and sanity.io

Features

  • 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

🚀 Quick start

  1. 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
  2. Start developing.

    Navigate into your new site’s directory and start it up.

    cd my-starter/
    gatsby develop
  3. 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 edit src/templates/Home.js. Save your changes and the browser will update in real time!

How does it work?

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