REST API: locale
The Internationalization (i18n) feature adds new abilities to the REST API.
To work with API content for a locale, please ensure the locale has been already added to Strapi in the admin panel.
The locale
API parameter can be used to work with documents only for a specified locale. locale
takes a locale code as a value (see full list of available locales).
If the locale
parameter is not defined, it will be set to the default locale. en
is the default locale when a new Strapi project is created, but another locale can be set as the default locale in the admin panel.
For instance, by default, a GET request to /api/restaurants
will return the same response as a request to /api/restaurants?locale=en
.
The following table lists the new possible use cases added by i18n to the REST API and gives syntax examples (you can click on requests to jump to the corresponding section with more details):
- For collection types
- For single types
Use case | Syntax example and link for more information |
---|---|
Get all documents in a specific locale | GET /api/restaurants?locale=fr |
Get a specific locale version for a document | GET /api/restaurants/abcdefghijklmno456?locale=fr |
Create a new document for the default locale | POST /api/restaurants + pass attributes in the request body |
Create a new document for a specific locale | POST /api/restaurants + pass attributes and locale in the request body |
Create a new, or update an existing, locale version for an existing document | PUT /api/restaurants/abcdefghijklmno456?locale=fr + pass attributes in the request body |
Delete a specific locale version of a document | DELETE /api/restaurants/abcdefghijklmno456?locale=fr |
Use case | Syntax example and link for more information |
---|---|
Get a specific locale version for a document | GET /api/homepage?locale=fr |
Create a new, or update an existing, locale version for an existing document | PUT /api/homepage?locale=fr + pass attributes in the request body |
Delete a specific locale version of a document | DELETE /api/homepage?locale=fr |
GET
Get all documents in a specific locale
GET http://localhost:1337/api/restaurants?locale=fr
{
"data": [
{
"id": 5,
"documentId": "h90lgohlzfpjf3bvan72mzll",
"Title": "Meilleures pizzas",
"Body": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "On déguste les meilleures pizzas de la ville à la Pizzeria Arrivederci."
}
]
}
],
"createdAt": "2024-03-06T22:08:59.643Z",
"updatedAt": "2024-03-06T22:10:21.127Z",
"publishedAt": "2024-03-06T22:10:21.130Z",
"locale": "fr"
}
],
"meta": {
"pagination": {
"page": 1,
"pageSize": 25,
"pageCount": 1,
"total": 1
}
}
}
GET
Get a document in a specific locale
To get a specific document in a given locale, add the locale
parameter to the query:
Use case | Syntax format and link for more information |
---|---|
In a collection type | GET /api/content-type-plural-name/document-id?locale=locale-code |
In a single type | GET /api/content-type-singular-name?locale=locale-code |