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

with "rewriteDefaultLanguage" the gridsome pages not have locale for page-query #28

Open
sebtiz13 opened this issue Jul 26, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@sebtiz13
Copy link
Contributor

sebtiz13 commented Jul 26, 2020

Describe the bug
All default page of gridsome (create by gridsome before the plugin) not receive context locale in route

To Reproduce
Steps to reproduce the behavior:

  1. Go to '/'
  2. the page-query locale variables is empty

Expected behavior

For example in my index page I want make this query

query blogPosts($locale: String) {
  allBlogPost(filter: { lang: { eq: $locale } }) {
    edges {
      node {
        id
        title
      }
    }
  }
}

but with rewriteDefaultLanguage: false for the urls like / $locale is empty
because gridsome create an managed page and it's exclude in plugin

if (options.path !== '/404' && options.internal.isDynamic === false && options.internal.isManaged === false) {

I think I don't really understand why the managed pages are exclude.

Environment (please complete the following information):

  • OS: [e.g. Linux]
  • NodeJS Version [e.g. v12.16.3]
  • Gridsome Version Version [e.g. 0.7.19 ]
  • Browser [e.g. chrome, firefox, safari]
  • Plugin Version [e.g. 1.5.1]

Plugin configuration

{
  use: 'gridsome-plugin-i18n',
  options: {
    locales: [
      'fr',
      'en',
    ],
    fallbackLocale: 'en', // fallback language
    defaultLocale: 'fr', // default language
    rewriteDefaultLanguage: false,
  },
}
@sebtiz13 sebtiz13 added the bug Something isn't working label Jul 26, 2020
@daaru00
Copy link
Owner

daaru00 commented Jul 26, 2020

Hi @sebtiz13,

I think I don't really understand why the managed pages are exclude.

Seems not currently possible to edit managed pages. That check is preventing this issue: #11 (comment) where template pages stop working.

Still waiting for gridsome/gridsome#1139 that will should add a more stable API to edit pages without the need to recreating it. Currently I have to specifically ignore that type of page in order to make the others work too.

It seems even the pageContext hook is correctly called, the one responsible for the default value of the context.

@sebtiz13
Copy link
Contributor Author

Hi @daaru00.

Ok so if i understand the condition to exclude it's for page generate by source plugin like source-filesystem works ?

Hum in fact i don't really understand what variable are used for graphql, but my filter works on urls "/fr/" and "/en/" but in "/" the query return all data without filtering.

In doubt I have try to remove condition options.internal.isManaged === false and it's work in my case.

@elmsec
Copy link

elmsec commented Mar 23, 2021

For those who needs a workaround, you can use a default value for your $locale in the GraphQL query. Replace the <DEFAULT_VALUE> below with your default locale, like "en":

query($locale: String = "<DEFAULT_VALUE>") {
  notes: allNote(filter: { lang: { eq: $locale } })
  // ....

By the way, after triggering the hot reloading several times (for example, by saving a document in the text editor), the problem unexpectedly disappears and my filtering starts working as it should. If you're unable reproduce, I have a screen recording to show this. (I am using the source-filesystem plugin for my markdown posts and have an index page to filter my posts by the locale).

Last but not least, I can see the "locale" set correctly in the Vue tab all the time. But my graphql query doesn't seem get it correctly. I am new to Gridsome so I may be wrong at some points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants