-
npm i @lingui/babel-preset-react @lingui/react @wapps/gatsby-plugin-lingui
-
npm i -D @lingui/cli
-
Add to
gatsby-config.js
{ resolve: `gatsby-source-filesystem`, options: { path: `${__dirname}/locale`, name: `locale`, }, }, { resolve: "@wapps/gatsby-plugin-lingui", options: { availableLngs: ["en", "de"], fallbackLng: "en", }, },
-
Add
lingui.config.js
to rootmodule.exports = { fallbackLocale: "en", sourceLocale: "en", localeDir: "<rootDir>/locale", srcPathDirs: ["<rootDir>/src/components", "<rootDir>/src/pages"], srcPathIgnorePatterns: ["/node_modules/"], format: "minimal", }
-
Add
.babelrc
to root{ "presets": ["babel-preset-gatsby", "@lingui/babel-preset-react"] }
-
Add tranlations to pages and components with
<Trans>Text to translate</Trans>
-
Add the locales query to your gatsby pages
export const query = graphql` query($lng: String!, $fallbackLng: String!) { locales: allLocale( filter: { lng: { in: [$lng, $fallbackLng] }, ns: { eq: "messages" } } ) { ...LocaleFragment } } `
-
Wrap you components:
export default withLingui()(IndexPage)
-
npm run add-locale en de fr
to add lanuages -
npm run extract
to get the messages files -
Translate the messages files
-
npm start
-
Profit
-
Notifications
You must be signed in to change notification settings - Fork 0
Had problems adding Lingui to a new Gatsby page. Need a .babelrc file and gatsby-source-filesystem to the locales in gatsby-config.js https://github.com/hupe1980/gatsby-i18n/issues/26
License
philschonholzer/gatsby-lingui
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Had problems adding Lingui to a new Gatsby page. Need a .babelrc file and gatsby-source-filesystem to the locales in gatsby-config.js https://github.com/hupe1980/gatsby-i18n/issues/26
Resources
License
Stars
Watchers
Forks
Releases
No releases published