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

feat(i18n): add Astro.currentLocale #9101

Merged
merged 4 commits into from
Nov 16, 2023
Merged

feat(i18n): add Astro.currentLocale #9101

merged 4 commits into from
Nov 16, 2023

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Nov 14, 2023

Changes

RFC change: withastro/roadmap@f934880

This PR adds a new Astro.currentLocale, which is computed from Request#url, i18n.locales, i18n.routingStrategy and i18n.defaultLocale

If the routing strategy is prefix-other-locales, for any URL that doesn't contain a locale, we return the defaultLocale.

This PR adds a bunch of data that we pass down the rendering of the page/endpoint, very similar to the same work I did when implementing preferredLocale.

Closes PLT-1207

Testing

I added new test cases that should cover new use cases.

Docs

withastro/docs#5410

/cc @withastro/maintainers-docs for feedback!

Copy link

changeset-bot bot commented Nov 14, 2023

🦋 Changeset detected

Latest commit: c56b5d9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Nov 14, 2023
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM! Excited to see this API added!

packages/astro/src/core/endpoint/index.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,5 @@
---
'astro': patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also checking that this is a patch, so only waiting for the feature to merge but not for the next minor release? If so, please help me remember when the corresponding docs PR should merge, since it's not on the normal release schedule! 😄 withastro/docs#5410

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the PR is merged, this new thing will go out in the next release (regardless of its entity).

remember when the corresponding docs PR should merge

Ideally, we should merge it before the next release. Although we don't have a schedule for that, I think it's also okay if the docs PR is released 1/2 day after.

@ematipico ematipico merged commit e3dce21 into main Nov 16, 2023
14 checks passed
@ematipico ematipico deleted the feat/current-locale branch November 16, 2023 14:54
@astrobot-houston astrobot-houston mentioned this pull request Nov 16, 2023
peng added a commit to peng/astro that referenced this pull request Nov 17, 2023
* main:
  feat(i18n): add `Astro.currentLocale` (withastro#9101)
  [ci] release (withastro#9107)
  Add compatibility with cloudflare node (withastro#8925)
  [ci] format
  Cancel response stream when connection closes (withastro#9071)
  [ci] format
  feat(i18n): apply specific routing logic only to pages (withastro#9091)
  feat(dev-overlay): Hide plugins into a separate menu when there's too many enabled (withastro#9102)
  [ci] format
  Support Svelte 5 (experimental) (withastro#9098)
  [ci] release (withastro#9078)
  [ci] format
  Refactor shikiji syntax highlighting code (withastro#9083)
  [ci] format
  fix: Query params trigger the trailingSlash error in preview mode (withastro#9045)
  fix(assets): bundling regression for specific config on non-Node runtimes (withastro#9087)
FredKSchott pushed a commit that referenced this pull request Nov 18, 2023
natemoo-re pushed a commit that referenced this pull request Nov 22, 2023
ArmandPhilippot added a commit to ArmandPhilippot/astro-docs that referenced this pull request Jul 29, 2024
* See withastro/astro#4986 for `site`, `generator`, `url`, `clientAddress`, `props` and `redirect`
* See withastro/astro#6721 for `locals`
* See withastro/astro#9021 for `preferredLocale` and `preferredLocaleList`
* See withastro/astro#9101 for `currentLocale`
ArmandPhilippot added a commit to ArmandPhilippot/astro-docs that referenced this pull request Jul 29, 2024
* See withastro/astro#4986 for `site`, `generator`, `url`, `clientAddress`, `props` and `redirect`
* See withastro/astro#6721 for `locals`
* See withastro/astro#9021 for `preferredLocale` and `preferredLocaleList`
* See withastro/astro#9101 for `currentLocale`
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) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants