Skip to content

Commit

Permalink
Fix i18n routing param (#9274)
Browse files Browse the repository at this point in the history
* Fix i18n routing param

* Add changeset
  • Loading branch information
TheOtterlord authored Dec 4, 2023
1 parent d71e937 commit feaba2c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-cats-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix routing prefixes when `prefixDefaultLocale` is `true`
12 changes: 6 additions & 6 deletions packages/astro/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
};

Expand All @@ -100,15 +100,15 @@ export function getLocaleRelativeUrlList({
path,
prependWith,
normalizeLocale = false,
routingStrategy = 'prefix-other-locales',
routing = 'prefix-other-locales',
defaultLocale,
}: GetLocalesBaseUrl) {
const locales = toPaths(_locales);
return locales.map((locale) => {
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);
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/test/units/i18n/astro_i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe('getLocaleRelativeUrl', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'es', 'en_US', 'en_AU'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};
Expand Down Expand Up @@ -530,7 +530,7 @@ describe('getLocaleRelativeUrlList', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'en_US', 'es'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};
Expand Down Expand Up @@ -840,7 +840,7 @@ describe('getLocaleAbsoluteUrl', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'es', 'en_US', 'en_AU'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};
Expand Down Expand Up @@ -1122,7 +1122,7 @@ describe('getLocaleAbsoluteUrlList', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'en_US', 'es'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};
Expand Down

0 comments on commit feaba2c

Please sign in to comment.