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

Map language in URL to locale #108

Closed
audunru opened this issue Apr 6, 2020 · 6 comments
Closed

Map language in URL to locale #108

audunru opened this issue Apr 6, 2020 · 6 comments

Comments

@audunru
Copy link

audunru commented Apr 6, 2020

Ran into an issue where we want to use a different path segment in the URL than what the actual locale is. This results in complaints in the browser console about missing locale data.

I'm wondering if this needs to be solved in the config.

Current config:

    {
      resolve: `gatsby-plugin-intl`,
      options: {
        path: `${__dirname}/../shared/src/lang`,
        languages: ['en', 'no'],
        defaultLanguage: 'no'
      }
    },

Proposal where a language can be an object, with the underlying locale name set to "nb" to fix any Intl locale data errors, but use the URL-friendly "no" in the visible URL.

    {
      resolve: `gatsby-plugin-intl`,
      options: {
        path: `${__dirname}/../shared/src/lang`,
        languages: ['en', { locale: 'nb', prefix: 'no' }],
        defaultLanguage: 'no'
      }
    },

This would, I believe, also allow you to to have URLs like /english/some/page but still use one of the available English locales.

Happy to submit a PR if this is of interest.

EDIT: Updated suggestion to use "prefix" as the option for what to use in the URL instead of my original suggestion of "path"

@snaegeli
Copy link

We would also be very interested in this. We would like to have /de/ as URL prefix and de-CH as locale for correct formatting of numbers and dates.

@audunru
Copy link
Author

audunru commented Jul 11, 2020

I've started to work on this.

@smaniotto
Copy link

Hey @audunru! Any success with this effort? We're having a similar problem with the pt<>br version of our site. Happy to help with what you've started.

@audunru
Copy link
Author

audunru commented Sep 15, 2020

I got it working pretty quickly, then I started working on adding some tests to the existing code to make sure I didn't break anything. I'll see if I can find some time soon to wrap it up!

@smaniotto
Copy link

Ah great, I'm using a fork for the time being, with a quick solution that complies with the options format you've suggested ({ locale: 'pt', prefix: 'br' }). But would prefer a more proper/tested solution hehe. Thanks, man!

In case somebody needs: https://github.com/smaniotto/gatsby-plugin-intl/tree/prefixes

@audunru
Copy link
Author

audunru commented Nov 27, 2020

I've opened up a pull request for this now.

@audunru audunru closed this as completed Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants