Comments (14)
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.
There are many competitive Gatsby Plugins which trying to solve i18n / l10n. And every have some limitations. In this case is no clear way, how to translate slugs.
I'd be also very happy to see this feature implemented!
from gatsby-plugin-intl.
Hello guys ! Thank you for the support.
I am currently trying to make a wrapper that will automatically add the <link rel="alternate" hreflang="lang_code"... >
in every page for SEO purpose.
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 :)
from gatsby-plugin-intl.
Hi guys, some news, so I didn't have time to make a proper implementation of the <link rel="alternate" hreflang="lang_code"... >
but I know how you can make it work for your pages.
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)
from gatsby-plugin-intl.
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.
from gatsby-plugin-intl.
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.js
and you want to be able to use slug on it you need to do this:
en.json
:
{
"pricing": {
"label": "Pricing",
"slug": "pricing"
}
es.json
:
{
"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 pricing.js
):
<Link
to=/pricing
>
Pricing
</Link>
I hope that solve your problem, if I am not clear do not hesitate to ask any other question :)
from gatsby-plugin-intl.
I'd be very happy to see this feature implemented! Thanks @kuus for your suggestion :)
from gatsby-plugin-intl.
Has anyone figured out a working implementation of this feature yet, by any chance?
from gatsby-plugin-intl.
I let you guys check the solution and give me feedback :)
from gatsby-plugin-intl.
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 createPages()
hook with actions.createPage()
in gatsby-node.js
).
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 to
prop of the <Link />
component could handle the default page path (e.g. <Link to="/about" />
) as well as the localized paths (e.g. <Link to="/ueber-uns" />
)
from gatsby-plugin-intl.
I let you guys check the solution and give me feedback :)
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.
from gatsby-plugin-intl.
@Jno21 your code looks pretty well! I'm really excited to have it in my project!
from gatsby-plugin-intl.
I am also looking forward having this in the official plugin!
from gatsby-plugin-intl.
Hi @Jno21 ,
Thanks very much for taking the time to improve this plugin. I tried to use your branch but I could not make it work so far. Could you please tell me if I'm doing something wrong? Thanks in advance.
I installed your branch: yarn add -D git://github.com/Jno21/gatsby-plugin-intl.git#4cac8ce
en.json
looks like this:
{
"header": {
"pricing": {
"label": "Pricing",
"slug": "pricing"
}
}
}
es.json
:
{
"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 id: 'header.pricing
as per your example here
from gatsby-plugin-intl.
@Jno21 it works perfectly <3 thank you very much!
from gatsby-plugin-intl.
Related Issues (20)
- Updated json needs clear cache in order to show changes on the page HOT 2
- Sitemap problems HOT 4
- redirect option creates problems with routers HOT 1
- Getting Error: Cannot find react-intl/locale-data/hk in Safari HOT 1
- Updating locales requires cleaning .cache HOT 2
- Distinguish between default display/redirect language and default messages language
- Is this project abandoned? HOT 8
- Fork and link this repo? HOT 1
- Styling a specific language HOT 1
- gatsby-plugin-intl is not compatible with your gatsby version 3 HOT 2
- How to use with Storybook? HOT 3
- Problem when using gatsby-plugin-transition-link and gatsby-plugin-intl. HOT 1
- Best practice for translate keywords ( react helmet ) & alt image description HOT 1
- ngeLoc
- Load component inside `wrapPageElement` fails HOT 1
- Is this plugin going to be updated to supported gatsby version 4.x.x? HOT 7
- Dynamic translation keys from json are not extracted
- How do I use this together with slices? HOT 1
- Wrong import of @formatjs locale-data
- All locale data included in bundle
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-plugin-intl.