Skip to content

fix(i18n): better filtering and search for preferred locales#9019

Merged
ematipico merged 2 commits intofeat/i18n-routingfrom
fix/normalized-paths-in-routing
Nov 8, 2023
Merged

fix(i18n): better filtering and search for preferred locales#9019
ematipico merged 2 commits intofeat/i18n-routingfrom
fix/normalized-paths-in-routing

Conversation

@ematipico
Copy link
Copy Markdown
Member

@ematipico ematipico commented Nov 8, 2023

Changes

This PR fixes some edge cases that could happen when looking for the preferred locales.

Since this feature doesn't enforce a restriction on how the locales should be written, this could be a problem when reading the locales coming from the browser. This will become a problem with the four-letter locales, e.g. pt_BR.

The Accept-Language header has a value like this pt-BR, but a user might have their routes and folders like this: src/pages/pt-br/index.astro and example.com/pt-br.

This PR fixes this issue by:

  • normalizing both sources: the locales coming from the browser and the locales coming from the configuration, it use the same function we use for the virtual module
  • returning the locales of the configuration, and not the locale of the browser

Testing

Added a new test case

Docs

N/A

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Nov 8, 2023

⚠️ No Changeset found

Latest commit: f8b68d8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Nov 8, 2023
@matthewp
Copy link
Copy Markdown
Contributor

matthewp commented Nov 8, 2023

Looks like there are some conflicts, can you update?

@ematipico ematipico force-pushed the fix/normalized-paths-in-routing branch from 148264f to f8b68d8 Compare November 8, 2023 13:53
@ematipico
Copy link
Copy Markdown
Member Author

@matthewp that's done

@ematipico ematipico merged commit 3af53cb into feat/i18n-routing Nov 8, 2023
@ematipico ematipico deleted the fix/normalized-paths-in-routing branch November 8, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants