Skip to content

Commit

Permalink
update changelog and readme for serverSetCookie option
Browse files Browse the repository at this point in the history
  • Loading branch information
dcporter44 committed Jan 5, 2024
1 parent 97da479 commit a2600b4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 5.2.0

- Change to cookie redirect behavior: When visiting a pathname that includes a locale, the middleware will now redirect if the `localeCookie` is set. Previously the redirecting based on cookie only occured on pathnames without a locale, but we've decided this is inconsistent behavior.
- Add `serverSetCookie` config option

## 5.1.0

Add forwarding of request headers in `i18nRouter`
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ You now have internationalized routing!

## Config Options

| Option | Default value | Type | Required? |
| ---------------- | --------------- | ----------------- | --------- |
| `locales` | | string[] | ✔ |
| `defaultLocale` | | string | ✔ |
| `prefixDefault` | `false` | boolean | |
| `localeDetector` | (See below) | function \| false | |
| `localeCookie` | `'NEXT_LOCALE'` | string | |
| `basePath` | `''` | string | |
| Option | Default value | Type | Required? |
| ----------------- | --------------- | ---------------------- | --------- |
| `locales` | | string[] | ✔ |
| `defaultLocale` | | string | ✔ |
| `prefixDefault` | `false` | boolean | |
| `localeDetector` | (See below) | function \| false | |
| `localeCookie` | `'NEXT_LOCALE'` | string | |
| `serverSetCookie` | | "always" \| "if-empty" | |
| `basePath` | `''` | string | |

## Locale Path Prefixing

Expand Down Expand Up @@ -108,6 +109,16 @@ You can override the `localeDetector` using the `NEXT_LOCALE=the-locale` cookie.

If you would prefer to use a different cookie key other than `NEXT_LOCALE`, you can set the `localeCookie` option.

### serverSetCookie (optional)

The `serverSetCookie` option automatically changes a visitor's preferred locale cookie by simply visiting a pathname that contains a locale.

`'always`: When the pathname of a request includes a locale, that locale will be set as the cookie by the middleware. This means that locale detection and any existing locale cookie will be ignored if a locale exists in the request's pathname. Locale detection and the reading of any existing cookie will still be run on pathnames that do not include a locale.

`'if-empty'`: Same as `'always'`, except the middleware will not overwrite the cookie if one already exists.

`undefined` (default): When `serverSetCookie` is not set, the middleware will not automatically set the cookie.

## Using `basePath` (optional)

This is only needed if you are using the `basePath` option in `next.config.js`. You will need to also include it as the `basePath` option in your `i18nConfig`.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-i18n-router",
"version": "5.1.0",
"version": "5.2.0",
"description": "Next.js App Router internationalized routing and locale detection.",
"repository": "https://github.com/i18nexus/next-i18n-router",
"keywords": [
Expand Down

0 comments on commit a2600b4

Please sign in to comment.