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): refined locales #9200

Merged
merged 16 commits into from
Nov 30, 2023
Merged

feat(i18n): refined locales #9200

merged 16 commits into from
Nov 30, 2023

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Nov 27, 2023

Changes

Relevant RFC change: withastro/roadmap@dc277b5

This PR adds a new way to configure locales. This new configuration allows users to map certain codes to a "path" that is more user-friendly.

Example:

// astro.config.mjs
import {defineConfig} from "astro/config"
export default defineConfig({
    i18n: {
        defaultLocale: 'en',
        locales: ['en', 'es', 'fr', {
            path: "portugues",
            codes: ["pt", "pt-BR", "pt-AO"]
        }]
    }
})

With this configuration, the user will have /portugues/ in their URLs, and a folder named portugues/. However, when leveraging the SSR Accept-Language header, Astro will use the codes when asking for Astro.preferredLocale.

Testing

I added various cases to handle this new configuration, let me know if there are other cases to handle.

Docs

/cc @withastro/maintainers-docs for feedback!

Copy link

changeset-bot bot commented Nov 27, 2023

🦋 Changeset detected

Latest commit: 89239a3

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 27, 2023
@ematipico ematipico force-pushed the feat/granular-locales branch from dab8bef to 098a676 Compare November 28, 2023 20:48
@ematipico ematipico marked this pull request as ready for review November 28, 2023 20:49
@github-actions github-actions bot added the semver: minor Change triggers a `minor` release label Nov 28, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Copy link
Member

@martrapp martrapp left a comment

Choose a reason for hiding this comment

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

Otherwise looks good to me!

Comment on lines 592 to 595
// const fallbackFromLocale = getPathByLocale(_fallbackFromLocale, i18n.locales);
// if (!fallbackFromLocale) {
// continue;
// }
Copy link
Member

Choose a reason for hiding this comment

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

Were these left in on purpose?

Copy link
Member

@MoustaphaDev MoustaphaDev left a comment

Choose a reason for hiding this comment

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

Looks good to me overall, I just have a few minor suggestions, and questions.

packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/astro/src/i18n/middleware.ts Outdated Show resolved Hide resolved
.changeset/fluffy-dolls-sleep.md Outdated Show resolved Hide resolved
.changeset/fluffy-dolls-sleep.md Outdated Show resolved Hide resolved
packages/astro/src/core/routing/manifest/create.ts Outdated Show resolved Hide resolved
packages/astro/src/core/routing/manifest/create.ts Outdated Show resolved Hide resolved
Copy link
Member

@MoustaphaDev MoustaphaDev left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

It's so exciting to see this all take shape, @ematipico ! Here are some comments that I think will help make the docs a little more clear for readers! 🙌

.changeset/fluffy-dolls-sleep.md Outdated Show resolved Hide resolved
.changeset/fluffy-dolls-sleep.md Outdated Show resolved Hide resolved
.changeset/fluffy-dolls-sleep.md Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
Co-authored-by: Sarah Rainsberger <[email protected]>
@ematipico ematipico requested a review from sarah11918 November 30, 2023 21:01
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

This has docs approval!

@ematipico ematipico dismissed github-actions[bot]’s stale review November 30, 2023 21:13

Got approval to land the feature

@ematipico ematipico merged commit b4b851f into main Nov 30, 2023
14 checks passed
@ematipico ematipico deleted the feat/granular-locales branch November 30, 2023 21:14
This was referenced Nov 30, 2023
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 semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants