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

Add option to disable page creation for each language #9

Closed
jenkin opened this issue Jun 23, 2020 · 4 comments
Closed

Add option to disable page creation for each language #9

jenkin opened this issue Jun 23, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@jenkin
Copy link
Contributor

jenkin commented Jun 23, 2020

I know that "support multi-language url routes in a single page component" is the main feature of this plugin, but if content and paths are managed by an external system (ie. wordpress with wpgraphql and polylang) that feature becomes a problem. For example, if wpgraphql returns a page with original path /en/page-1, gatsby creates multiple pages with /en/en/page-1, /it/en/page-1, and so on.

I made a little change to make optional the creation of localized paths (localizedPaths option), without change the default behavior. In this case, language is extracted from original path with a custom function (languageFromPath option). You can see it here.

Of course, if you want, I can send you a PR.

@jimmyn
Copy link
Member

jimmyn commented Jun 23, 2020

Hi, thanks for the contribution, I will appreciate a PR, but I think your approach is all or nothing. Maybe we can add another option to specify a regex to enable this feature only for some paths.

Imagine the use case where you have a landing page that you want to automatically translate to all available languages, but you also have a blog section that fetches posts from some CRM. I think it would be handy to allow a user to specify

localizedPaths: /^\/([a-z]{2})\/blog/

@jimmyn jimmyn added the enhancement New feature or request label Jun 23, 2020
jenkin pushed a commit to Dataninja/gatsby-plugin-react-i18next that referenced this issue Jun 23, 2020
@jenkin
Copy link
Contributor Author

jenkin commented Jun 23, 2020

Good point, in the latest commit I changed localizedPaths from boolean to regexp and now onCreatePage test for regexp match of path.

@jenkin
Copy link
Contributor Author

jenkin commented Jun 23, 2020

I notice there is also a problem with Link component, it ignores this new option and prepend language to all linked routes, breaking links... 🤔

@jimmyn
Copy link
Member

jimmyn commented Jul 28, 2020

@jenkin this should be solved in the latest release. Check new pages option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants