Skip to content

Commit 7336525

Browse files
committed
doc: add how to use lang data section in readme
1 parent c92eb40 commit 7336525

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ content/
5151
├── fr.json
5252
└── [other-locales].json
5353
```
54-
How to add a new language support:
54+
#### How to add a new language support:
55+
5556
To add a new language, we have to add the language JSON file to the content directory, which is in the root directory, that is our first step.
5657

5758
After that, we have to add the newly added language to the locales array in the navigation.ts file. Below is the content of the navigation.ts file, where we need to add the newly added language to the locales array:
@@ -70,8 +71,28 @@ export const routing = defineRouting({
7071
export const {Link, redirect, usePathname, useRouter, getPathname} =
7172
createNavigation(routing);
7273
```
73-
## Getting Started
74+
#### Using Strings from Language Files
75+
76+
To use strings from a language file in both **client and server** components, use the `useTranslations` hook.
77+
78+
#### Steps:
7479

80+
1. **Import `useTranslations`:**
81+
82+
```javascript
83+
import { useTranslations } from 'next-intl';
84+
```
85+
2. **Initialize useTranslations with a section:**
86+
```javascript
87+
const t = useTranslations('Home');
88+
```
89+
3. **Fetch and use translations:**
90+
91+
```javascript
92+
<h1>{t('welcomeMessage')}</h1>
93+
```
94+
95+
## Getting Started
7596
> Usage
7697
7798
```bash

0 commit comments

Comments
 (0)