npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hitsuji_no_shippo/gatsby-plugin-i18n

v0.2.0

Published

Multi language feature for Gatsby

Downloads

2

Readme

gatsby-plugin-i18n

Hi Folks!

Are you trying to build a multi language gatsby website?

We want to help you! Please open an issue for help, suggestions or bugs.

You can use this plugin with react-intl, i18next, or any other i18n library. This plugin do not translate messages, it just creates routes for each language, and you can use different layouts for each language if you want to.

How it works

Name your files with .langKey.js and the url will be /langKey/path/fileName

Examples:

file | url -- | -- src/pages/about.en.js | /en/about src/pages/about/index.en.js | /en/about src/pages/blog/gatsby-i18n.pt.md | /pt/blog/gatsby-i18n

Why?

Google! Google needs different URLs to crawl and render your pages for each language.

Showcase

Websites built with Gatsby i18n:

Starters

Docs

  • gatsby-starter-default-i18n DEMO, features:
    • automatic browser-language detection and redirection
    • integration with react-intl FormattedMessage with translation keys
    • custom layout and pages per language
    • language switcher component   - dev mode with HMR
    • build deployed to Netlify

Packages

Install

  yarn add gatsby-plugin-i18n

How to use

Include the plugin in your gatsby-config.js file.

Simple configuration example:

// Add to gatsby-config.js
plugins: [
  {
      resolve: 'gatsby-plugin-i18n',
      options: {  
        langKeyDefault: 'en',
        useLangKeyLayout: false
      }
    }
]

Blog using markdownRemark configuration example:

// Add to gatsby-config.js
plugins: [
  {
      resolve: 'gatsby-plugin-i18n',
      options: {  
        langKeyDefault: 'en',
        useLangKeyLayout: false,
        lightweightMarkup: {
          language: 'markdownRemark',
          postPage: 'src/templates/blog-post.js',
          query: `
          {
              allMarkdownRemark {
                  edges {
                  node {
                      fields {
                      slug,
                      langKey
                      }
                  }
                  }
              }
          }
          `
        }
      }
    }
]

All Options

  • langKeyDefault: lanKey to use when no lanKey specified.

  • useLangKeyLayout:

    true: use a different layout for each langKey (src/layouts/en.js, src/layouts/pt.js, ...)

    false: use default layout (src/layouts/index.js)

  • markdownRemark:

    Add markdownRemark if you are using gatsby-transformer-remark.

    You can set a postPage component and a query to get the pages.

  • langKeyForNull: lanKey added to page context and graphql when no langKey specified. Default: any.

  • pagesPaths: If you are not using just /src/pages/ folder, you can add an array with the folders your are using:

     plugins:{
       //... other plugins
       resolve: 'gatsby-plugin-i18n',
         options: {  
           //.. other options
           pagesPaths: [ '/my/custom/pages/folder1', /my/custom/pages/folder2/ ]
     }
  • prefixDefault:

    true: add langKey on all pages, including default

    false: omit langKey in url when page lang is the default. Ex: when langKeyDefault is en, blog/first-post.en.md and blog/first-post.pt.md will have the following urls:

    • /blog/first-post
    • /pt/blog/first-post

    Default: true

Finally

Go Gatsby!

Go Open-source!

Good luck folks! Open an issue if you need help.