Language

Introduction

When an endpoint provides multilingual fields, there are two ways to handle the multiple languages:

  • Display all locales for each multilingual field.
  • Use header Accept-Language and Content-Language.

Using the multilingual query parameter

Here, we create a tournament with a list of supported locales, with the “en_GB” one being the default. There are two objects, one to declare the locales and default one, the other for descriptions containing the locale as key and text as value.

$ curl -X POST 'https://api.toornament.com/organizer/v2/tournaments?multilingual=1' \
-H 'X-Api-Key: <api-key>' \
-H 'Authorization: Bearer <access-token>' \
-d '{... "locales": {"en_GB": {"default": true}, "de": {"default": false}}, "description": {"en_GB": "My description", "de": "Meine Beschreibung"} ...}'

You can also GET and PATCH a tournament with this parameter.

$ curl -i 'https://api.toornament.com/organizer/v2/tournaments/be53857b-6af6-4330?multilingual=1' \
-H 'X-Api-Key: <api-key>' \
-H 'Authorization: Bearer <access-token>'

HTTP/1.1 200 OK
Content-Type: application/json

{... "description": {"en_GB": "My description", "de": "Meine Beschreibung"}, "rules": {"es": "Reglas del torneo"} ...}

Using the Accept-Language and Content-Language HTTP headers

In this example, a tournament already exists with a few locales (“en_GB”, “de”, "es"), and “en_GB” being the default one. If you do not specify a locale, the contents in the default locale will be retrieved.

Note: error messages are not affected by these headers.

$ curl -i 'https://api.toornament.com/organizer/v2/tournaments/be53857b-6af6-4330' \
-H 'X-Api-Key: <api-key>' \
-H 'Authorization: Bearer <access-token>'

HTTP/1.1 200 OK
Content-Type: application/json
Content-Language: en-GB

{... "description": "My description" ...}

In the following example we'll retrieve a tournament in different locales, in order of importance with the HTTP header Accept-Language. The tournament has:
field description in "en_GB" and "de" locales
field rules in "de" locale only
field prize in "es" locale only

$ curl -i 'https://api.toornament.com/organizer/v2/tournaments/be53857b-6af6-4330' \
-H 'X-Api-Key: <api-key>' \
-H 'Authorization: Bearer <access-token>' \
-H 'Accept-Language: en-GB, de'

HTTP/1.1 200 OK
Content-Type: application/json
Content-Language: en-GB, de

{... "description": "My description", "rules": "Turnierregeln", "prize": null, ...}

To patch content in a specific locale, simply use the HTTP header Content-Language. In this case, only one locale is accepted in the header.

$ curl -i -X PATCH 'https://api.toornament.com/organizer/v2/tournaments/be53857b-6af6-4330' \
-H 'X-Api-Key: <api-key>' \
-H 'Authorization: Bearer <access-token>' \
-H 'Content-Language: es' \
-d '{"description": "Mi descripción"}'

HTTP/1.1 200 OK
Content-Type: application/json
Content-Language: es

{... "description": "Mi descripción" ...}

Locale Codes

List of currently supported locales:

Country FlagLocaleLanguageCountry
en_USEnglish (United States)en-USUS
en_GBEnglish (United Kingdom)en-GBGB
deGermandeDE
esSpanishesES
frFrenchfrFR
plPolishplPL
pt_BRPortuguese (Brazil)pt-BRBR
arArabicarSA
idIndonesianidID