-
Notifications
You must be signed in to change notification settings - Fork 176
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
Allow translation of URLS #33
Comments
I'd be very happy to see this feature implemented! Thanks @kuus for your suggestion :) |
I'm noob in Gatsby world. I don't understand how the entire Gatsby community can live without robust standardized way to localize their webapps. I'd be also very happy to see this feature implemented! |
Has anyone figured out a working implementation of this feature yet, by any chance? |
Any news on this matter? all the SEO marketing from Gatsby means nothing if your URLs look the same in different languages. I hope this feature will be taken into consideration too. |
I let you guys check the solution and give me feedback :) |
It would also be great if there is some way to define the localized urls for dynmically/programatically generated pages (E.g. when creating pages via the This is useful, if you don't have the content of your pages stored as local files (.md, etc...), but generate pages from another data source, for example a cms, that already manages the URLs of the pages. Here a small example how this could look /// gatsby-node.js
// ...
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
query DynamicPages {
someQuery {
pages {
id
urls {
en
de
it
}
}
}
}
`);
result.someQuery.pages.forEach((page) => {
createPage({
path: page.urls.en, // e.g. "/about"
component: path.resolve(`./src/templates/page.jsx`),
context: {
intlLocalizedUrls: {
en: page.urls.en, // e.g. "/about"
de: page.urls.de, // e.g. "/ueber-uns"
it: page.urls.it, // e.g. "/chi-siamo"
}
},
});
});
};
// ... If possible, it would also be great then if the |
Hi @Jno21, I've tested your solution and is working great, apart from the missing trailing slash on the translated url and the few points you already have covered in the to-dos. Thanks. |
@Jno21 your code looks pretty well! I'm really excited to have it in my project! |
I am also looking forward having this in the official plugin! |
Hello guys ! Thank you for the support. I am currently trying to make a wrapper that will automatically add the I did a PoC, outside the plugin that seems to work. I will try to add it directly in the plugin as soon as possible and it will be done :) |
Hi guys, some news, so I didn't have time to make a proper implementation of the Somebody asked if they could use my version directly instead of this plugin (because the PR is not merged), so what I am going to do is to edit the README in my code too to make it easier to explain how to do the alternate link and how to make it work with slugs. (For those interested I also implemented a solution, for this plugin, if you have a CMS that include translated page already, like wordpress) |
Hi @Jno21 , I installed your branch:
{
"header": {
"pricing": {
"label": "Precios",
"slug": "precios"
}
}
} and in my code: <Link
to={`/${intl.formatMessage({
id: 'header.pricing.slug',
})}`}
>
Pricing
</Link> I have also tried with |
Hi ! Thanks for trying my feature @gregoryforel. So the problem come from the implementation behind, I do not support multiple level in json. If your page is
{
"pricing": {
"label": "Pricing",
"slug": "pricing"
}
{
"pricing": {
"label": "Precios",
"slug": "precios"
} In the code you need to let the normal link to the page (for example if your page is name <Link
to=/pricing
>
Pricing
</Link> I hope that solve your problem, if I am not clear do not hesitate to ask any other question :) |
@Jno21 it works perfectly <3 thank you very much! |
Hi @wiziple, thanks for this nice plugin. I was wondering if you plan to add url slug's translations too, which is a feature I haven't seen yet in the various gatsby i18n plugins.
So, to make it more clear, I mean if you plan to allow this:
same page with two different slugs.
I guess is not easy to manage the link routing, but I think it's possible to build a sort of routes map during the
createPages
step and pass it to the pages inside theintl
context. The link component can then use theto
prop as a key that would match this routes map.Some super pseudo code:
in
src/pages/about/index.en.md
in
src/pages/about/index.it.md
Then we would have a routes map in page contexts like:
And the Link component would do
I am curious to see what you think of this approach or if you have any other idea in this regard.
Let me know if all this is a bit unclear!
The text was updated successfully, but these errors were encountered: