gatsby-plugin-intl icon indicating copy to clipboard operation
gatsby-plugin-intl copied to clipboard

Contentful content.

Open mbappai opened this issue 6 years ago • 8 comments

How does one use this plugin while having all contents stored in a contentful CMS? How will it be possible to query the preferred locale based on the user's language selection?

mbappai avatar Oct 07 '19 10:10 mbappai

One way to use the currently selected language to load content from a CMS is to use injectIntl HOC and read locale (current language) from props.intl.

flocbit avatar Oct 12 '19 09:10 flocbit

One way to use the currently selected language to load content from a CMS is to use injectIntl HOC and read locale (current language) from props.intl.

Thank you very much for your reply. Do you still think the injectIntl HOC is still a thing in the v3 or react-intl?

mbappai avatar Oct 12 '19 09:10 mbappai

gatsby-plugin-intl currently does not support react-intl v3 so for now this is the proposed way I guess ;)

flocbit avatar Oct 12 '19 09:10 flocbit

gatsby-plugin-intl currently does not support react-intl v3 so for now this is the proposed way I guess ;)

Yeah, I understand. I am, however, finding it a bit difficult to think of a way to switch the language based on the props.intl from the injectIntl HOC you suggested. Were you suggesting that I query both locales from my CMS at the same time then have like a condition to switch the locales based on the props.intl? Will that work?

mbappai avatar Oct 12 '19 10:10 mbappai

That depends on the CMS you use. I would try to append the language code to the API call when loading data from your CMS.

flocbit avatar Oct 12 '19 11:10 flocbit

Using contentful, I was thinking about having my query like this.

export const query =graphql`
{
    site {
        siteMetadata {
          languages {
            defaultLangKey
            langs
          }
        }
      }
 chineseSpace:allContentfulWorkspace(filter: {node_locale: {eq: "zh-CN"}}) {
    edges {
      node {
        id
        slug
        price
        duration
        name
        node_locale
        shortDescription {
          shortDescription
        }
        thumbnail{
          fluid{
            ...GatsbyContentfulFluid
        }
        }
      }
    }
  }
  englishSpace:allContentfulWorkspace(filter: {node_locale: {eq: "en-US"}}) {
    edges {
      node {
        id
        slug
        price
        duration
        name
        node_locale
        shortDescription {
          shortDescription
        }
        thumbnail{
          fluid{
            ...GatsbyContentfulFluid
        }
        }
      }
    }
  }
  }`

Then i'll later use a condition like follows

const data= props.intl==='en-US'?englishSpace:chineseSpace;

What do you think about this?

mbappai avatar Oct 12 '19 11:10 mbappai

Hey, @mujeex did you manage to solve your issue with this? I'm facing the same thing at the moment with WordPress.

mikexavier avatar Mar 30 '20 18:03 mikexavier

Hey, @mujeex did you manage to solve your issue with this? I'm facing the same thing at the moment with WordPress.

Hey Mike! Sorry for the late response. Sorry again, but I never managed to finish localizing that project. I just ended up using english, as other languages were not a priority at the time.

mbappai avatar Mar 31 '20 14:03 mbappai