Coder Social home page Coder Social logo

Comments (14)

mattez avatar mattez commented on May 18, 2024 10

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.

Jno21 avatar Jno21 commented on May 18, 2024 4

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.

Jno21 avatar Jno21 commented on May 18, 2024 2

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.

rekuenkdr avatar rekuenkdr commented on May 18, 2024 1

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.

Jno21 avatar Jno21 commented on May 18, 2024 1

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.

flocbit avatar flocbit commented on May 18, 2024

I'd be very happy to see this feature implemented! Thanks @kuus for your suggestion :)

from gatsby-plugin-intl.

jdahdah avatar jdahdah commented on May 18, 2024

Has anyone figured out a working implementation of this feature yet, by any chance?

from gatsby-plugin-intl.

Jno21 avatar Jno21 commented on May 18, 2024

I let you guys check the solution and give me feedback :)

from gatsby-plugin-intl.

kije avatar kije commented on May 18, 2024

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.

rekuenkdr avatar rekuenkdr commented on May 18, 2024

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.

GenisDiaz avatar GenisDiaz commented on May 18, 2024

@Jno21 your code looks pretty well! I'm really excited to have it in my project!

from gatsby-plugin-intl.

sdegetaus avatar sdegetaus commented on May 18, 2024

I am also looking forward having this in the official plugin!

from gatsby-plugin-intl.

gregoryforel avatar gregoryforel commented on May 18, 2024

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.

adiusz avatar adiusz commented on May 18, 2024

@Jno21 it works perfectly <3 thank you very much!

from gatsby-plugin-intl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.