All Projects → wiziple → Gatsby Plugin Intl

wiziple / Gatsby Plugin Intl

Licence: mit
Gatsby plugin that turns your website into an internationalization-framework out of the box.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gatsby Plugin Intl

Js Lingui
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript
Stars: ✭ 3,249 (+983%)
Mutual labels:  i18n, localization, intl
Jquery.ime
jQuery based input methods library
Stars: ✭ 145 (-51.67%)
Mutual labels:  i18n, localization, intl
Eo Locale
🌏Internationalize js apps 👔Elegant lightweight library based on Internationalization API
Stars: ✭ 290 (-3.33%)
Mutual labels:  i18n, localization, intl
Formatjs
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Stars: ✭ 12,869 (+4189.67%)
Mutual labels:  i18n, localization, intl
Goloc
A flexible tool for application localization using Google Sheets.
Stars: ✭ 42 (-86%)
Mutual labels:  i18n, localization, intl
Gatsby Starter Prismic I18n
Based on gatsby-starter-prismic with Internationalization (i18n) support
Stars: ✭ 77 (-74.33%)
Mutual labels:  gatsbyjs, i18n, localization
i18n
internationalize projects to Arabic
Stars: ✭ 67 (-77.67%)
Mutual labels:  i18n, localization
inlang
Open Source Localization Solution for Software.
Stars: ✭ 160 (-46.67%)
Mutual labels:  i18n, localization
Tower
i18n & L10n library for Clojure/Script
Stars: ✭ 264 (-12%)
Mutual labels:  i18n, localization
gatsby-simple-blog
an easily configurable gatsby-starter-blog with overreacted looking and tags, breadcrumbs, disqus, i18n, eslint, algolia supported
Stars: ✭ 48 (-84%)
Mutual labels:  i18n, gatsbyjs
mobility-actiontext
Translate Rails Action Text rich text with Mobility.
Stars: ✭ 27 (-91%)
Mutual labels:  i18n, localization
Angular-Gulp-Boilerplate
Clean but full-featured AngularJS boilerplate using Gulp workflow and best practices
Stars: ✭ 30 (-90%)
Mutual labels:  i18n, localization
f3-multilang
Create multilingual apps with this localization plugin for the PHP Fat-Free Framework
Stars: ✭ 44 (-85.33%)
Mutual labels:  i18n, localization
go-locale
GoLang library used to retrieve the current locale(s) of the operating system.
Stars: ✭ 16 (-94.67%)
Mutual labels:  i18n, localization
i18n.cr
Internationalization API ( i18n ) for Crystal!
Stars: ✭ 36 (-88%)
Mutual labels:  i18n, localization
translation
👅 Translations (symfony/translation) to Nette Framework (@nette)
Stars: ✭ 55 (-81.67%)
Mutual labels:  i18n, localization
i18n-tag-schema
Generates a json schema for all i18n tagged template literals in your project
Stars: ✭ 15 (-95%)
Mutual labels:  i18n, localization
plate
Internationalization library for Python
Stars: ✭ 31 (-89.67%)
Mutual labels:  i18n, localization
python-fluent
Python implementation of Project Fluent
Stars: ✭ 142 (-52.67%)
Mutual labels:  i18n, localization
labels
Bolt Labels extension - Translatable labels for Bolt
Stars: ✭ 18 (-94%)
Mutual labels:  i18n, localization

gatsby-plugin-intl

Internationalize your Gatsby site.

Features

  • Turn your gatsby site into an internationalization-framework out of the box powered by react-intl.

  • Support automatic redirection based on the user's preferred language in browser provided by browser-lang.

  • Support multi-language url routes in a single page component. This means you don't have to create separate pages such as pages/en/index.js or pages/ko/index.js.

Why?

When you build multilingual sites, Google recommends using different URLs for each language version of a page rather than using cookies or browser settings to adjust the content language on the page. (read more)

Starters

Demo: http://gatsby-starter-default-intl.netlify.com

Source: https://github.com/wiziple/gatsby-plugin-intl/tree/master/examples/gatsby-starter-default-intl

Showcase

Feel free to send us PR to add your project.

How to use

Install package

npm install --save gatsby-plugin-intl

Add a plugin to your gatsby-config.js

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-plugin-intl`,
    options: {
      // language JSON resource path
      path: `${__dirname}/src/intl`,
      // supported language
      languages: [`en`, `ko`, `de`],
      // language file path
      defaultLanguage: `ko`,
      // option to redirect to `/ko` when connecting `/`
      redirect: true,
    },
  },
]

You'll also need to add language JSON resources to the project.

For example,

language resource file language
src/intl/en.json English
src/intl/ko.json Korean
src/intl/de.json German

Change your components

You can use injectIntl HOC on any react components including page components.

import React from "react"
import { injectIntl, Link, FormattedMessage } from "gatsby-plugin-intl"

const IndexPage = ({ intl }) => {
  return (
    <Layout>
      <SEO
        title={intl.formatMessage({ id: "title" })}
      />
      <Link to="/page-2/">
        {intl.formatMessage({ id: "go_page2" })}
        {/* OR <FormattedMessage id="go_page2" /> */}
      </Link>
    </Layout>
  )
}
export default injectIntl(IndexPage)

Or you can use the new useIntl hook.

import React from "react"
import { useIntl, Link, FormattedMessage } from "gatsby-plugin-intl"

const IndexPage = () => {
  const intl = useIntl()
  return (
    <Layout>
      <SEO
        title={intl.formatMessage({ id: "title" })}
      />
      <Link to="/page-2/">
        {intl.formatMessage({ id: "go_page2" })}
        {/* OR <FormattedMessage id="go_page2" /> */}
      </Link>
    </Layout>
  )
}
export default IndexPage

How It Works

Let's say you have two pages (index.js and page-2.js) in your pages directory. The plugin will create static pages for every language.

file English Korean German Default*
src/pages/index.js /en /ko /de /
src/pages/page-2.js /en/page-2 /ko/page-2 /de/page-2 /page-2

Default Pages and Redirection

If redirect option is true, / or /page-2 will be redirected to the user's preferred language router. e.g) /ko or /ko/page-2. Otherwise, the pages will render defaultLangugage language. You can also specify additional component to be rendered on redirection page by adding redirectComponent option.

Plugin Options

Option Type Description
path string language JSON resource path
languages string[] supported language keys
defaultLanguage string default language when visiting /page instead of ko/page
redirect boolean if the value is true, / or /page-2 will be redirected to the user's preferred language router. e.g) /ko or /ko/page-2. Otherwise, the pages will render defaultLangugage language.
redirectComponent string (optional) additional component file path to be rendered on with a redirection component for SEO.

Components

To make it easy to handle i18n with multi-language url routes, the plugin provides several components.

To use it, simply import it from gatsby-plugin-intl.

Component Type Description
Link component This is a wrapper around @gatsby’s Link component that adds useful enhancements for multi-language routes. All props are passed through to @gatsby’s Link component.
navigate function This is a wrapper around @gatsby’s navigate function that adds useful enhancements for multi-language routes. All options are passed through to @gatsby’s navigate function.
changeLocale function A function that replaces your locale. changeLocale(locale, to = null)
IntlContextConsumer component A context component to get plugin configuration on the component level.
injectIntl component https://github.com/yahoo/react-intl/wiki/API#injection-api
FormattedMessage component https://github.com/yahoo/react-intl/wiki/Components#string-formatting-components
and more... https://github.com/yahoo/react-intl/wiki/Components

License

MIT © Daewoong Moon

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].