diff options
author | 2023-12-04 05:00:01 +0000 | |
---|---|---|
committer | 2023-12-04 00:00:01 -0500 | |
commit | feaba2c7fc0a48d3af7dd98e6b750ec1e8274e33 (patch) | |
tree | e5201b48532b41ab5fbb8146cfd9027eee685b62 | |
parent | d71e937492cbaa0af7ad3dc7c9e4203e4145ed9b (diff) | |
download | astro-feaba2c7fc0a48d3af7dd98e6b750ec1e8274e33.tar.gz astro-feaba2c7fc0a48d3af7dd98e6b750ec1e8274e33.tar.zst astro-feaba2c7fc0a48d3af7dd98e6b750ec1e8274e33.zip |
Fix i18n routing param (#9274)
* Fix i18n routing param
* Add changeset
-rw-r--r-- | .changeset/smart-cats-camp.md | 5 | ||||
-rw-r--r-- | packages/astro/src/i18n/index.ts | 12 | ||||
-rw-r--r-- | packages/astro/test/units/i18n/astro_i18n.test.js | 8 |
3 files changed, 15 insertions, 10 deletions
diff --git a/.changeset/smart-cats-camp.md b/.changeset/smart-cats-camp.md new file mode 100644 index 000000000..96f290362 --- /dev/null +++ b/.changeset/smart-cats-camp.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix routing prefixes when `prefixDefaultLocale` is `true` diff --git a/packages/astro/src/i18n/index.ts b/packages/astro/src/i18n/index.ts index 1370087bc..947689d51 100644 --- a/packages/astro/src/i18n/index.ts +++ b/packages/astro/src/i18n/index.ts @@ -10,7 +10,7 @@ type GetLocaleRelativeUrl = GetLocaleOptions & { locales: Locales; trailingSlash: AstroConfig['trailingSlash']; format: AstroConfig['build']['format']; - routingStrategy?: 'prefix-always' | 'prefix-other-locales'; + routing?: 'prefix-always' | 'prefix-other-locales'; defaultLocale: string; }; @@ -45,7 +45,7 @@ export function getLocaleRelativeUrl({ path, prependWith, normalizeLocale = true, - routingStrategy = 'prefix-other-locales', + routing = 'prefix-other-locales', defaultLocale, }: GetLocaleRelativeUrl) { const codeToUse = peekCodePathToUse(_locales, locale); @@ -57,7 +57,7 @@ export function getLocaleRelativeUrl({ } const pathsToJoin = [base, prependWith]; const normalizedLocale = normalizeLocale ? normalizeTheLocale(codeToUse) : codeToUse; - if (routingStrategy === 'prefix-always') { + if (routing === 'prefix-always') { pathsToJoin.push(normalizedLocale); } else if (locale !== defaultLocale) { pathsToJoin.push(normalizedLocale); @@ -88,7 +88,7 @@ type GetLocalesBaseUrl = GetLocaleOptions & { locales: Locales; trailingSlash: AstroConfig['trailingSlash']; format: AstroConfig['build']['format']; - routingStrategy?: 'prefix-always' | 'prefix-other-locales'; + routing?: 'prefix-always' | 'prefix-other-locales'; defaultLocale: string; }; @@ -100,7 +100,7 @@ export function getLocaleRelativeUrlList({ path, prependWith, normalizeLocale = false, - routingStrategy = 'prefix-other-locales', + routing = 'prefix-other-locales', defaultLocale, }: GetLocalesBaseUrl) { const locales = toPaths(_locales); @@ -108,7 +108,7 @@ export function getLocaleRelativeUrlList({ const pathsToJoin = [base, prependWith]; const normalizedLocale = normalizeLocale ? normalizeTheLocale(locale) : locale; - if (routingStrategy === 'prefix-always') { + if (routing === 'prefix-always') { pathsToJoin.push(normalizedLocale); } else if (locale !== defaultLocale) { pathsToJoin.push(normalizedLocale); diff --git a/packages/astro/test/units/i18n/astro_i18n.test.js b/packages/astro/test/units/i18n/astro_i18n.test.js index 126883d54..ad5a2fa23 100644 --- a/packages/astro/test/units/i18n/astro_i18n.test.js +++ b/packages/astro/test/units/i18n/astro_i18n.test.js @@ -286,7 +286,7 @@ describe('getLocaleRelativeUrl', () => { i18n: { defaultLocale: 'en', locales: ['en', 'es', 'en_US', 'en_AU'], - routingStrategy: 'prefix-always', + routing: 'prefix-always', }, }, }; @@ -530,7 +530,7 @@ describe('getLocaleRelativeUrlList', () => { i18n: { defaultLocale: 'en', locales: ['en', 'en_US', 'es'], - routingStrategy: 'prefix-always', + routing: 'prefix-always', }, }, }; @@ -840,7 +840,7 @@ describe('getLocaleAbsoluteUrl', () => { i18n: { defaultLocale: 'en', locales: ['en', 'es', 'en_US', 'en_AU'], - routingStrategy: 'prefix-always', + routing: 'prefix-always', }, }, }; @@ -1122,7 +1122,7 @@ describe('getLocaleAbsoluteUrlList', () => { i18n: { defaultLocale: 'en', locales: ['en', 'en_US', 'es'], - routingStrategy: 'prefix-always', + routing: 'prefix-always', }, }, }; |