Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localized site metadata #8890

Closed
sedubois opened this issue Oct 7, 2018 · 5 comments
Closed

Localized site metadata #8890

sedubois opened this issue Oct 7, 2018 · 5 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@sedubois
Copy link
Contributor

sedubois commented Oct 7, 2018

Summary

I would like to populate my GraphQL API with localized site metadata, which would require the ability to pass a variable in the GraphQL query.

Basic example

// gatsby-config.js
const indexNames = { en: "my-algolia-index-en", fr: "my-algolia-index-fr" };

module.exports = {
  siteMetadata: {
    algoliaIndexName: // somehow pass indexNames so that we can then query by locale
  },
}
// in some React component
query($locale: String!) {
  site {
    siteMetadata {
      algoliaIndexName(locale: $locale)
    }
  }
}

or

// in some React component
query($locale: String!) {
  site {
    siteMetadata(locale: $locale) {
      algoliaIndexName
    }
  }
}

Motivation

The various examples using siteMetadata currently don't take localization into account, which makes its use problematic for multilingual webapps. Even the basic properties shown in the doc such as title, siteUrl and description can't be defined there currently as they are all language-dependent.

@NickyMeuleman
Copy link
Contributor

Hi @sedubois 👋,
there is some information in #5069. There's an RFC about this at gatsbyjs/rfcs#3

@sedubois
Copy link
Contributor Author

sedubois commented Oct 7, 2018

Thanks @NickyMeuleman. I haven’t understood how those build-time GraphQL templates would solve the issue. How would I build and query siteMetadata so that it works for all locales?

@kakadiadarpan kakadiadarpan added the type: question or discussion Issue discussing or asking a question about Gatsby label Oct 9, 2018
@sedubois
Copy link
Contributor Author

@kakadiadarpan would you know if the way site metadata is built could be adapted to support GraphQL variables, and what would be the process to make it happen?

@pieh
Copy link
Contributor

pieh commented Oct 10, 2018

You would probably need some other place than gatsby-config for that. Like separate yaml, or json file with something setup like:

[
  {
    "lang": "en",
    "algioliaIndex": "my-algolia-index-en"
  }
]

and using transformer json transformer plugin then you could query that and filter based on "lang" field

@sedubois
Copy link
Contributor Author

Thanks @pieh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants