Skip to content

Commit

Permalink
chore: make normalize path the default (#9004)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 6, 2023
1 parent e08eecc commit f54e508
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ declare module 'astro:i18n' {
* import { getLocaleRelativeUrl } from "astro:i18n";
* getLocaleRelativeUrl("es"); // /es
* getLocaleRelativeUrl("es", "getting-started"); // /es/getting-started
* getLocaleRelativeUrl("es", "getting-started", { prependWith: "blog" }); // /blog/es/getting-started
* getLocaleRelativeUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: true }); // /blog/es-us/getting-started
* getLocaleRelativeUrl("es_US", "getting-started", { prependWith: "blog" }); // /blog/es-us/getting-started
* getLocaleRelativeUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // /blog/es_US/getting-started
* ```
*/
export const getLocaleRelativeUrl: (
Expand Down Expand Up @@ -174,8 +174,8 @@ declare module 'astro:i18n' {
* import { getLocaleAbsoluteUrl } from "astro:i18n";
* getLocaleAbsoluteUrl("es"); // https://example.com/es
* getLocaleAbsoluteUrl("es", "getting-started"); // https://example.com/es/getting-started
* getLocaleAbsoluteUrl("es", "getting-started", { prependWith: "blog" }); // https://example.com/blog/es/getting-started
* getLocaleAbsoluteUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: true }); // https://example.com/blog/es-us/getting-started
* getLocaleAbsoluteUrl("es_US", "getting-started", { prependWith: "blog" }); // https://example.com/blog/es-us/getting-started
* getLocaleAbsoluteUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // https://example.com/blog/es_US/getting-started
* ```
*/
export const getLocaleAbsoluteUrl: (
Expand Down
7 changes: 4 additions & 3 deletions packages/astro/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ type GetLocaleRelativeUrl = GetLocaleOptions & {
export type GetLocaleOptions = {
/**
* Makes the locale URL-friendly by replacing underscores with dashes, and converting the locale to lower case.
* @default true
*/
normalizeLocale?: boolean;
/**
* An optional path to add after the `locale`
* An optional path to add after the `locale`.
*/
path?: string;
/**
* An optional path to prepend to `locale`
* An optional path to prepend to `locale`.
*/
prependWith?: string;
};
Expand All @@ -41,7 +42,7 @@ export function getLocaleRelativeUrl({
format,
path,
prependWith,
normalizeLocale = false,
normalizeLocale = true,
}: GetLocaleRelativeUrl) {
if (!locales.includes(locale)) {
throw new AstroError({
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/test/units/i18n/astro_i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('getLocaleRelativeUrl', () => {
).to.eq('/blog/en');
});

it('should normalize locales', () => {
it('should normalize locales by default', () => {
/**
*
* @type {import("../../../dist/@types").AstroUserConfig}
Expand All @@ -216,7 +216,7 @@ describe('getLocaleRelativeUrl', () => {
trailingSlash: 'always',
format: 'directory',
})
).to.eq('/blog/en_US/');
).to.eq('/blog/en-us/');

expect(
getLocaleRelativeUrl({
Expand All @@ -225,9 +225,9 @@ describe('getLocaleRelativeUrl', () => {
locales: config.experimental.i18n.locales,
trailingSlash: 'always',
format: 'directory',
normalizeLocale: true,
normalizeLocale: false,
})
).to.eq('/blog/en-us/');
).to.eq('/blog/en_US/');

expect(
getLocaleRelativeUrl({
Expand All @@ -237,7 +237,7 @@ describe('getLocaleRelativeUrl', () => {
trailingSlash: 'always',
format: 'directory',
})
).to.eq('/blog/en_AU/');
).to.eq('/blog/en-au/');
});
});

Expand Down

0 comments on commit f54e508

Please sign in to comment.