Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions packages/h3/docs/functions/getCookieLocale.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: getCookieLocale()

```ts
function getCookieLocale(event, __namedParameters?): Locale;
function getCookieLocale(request, options?): Locale;
```

get locale from cookie
Expand All @@ -16,10 +16,8 @@ get locale from cookie

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `__namedParameters?` | \{ `lang?`: `string`; `name?`: `string`; \} | - |
| `__namedParameters.lang?` | `string` | - |
| `__namedParameters.name?` | `string` | - |
| `request` | `Request` | The Request \| request |
| `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. |

## Returns

Expand All @@ -29,19 +27,20 @@ The locale that resolved from cookie

## Example

example for h3:
example for Web API request on Deno:

```ts
import { createApp, eventHandler } from 'h3'
import { getCookieLocale } from '@intlify/utils/h3'
import { getCookieLocale } from 'https://esm.sh/@intlify/utils/web'

app.use(eventHandler(event) => {
const locale = getCookieLocale(event)
Deno.serve({
port: 8080,
}, (req) => {
const locale = getCookieLocale(req)
console.log(locale) // output `Intl.Locale` instance
// ...
})
```

## Throws

Throws a RangeError if `lang` option or cookie name value are not a well-formed BCP 47 language tag.
Throws a `RangeError` if `lang` option or cookie name value are not a well-formed BCP 47 language tag.
20 changes: 10 additions & 10 deletions packages/h3/docs/functions/getHeaderLanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: getHeaderLanguage()

```ts
function getHeaderLanguage(event, __namedParameters?): string;
function getHeaderLanguage(request, options?): string;
```

get language from header
Expand All @@ -16,8 +16,8 @@ get language from header

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `__namedParameters?` | `HeaderOptions` | - |
| `request` | `Request` | The Request \| request |
| `options?` | `HeaderOptions` | The HeaderOptions \| header options object |

## Returns

Expand All @@ -31,16 +31,16 @@ parse header string, default `accept-language`. if you use `accept-language`, th

## Example

example for h3:
example for Web API request on Deno:

```ts
import { createApp, eventHandler } from 'h3'
import { getAcceptLanguage } from '@intlify/utils/h3'
import { getAcceptLanguage } from 'https://esm.sh/@intlify/utils/web'

const app = createApp()
app.use(eventHandler(event) => {
const langTag = getHeaderLanguage(event)
Deno.serve({
port: 8080,
}, (req) => {
const langTag = getHeaderLanguage(req)
// ...
return `accepted language: ${langTag}`
return new Response(`accepted language: ${langTag}`
})
```
20 changes: 10 additions & 10 deletions packages/h3/docs/functions/getHeaderLanguages.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: getHeaderLanguages()

```ts
function getHeaderLanguages(event, __namedParameters?): string[];
function getHeaderLanguages(request, options?): string[];
```

get languages from header
Expand All @@ -16,8 +16,8 @@ get languages from header

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `__namedParameters?` | `HeaderOptions` | - |
| `request` | `Request` | The Request \| request |
| `options?` | `HeaderOptions` | The HeaderOptions \| header options object. `name` option is `accept-language` as default. |

## Returns

Expand All @@ -31,16 +31,16 @@ parse header string, default `accept-language` header

## Example

example for h3:
example for Web API request on Deno:

```ts
import { createApp, eventHandler } from 'h3'
import { getHeaderLanguages } from '@intlify/utils/h3'
import { getHeaderLanguages } from 'https://esm.sh/@intlify/utils/web'

const app = createApp()
app.use(eventHandler(event) => {
const langTags = getHeaderLanguages(event)
Deno.serve({
port: 8080,
}, (req) => {
const langTags = getHeaderLanguages(req)
// ...
return `accepted languages: ${acceptLanguages.join(', ')}`
return new Response(`accepted languages: ${langTags.join(', ')}`
})
```
26 changes: 14 additions & 12 deletions packages/h3/docs/functions/getHeaderLocale.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: getHeaderLocale()

```ts
function getHeaderLocale(event, __namedParameters?): Locale;
function getHeaderLocale(request, options?): Locale;
```

get locale from header
Expand All @@ -16,8 +16,8 @@ get locale from header

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `__namedParameters?` | `HeaderOptions` & `object` | - |
| `request` | `Request` | The Request \| request |
| `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. |

## Returns

Expand All @@ -31,19 +31,21 @@ wrap language tag with Intl.Locale \| locale, languages tags will be parsed from

## Example

example for h3:

```ts
import { createApp, eventHandler } from 'h3'
import { getHeaderLocale } from '@intlify/utils/h3'
example for Web API request on Bun:

import { getHeaderLocale } from '@intlify/utils/web'

app.use(eventHandler(event) => {
const locale = getHeaderLocale(event)
// ...
return `accepted locale: ${locale.toString()}`
Bun.serve({
port: 8080,
fetch(req) {
const locale = getHeaderLocale(req)
// ...
return new Response(`accpected locale: ${locale.toString()}`)
},
})
```

## Throws

Throws the RangeError if `lang` option or header are not a well-formed BCP 47 language tag.
Throws the `RangeError` if `lang` option or header are not a well-formed BCP 47 language tag.
26 changes: 14 additions & 12 deletions packages/h3/docs/functions/getHeaderLocales.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: getHeaderLocales()

```ts
function getHeaderLocales(event, __namedParameters?): Locale[];
function getHeaderLocales(request, options?): Locale[];
```

get locales from header
Expand All @@ -16,8 +16,8 @@ get locales from header

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `__namedParameters?` | `HeaderOptions` | - |
| `request` | `Request` | The Request \| request |
| `options?` | `HeaderOptions` | The HeaderOptions \| header options object |

## Returns

Expand All @@ -31,19 +31,21 @@ wrap language tags with Intl.Locale \| locale, languages tags will be parsed fro

## Example

example for h3:
example for Web API request on Bun:

```ts
import { createApp, eventHandler } from 'h3'
import { getHeaderLocales } from '@intlify/utils/h3'

app.use(eventHandler(event) => {
const locales = getHeaderLocales(event)
// ...
return `accepted locales: ${locales.map(locale => locale.toString()).join(', ')}`
import { getHeaderLocales } from '@intlify/utils/web'

Bun.serve({
port: 8080,
fetch(req) {
const locales = getHeaderLocales(req)
// ...
return new Response(`accpected locales: ${locales.map(locale => locale.toString()).join(', ')}`)
},
})
```

## Throws

Throws the RangeError if header are not a well-formed BCP 47 language tag.
Throws the `RangeError` if header are not a well-formed BCP 47 language tag.
8 changes: 4 additions & 4 deletions packages/h3/docs/functions/getPathLocale.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: getPathLocale()

```ts
function getPathLocale(event, __namedParameters?): Locale;
function getPathLocale(request, options?): Locale;
```

get the locale from the path
Expand All @@ -16,8 +16,8 @@ get the locale from the path

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | the H3Event \| H3 event |
| `__namedParameters?` | `PathOptions` | - |
| `request` | `Request` | the Request \| request |
| `options?` | `PathOptions` | the PathOptions \| path options object |

## Returns

Expand All @@ -27,4 +27,4 @@ The locale that resolved from path

## Throws

Throws the RangeError if the language in the path, that is not a well-formed BCP 47 language tag.
Throws the `RangeError` if the language in the path, that is not a well-formed BCP 47 language tag.
8 changes: 4 additions & 4 deletions packages/h3/docs/functions/getQueryLocale.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: getQueryLocale()

```ts
function getQueryLocale(event, __namedParameters?): Locale;
function getQueryLocale(request, options?): Locale;
```

get the locale from the query
Expand All @@ -16,8 +16,8 @@ get the locale from the query

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | the H3Event \| H3 event |
| `__namedParameters?` | `QueryOptions` | - |
| `request` | `Request` | the Request \| request |
| `options?` | `QueryOptions` | The QueryOptions \| query options, `lang` option is `en-US` as default, `name` option is `locale` as default. |

## Returns

Expand All @@ -27,4 +27,4 @@ The locale that resolved from query

## Throws

Throws the RangeError if the language in the query, that is not a well-formed BCP 47 language tag.
Throws the `RangeError` if the language in the query, that is not a well-formed BCP 47 language tag.
26 changes: 15 additions & 11 deletions packages/h3/docs/functions/setCookieLocale.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```ts
function setCookieLocale(
event,
response,
locale,
options?): void;
```
Expand All @@ -19,28 +19,32 @@ set locale to the response `Set-Cookie` header.

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `response` | `Response` | The Response \| response |
| `locale` | `string` \| `Locale` | The locale value |
| `options?` | `CookieOptions` | The cookie options, `name` option is `i18n_locale` as default, and `path` option is `/` as default. |
| `options?` | `CookieOptions` | The CookieOptions \| cookie options, `name` option is `i18n_locale` as default |

## Returns

`void`

## Example

example for h3:
example for Web API response on Bun:

```ts
import { createApp, eventHandler } from 'h3'
import { getCookieLocale } from '@intlify/utils/h3'

app.use(eventHandler(event) => {
setCookieLocale(event, 'ja-JP')
// ...
import { setCookieLocale } from '@intlify/utils/web'

Bun.serve({
port: 8080,
fetch(req) {
const res = new Response('こんにちは、世界!')
setCookieLocale(res, 'ja-JP')
// ...
return res
},
})
```

## Throws

Throws the SyntaxError if `locale` is invalid.
Throws the `SyntaxError` if `locale` is invalid.
10 changes: 4 additions & 6 deletions packages/h3/docs/functions/tryCookieLocale.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: tryCookieLocale()

```ts
function tryCookieLocale(event, __namedParameters?): Locale | null;
function tryCookieLocale(request, options?): Locale | null;
```

try to get locale from cookie
Expand All @@ -16,10 +16,8 @@ try to get locale from cookie

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `__namedParameters?` | \{ `lang?`: `string`; `name?`: `string`; \} | - |
| `__namedParameters.lang?` | `string` | - |
| `__namedParameters.name?` | `string` | - |
| `request` | `Request` | The Request \| request |
| `options?` | `CookieLocaleOptions` | The CookieLocaleOptions \| cookie locale options |

## Returns

Expand All @@ -29,4 +27,4 @@ The locale that resolved from cookie. if `lang` option or cookie name value are

## Description

Unlike [getCookieLocale](getCookieLocale.md), this function does not throw an error if the locale cannot be obtained, this function returns `null`.
Unlike [`getCookieLocale`](getCookieLocale.md), this function does not throw an error if the locale cannot be obtained, this function returns `null`.
8 changes: 4 additions & 4 deletions packages/h3/docs/functions/tryHeaderLocale.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Function: tryHeaderLocale()

```ts
function tryHeaderLocale(event, __namedParameters?): Locale | null;
function tryHeaderLocale(request, options?): Locale | null;
```

try to get locale from header
Expand All @@ -16,14 +16,14 @@ try to get locale from header

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `H3Event` | The H3Event \| H3 event |
| `__namedParameters?` | `HeaderOptions` & `object` | - |
| `request` | `Request` | The Request \| request |
| `options?` | `HeaderOptions` & `object` | The HeaderOptions \| header options object |

## Returns

`Locale` \| `null`

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`. if header are not a well-formed BCP 47 language tag, return `null`.
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`. if `lang` option or header are not a well-formed BCP 47 language tag, return `null`.

## Description

Expand Down
Loading
Loading