Skip to content
Open
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
6 changes: 3 additions & 3 deletions docs/en-US/node/guides/strings.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: String Translation Patterns
description: Two approaches to translating strings in Node.js — inline and pre-registered
description: Three approaches to translating strings in Node.js — inline, pre-registered, and on-demand
---

There are three ways to translate strings in `gt-node`:
Expand Down Expand Up @@ -38,7 +38,7 @@ gt('{city} weather: {temp}°F', { city: 'Tokyo', temp: 72 });

## Pre-registered strings with `msg()` / `getMessages()`

Use [`msg()`](/docs/node/api/get-messages) to register strings at module scope — outside of any request handler. Then use [`getMessages()`](/docs/node/api/get-messages) inside handlers to resolve them for the current locale:
Use [`msg()`](/docs/node/api/strings/msg) to register strings at module scope — outside of any request handler. Then use [`getMessages()`](/docs/node/api/get-messages) inside handlers to resolve them for the current locale:

```js title="messages.js"
import { msg } from 'gt-node';
Expand Down Expand Up @@ -96,7 +96,7 @@ app.post('/api/translate', async (req, res) => {
| `tx()` | Dynamic or user-generated content not known at build time |

<Callout>
Both approaches produce identical translations. The difference is only in code organization — pick whichever fits your project structure.
`getGT()` and `msg()` / `getMessages()` both produce identical build-time translations. The difference is only in code organization — pick whichever fits your project structure. Use `tx()` only when the content is not known at build time.
</Callout>

## Using `$context` for disambiguation
Expand Down
Loading