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

@jamfury/gatsby-theme-i18n

v0.1.2

Published

Learn more about Gatsby Themes here:\ https://www.gatsbyjs.org/blog/2018-11-11-introducing-gatsby-themes/

Downloads

2

Readme

Gatsby We Themes

Learn more about Gatsby Themes here:
https://www.gatsbyjs.org/blog/2018-11-11-introducing-gatsby-themes/

Getting Started

Create a new gatsby project

> yarn global add gatsby-cli
> gatsby new we-site-i18n
> cd gatsby-site

Install theme

> yarn add @jamfury/gatsby-theme-i18n@next

Update gatsby-config.js file (sample repo):

module.exports = {
  __experimentalThemes: [
    {
      resolve: '@jamfury/gatsby-theme-i18n',
      options: {
        // these options should ideally be in constants somewhere
        // hardcoding here for illustration/usage
        availableLngs: ['en-US', 'de-DE'],
        fallbackLng: 'en-US'
      }
    }
  ],
  ...
}

Create root ./locale folder

> mkdir -p ./locale/en-US && touch ./locale/en-US/messages.json
> mkdir -p ./locale/de-DE && touch ./locale/de-DE/messages.json

Just to see some localized content, let's add the default Gatsby index page copy to our messages files.

Add this to locale/en-US/messages.json

{
  "Hi people": "Hi people",
  "Welcome to your new Gatsby site.": "Welcome to your new Gatsby site.",
  "Now go build something great.": "Now go build something great.",
  "Go to page {{page}}": "Go to page {{page}}"
}

Add this to locale/de-DE/messages.json

These were taken from Google Translate, so may not be very accurate

{
  "Hi people": "hallo Leute",
  "Welcome to your new Gatsby site.": "Willkommen auf Ihrer neuen Gatsby-Site.",
  "Now go build something great.": "Bauen Sie jetzt etwas Großes auf.",
  "Go to page {{page}}": "Gehe zu Seite {{page}}"
}

Note maintaining string files are tedious, and there are ways to automate the process. One such approach can be seen here in this PR from the labs-www project which uses i18next-parser

Update Index Page

Update the generated src/pages/index.js file with the following:

import React from 'react'
import { graphql } from 'gatsby'
import { withI18next } from '@jamfury/gatsby-plugin-i18next'
import { useTranslation } from 'react-i18next'

const IndexPage = () => {
  const { t } = useTranslation()

  return <h1>{t('Index Page!!')}</h1>
}

export default withI18next()(IndexPage)

export const query = graphql`
  query($lng: String) {
    locales: allLocale(filter: { lng: { eq: $lng }, ns: { eq: "messages" } }) {
      ...TranslationFragment
    }
  }
`

Run Gatsby server

> yarn develop

Once the server is up and running, navigate to http://localhost:8000/de-DE and you should see some German copy!

Troubleshooting

error The path passed to gatsby-source-filesystem does not exist on your file > system:

locale

Please pick a path to an existing directory.

The above error means you haven't created the locale folder at the root of your project. See Getting Started instructions above

error Plugin @jamfury/gatsby-plugin-i18next returned an error

SyntaxError: Unexpected end of JSON input

If you see the above error, it usually means that your locale/en-US/messages.json file has invalid JSON. At the very least, it needs {}