Language support
Opened this issue · 2 comments
drigolin commented
Following documentation of Alma API at
https://developers.exlibrisgroup.com/alma/apis/#lang
Language Support
By default all APIs return error messages and textual information in English. To run an API with another language include the ‘lang’ parameter with a 2 letter code of the language. E.g. for French: ...&lang=fr. Note that only languages which are enabled in Alma can be used (according to ‘Institution Languages’ mapping-table).
Adding this "extra parameter" to AlmaClient can make easier to handle multiple language instances.
I solved the issue for the moment extending AlmaClient:
class LocalizedAlmaClient extends AlmaClient {
public $lang;
public function __construct(
$key = null,
$region = 'eu',
$lang = 'en',
$zone = Zones::INSTITUTION,
HttpClientInterface $http = null,
RequestFactoryInterface $requestFactory = null,
UriFactoryInterface $uriFactory = null
) {
$this->lang = $lang;
parent::__construct($key,$region,$zone,$http,$requestFactory,$uriFactory);
}
public function buildUrl($url, $query = [])
{
$url = explode('?', $url, 2);
if (count($url) == 2) {
parse_str($url[1], $query0);
$query = array_merge($query0, $query);
}
$query['apikey'] = $this->key;
$query['lang'] = $this->lang;
$url = $url[0];
if (strpos($url, $this->baseUrl) === false) {
$url = $this->baseUrl . $url;
}
return $this->uriFactory->createUri($url)
->withQuery(http_build_query($query));
}
}
symac commented