Skip to content

Commit 02a6565

Browse files
committed
docs: update docs
1 parent fbabab4 commit 02a6565

23 files changed

+889
-15
lines changed

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const config: ReturnType<typeof defineConfig> = defineConfig(
106106
'./**/playground/**',
107107
'./packages/h3/docs/**',
108108
'./packages/hono/docs/**',
109+
'./packages/elysia/docs/**',
109110
'design/**'
110111
]) as Linter.Config
111112
)

packages/elysia/docs/functions/detectLocaleFromAcceptLanguageHeader.md

Lines changed: 63 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[**@intlify/elysia**](../index.md)
2+
3+
---
4+
5+
[@intlify/elysia](../index.md) / getCookieLocale
6+
7+
# Function: getCookieLocale()
8+
9+
```ts
10+
function getCookieLocale(request, options?): Locale
11+
```
12+
13+
get locale from cookie
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| ---------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19+
| `request` | `Request` | The Request \| request |
20+
| `options?` | `CookieLocaleOptions` | The CookieLocaleOptions \| cookie locale options, `lang` option is `en-US` as default, you must specify the language tag with the [BCP 47 syntax](https://datatracker.ietf.org/doc/html/rfc4646#section-2.1). `name` option is `i18n_locale` as default. |
21+
22+
## Returns
23+
24+
`Locale`
25+
26+
The locale that resolved from cookie
27+
28+
## Example
29+
30+
example for Web API request on Deno:
31+
32+
```ts
33+
import { getCookieLocale } from 'https://esm.sh/@intlify/utils/web'
34+
35+
Deno.serve(
36+
{
37+
port: 8080
38+
},
39+
req => {
40+
const locale = getCookieLocale(req)
41+
console.log(locale) // output `Intl.Locale` instance
42+
// ...
43+
}
44+
)
45+
```
46+
47+
## Throws
48+
49+
Throws a `RangeError` if `lang` option or cookie name value are not a well-formed BCP 47 language tag.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[**@intlify/elysia**](../index.md)
2+
3+
---
4+
5+
[@intlify/elysia](../index.md) / getHeaderLanguage
6+
7+
# Function: getHeaderLanguage()
8+
9+
```ts
10+
function getHeaderLanguage(request, options?): string
11+
```
12+
13+
get language from header
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| ---------- | --------------- | ------------------------------------------ |
19+
| `request` | `Request` | The Request \| request |
20+
| `options?` | `HeaderOptions` | The HeaderOptions \| header options object |
21+
22+
## Returns
23+
24+
`string`
25+
26+
The **first language tag** of header, if header is not exists, or `*` (any language), return empty string.
27+
28+
## Description
29+
30+
parse header string, default `accept-language`. if you use `accept-language`, this function returns the **first language tag** of `accept-language` header.
31+
32+
## Example
33+
34+
example for Web API request on Deno:
35+
36+
```ts
37+
import { getAcceptLanguage } from 'https://esm.sh/@intlify/utils/web'
38+
39+
Deno.serve({
40+
port: 8080,
41+
}, (req) => {
42+
const langTag = getHeaderLanguage(req)
43+
// ...
44+
return new Response(`accepted language: ${langTag}`
45+
})
46+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[**@intlify/elysia**](../index.md)
2+
3+
---
4+
5+
[@intlify/elysia](../index.md) / getHeaderLanguages
6+
7+
# Function: getHeaderLanguages()
8+
9+
```ts
10+
function getHeaderLanguages(request, options?): string[]
11+
```
12+
13+
get languages from header
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| ---------- | --------------- | ------------------------------------------------------------------------------------------ |
19+
| `request` | `Request` | The Request \| request |
20+
| `options?` | `HeaderOptions` | The HeaderOptions \| header options object. `name` option is `accept-language` as default. |
21+
22+
## Returns
23+
24+
`string`[]
25+
26+
The array of language tags, if you use `accept-language` header and `*` (any language) or empty string is detected, return an empty array.
27+
28+
## Description
29+
30+
parse header string, default `accept-language` header
31+
32+
## Example
33+
34+
example for Web API request on Deno:
35+
36+
```ts
37+
import { getHeaderLanguages } from 'https://esm.sh/@intlify/utils/web'
38+
39+
Deno.serve({
40+
port: 8080,
41+
}, (req) => {
42+
const langTags = getHeaderLanguages(req)
43+
// ...
44+
return new Response(`accepted languages: ${langTags.join(', ')}`
45+
})
46+
```
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[**@intlify/elysia**](../index.md)
2+
3+
---
4+
5+
[@intlify/elysia](../index.md) / getHeaderLocale
6+
7+
# Function: getHeaderLocale()
8+
9+
```ts
10+
function getHeaderLocale(request, options?): Locale
11+
```
12+
13+
get locale from header
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| ---------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
19+
| `request` | `Request` | The Request \| request |
20+
| `options?` | `HeaderOptions` & `object` | The HeaderOptions \| header options object. `lang` option is `en-US` as default, you must specify the language tag with the [BCP 47 syntax](https://datatracker.ietf.org/doc/html/rfc4646#section-2.1). `name` option is `accept-language` as default, and `parser` option is parseDefaultHeader as default. |
21+
22+
## Returns
23+
24+
`Locale`
25+
26+
The first locale that resolved from header string. if you use `accept-language` header and `*` (any language) or empty string is detected, return `en-US`.
27+
28+
## Description
29+
30+
wrap language tag with Intl.Locale \| locale, languages tags will be parsed from `accept-language` header as default.
31+
32+
## Example
33+
34+
```ts
35+
example for Web API request on Bun:
36+
37+
import { getHeaderLocale } from '@intlify/utils/web'
38+
39+
Bun.serve({
40+
port: 8080,
41+
fetch(req) {
42+
const locale = getHeaderLocale(req)
43+
// ...
44+
return new Response(`accpected locale: ${locale.toString()}`)
45+
},
46+
})
47+
```
48+
49+
## Throws
50+
51+
Throws the `RangeError` if `lang` option or header are not a well-formed BCP 47 language tag.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[**@intlify/elysia**](../index.md)
2+
3+
---
4+
5+
[@intlify/elysia](../index.md) / getHeaderLocales
6+
7+
# Function: getHeaderLocales()
8+
9+
```ts
10+
function getHeaderLocales(request, options?): Locale[]
11+
```
12+
13+
get locales from header
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| ---------- | --------------- | ------------------------------------------ |
19+
| `request` | `Request` | The Request \| request |
20+
| `options?` | `HeaderOptions` | The HeaderOptions \| header options object |
21+
22+
## Returns
23+
24+
`Locale`[]
25+
26+
The locales that wrapped from header, if you use `accept-language` header and `*` (any language) or empty string is detected, return an empty array.
27+
28+
## Description
29+
30+
wrap language tags with Intl.Locale \| locale, languages tags will be parsed from `accept-language` header as default.
31+
32+
## Example
33+
34+
example for Web API request on Bun:
35+
36+
```ts
37+
import { getHeaderLocales } from '@intlify/utils/web'
38+
39+
Bun.serve({
40+
port: 8080,
41+
fetch(req) {
42+
const locales = getHeaderLocales(req)
43+
// ...
44+
return new Response(`accpected locales: ${locales.map(locale => locale.toString()).join(', ')}`)
45+
}
46+
})
47+
```
48+
49+
## Throws
50+
51+
Throws the `RangeError` if header are not a well-formed BCP 47 language tag.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[**@intlify/elysia**](../index.md)
2+
3+
---
4+
5+
[@intlify/elysia](../index.md) / getPathLocale
6+
7+
# Function: getPathLocale()
8+
9+
```ts
10+
function getPathLocale(request, options?): Locale
11+
```
12+
13+
get the locale from the path
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| ---------- | ------------- | -------------------------------------- |
19+
| `request` | `Request` | the Request \| request |
20+
| `options?` | `PathOptions` | the PathOptions \| path options object |
21+
22+
## Returns
23+
24+
`Locale`
25+
26+
The locale that resolved from path
27+
28+
## Throws
29+
30+
Throws the `RangeError` if the language in the path, that is not a well-formed BCP 47 language tag.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[**@intlify/elysia**](../index.md)
2+
3+
---
4+
5+
[@intlify/elysia](../index.md) / getQueryLocale
6+
7+
# Function: getQueryLocale()
8+
9+
```ts
10+
function getQueryLocale(request, options?): Locale
11+
```
12+
13+
get the locale from the query
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| ---------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
19+
| `request` | `Request` | the Request \| request |
20+
| `options?` | `QueryOptions` | The QueryOptions \| query options, `lang` option is `en-US` as default, `name` option is `locale` as default. |
21+
22+
## Returns
23+
24+
`Locale`
25+
26+
The locale that resolved from query
27+
28+
## Throws
29+
30+
Throws the `RangeError` if the language in the query, that is not a well-formed BCP 47 language tag.

0 commit comments

Comments
 (0)