Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language support #22

Open
drigolin opened this issue Nov 12, 2020 · 2 comments
Open

Language support #22

drigolin opened this issue Nov 12, 2020 · 2 comments

Comments

@drigolin
Copy link

drigolin commented Nov 12, 2020

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
Copy link

symac commented Dec 4, 2020

@drigolin I have opened the PR #26 that offers an option to set the language, a bit different than yours but achieving the same result.

@drigolin
Copy link
Author

drigolin commented Dec 7, 2020

@sy

@drigolin I have opened the PR #26 that offers an option to set the language, a bit different than yours but achieving the same result.

@symac your PR is the correct solution. My workaround was only to avoid patching the core library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants