Skip to content

Commit

Permalink
docs: update wording for server-side usage (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn authored Jan 21, 2024
1 parent e1d02fa commit 9e213d0
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions docs/content/2.guide/16.server-side-translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The locale messages defined in nuxt i18n module options are integrated, so all you need to do is configure the locale detector.

You can do the translation on the server side and return it as a response.
You can do the translation on the server-side and return it as a response.

---

Expand All @@ -12,12 +12,11 @@ You can do the translation on the server side and return it as a response.

## Define locale detector

For server-side translation, you need to define locale detector.
For server-side translation, you need to define a locale detector.

Nuxt i18n export the `defineI18nLocaleDetector` composable function to define it.
You can use it to define the locale detector.
Nuxt i18n exports the `defineI18nLocaleDetector` composable function to define it.

The following is an example of defining a detector that detects locale using query, cookie, and header:
The following is an example of how to define a detector that detects locale using query, cookie, and header:
```ts {}[localeDetector.ts]
// Detect based on query, cookie, header
export default defineI18nLocaleDetector((event, config) => {
Expand All @@ -44,11 +43,11 @@ export default defineI18nLocaleDetector((event, config) => {
})
```

The locale detector function is used to detect the locale on server-side. It's called per request on the server.
The locale detector function is used to detect the locale on the server-side. It's called per request on the server.

when you will define the locale detector, you need to pass the path to the locale detector to `experimental.localeDetector` option.
When you define the locale detector, you need to pass the path to the locale detector to the `experimental.localeDetector` option.

The following is an example of locale detector configuration defined directly under Nuxt application:
The following is an example of a locale detector configuration defined directly in the Nuxt application:

```ts {}[nuxt.config.ts]
export default defineNuxtConfig({
Expand All @@ -70,7 +69,7 @@ For details on the locale detector function defined by `defineI18nLocaleDetector

## `useTranslation` on eventHandler

To translate on the server side, you need to call `useTranslation`.
To translate on the server-side , you need to call `useTranslation`.

Example:
```ts
Expand All @@ -87,5 +86,5 @@ export default defineEventHandler(async event => {
```

::alert{type="info"}
For the key of translation function, you can specify the locale messages set in nuxt i18n options in nuxt.config, or the locale loaded in i18n.config messages loaded in i18n.config.
For the key of the translation function, you can specify the locale messages set in the nuxt-i18n options inside the nuxt.config, or the locale loaded in the i18n.config messages.
::

0 comments on commit 9e213d0

Please sign in to comment.