Multilanguage
Yes, t3api supports multilanguage applications!
T3api offers two ways you can request multilanguage data:
- standard language prefix
- language header
Standard prefix
First is a standard way, just to prefix your request with language base as defined
in your site's config..
https://will return news in default language.14. t3api. ddev. site/_ api/ news/ news https://will return news in14. t3api. ddev. site/ de/_ api/ news/ news delanguage.
Language header
Second way is to use always the same default language URL and add request header X-
with value set to identifier of expected language. Identifier means language value
from your site's config..
https://with header14. t3api. ddev. site/_ api/ news/ news X-or no header at all will return news in default language.Locale: 0 https://with header14. t3api. ddev. site/_ api/ news/ news X-will return news inLocale: 1 delanguage.
curl -H "X-Locale: 1" https://14.t3api.ddev.site/_api/news/news
An empty header is ignored. A value which is not the identifier of an available language (unknown identifier,
not a number) results in 400 Bad Request. A disabled language (enabled: false) is available only for a
logged in backend user with access to this language - same as for the language prefix in URL.
Here is a part of config. used for the examples (site configuration of testing instance):
languages:
-
title: English
enabled: true
languageId: 0
base: /
typo3Language: default
locale: en_US.UTF-8
flag: us
-
title: German
enabled: true
languageId: 1
base: /de/
typo3Language: de
locale: de_DE.UTF-8
fallbackType: strict
fallbacks: ''
flag: de
-
title: Polish
enabled: true
languageId: 2
base: /pl/
typo3Language: pl
locale: pl_PL.UTF-8
fallbackType: fallback
fallbacks: '0'
flag: pl
Important
t3api respects fallbackType set in site's configuration.
It is possible to customize name of the language header inside ext_:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['languageHeader'] = 'My-Header-Name';
Real examples. Run "ddev restart && ddev ci 14" and try those links below.
- News in German -
fallbackso only 2 translated records are returned:Type: strict
- News in Polish -
fallbackso 2 translated records and default language records for the rest are returned:Type: fallback