Skip to content

Commit 970ac0f

Browse files
ArmandPhilippotematipicoyanthomasdev
authored
docs: add JSDoc for astro:i18n public utilities (#14703)
* docs: add missing JSDoc for `astro:i18n` public utilities * add changeset Co-authored-by: ematipico <[email protected]> Co-authored-by: yanthomasdev <[email protected]>
1 parent 9be54c7 commit 970ac0f

File tree

2 files changed

+93
-5
lines changed

2 files changed

+93
-5
lines changed

.changeset/beige-friends-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Adds missing documentation for some public utilities exported from `astro:i18n`.

packages/astro/src/virtual-modules/i18n.ts

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import type { MiddlewareHandler } from '../types/public/common.js';
99
import type { AstroConfig, ValidRedirectStatus } from '../types/public/config.js';
1010
import type { APIContext } from '../types/public/context.js';
1111

12-
export { normalizeTheLocale, toCodes, toPaths } from '../i18n/index.js';
13-
1412
const { trailingSlash, format, site, i18n, isBuild } =
1513
// @ts-expect-error
1614
__ASTRO_INTERNAL_I18N_CONFIG__ as I18nInternalConfig;
@@ -236,9 +234,9 @@ export const getLocaleByPath = (path: string) => I18nInternals.getLocaleByPath(p
236234
*
237235
* ```js
238236
* import { pathHasLocale } from "astro:i18n";
239-
* getLocaleByPath("italiano"); // returns `true`
240-
* getLocaleByPath("es"); // returns `true`
241-
* getLocaleByPath("it-VT"); // returns `false`
237+
* pathHasLocale("italiano"); // returns `true`
238+
* pathHasLocale("es"); // returns `true`
239+
* pathHasLocale("it-VT"); // returns `false`
242240
* ```
243241
*/
244242
export const pathHasLocale = (path: string) => I18nInternals.pathHasLocale(path, locales);
@@ -388,3 +386,88 @@ if (i18n?.routing === 'manual') {
388386
} else {
389387
middleware = noop('middleware');
390388
}
389+
390+
/**
391+
* Replaces underscores (`_`) with hyphens (`-`) in the given locale before
392+
* returning a lowercase version.
393+
*
394+
* @param {string} locale A locale code to normalize.
395+
* @returns {string} The normalized locale.
396+
*
397+
* ## Example
398+
*
399+
* ```js
400+
* import { normalizeTheLocale } from "astro:i18n";
401+
* normalizeTheLocale("it_VT") // returns `it-vt`
402+
* ```
403+
*/
404+
export const normalizeTheLocale = I18nInternals.normalizeTheLocale;
405+
406+
/**
407+
* Retrieves the configured locale codes for each locale defined in your
408+
* configuration. When multiple codes are associated to a locale, only the
409+
* first one will be added to the array.
410+
*
411+
* @param {Locales} locales The configured locales.
412+
* @returns {string[]} The configured locales codes.
413+
*
414+
* ## Example
415+
*
416+
* Given the following configuration:
417+
*
418+
* ```js
419+
* // astro.config.mjs
420+
*
421+
* export default defineConfig({
422+
* i18n: {
423+
* locales: [
424+
* { codes: ["it-VT", "it"], path: "italiano" },
425+
* "es"
426+
* ]
427+
* }
428+
* })
429+
* ```
430+
*
431+
* Here's a use case:
432+
*
433+
* ```js
434+
* import { i18n } from "astro:config/client";
435+
* import { toCodes } from "astro:i18n";
436+
* toCodes(i18n.locales); // ["it-VT", "es"]
437+
* ```
438+
*/
439+
export const toCodes = I18nInternals.toCodes;
440+
441+
/**
442+
* Retrieves the configured locale paths for each locale defined in your
443+
* configuration.
444+
*
445+
* @param {Locales} locales The configured locales.
446+
* @returns {string[]} The configured locales paths.
447+
*
448+
* ## Example
449+
*
450+
* Given the following configuration:
451+
*
452+
* ```js
453+
* // astro.config.mjs
454+
*
455+
* export default defineConfig({
456+
* i18n: {
457+
* locales: [
458+
* { codes: ["it-VT", "it"], path: "italiano" },
459+
* "es"
460+
* ]
461+
* }
462+
* })
463+
* ```
464+
*
465+
* Here's a use case:
466+
*
467+
* ```js
468+
* import { i18n } from "astro:config/client";
469+
* import { toPaths } from "astro:i18n";
470+
* toPaths(i18n.locales); // ["italiano", "es"]
471+
* ```
472+
*/
473+
export const toPaths = I18nInternals.toPaths;

0 commit comments

Comments
 (0)