APIs do have a language parameter option. We could make the retreival of external entities language aware.
Rijksmuseum API has the option for ie
- Dutch: https://www.rijksmuseum.nl/api/nl/collection
- English: https://www.rijksmuseum.nl/api/en/collection
To get the Nightwatch in:
- Dutch the code is https://www.rijksmuseum.nl/api/nl/collection/SK-C-5?key=fpGQTuED&format=...
- English https://www.rijksmuseum.nl/api/en/collection/SK-C-5?key=fpGQTuED&format=...
What we would like is that a bilingual website links to SK-C-5 and shows the English or Dutch version depending on the user language.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | external_entities-3018424-10.patch | 2.06 KB | clemens.tolboom |
Issue fork external_entities-3018424
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
hanno commentedComment #3
hanno commentedComment #4
hanno commentedComment #5
hanno commentedWe want to financially support this request if implemented in a sustainable way.
Comment #6
clemens.tolboomComment #7
clemens.tolboomA general version using placeholders of a list request would be
with response
So objectNumber is the id as language should be provided by Drupal.
and item would be
Comment #8
clemens.tolboomThe list items and single item are both processed through the field mapping. Either one fail as list items are in artObjects and singular item has content in artObject next to artObjectPage.
Not sure what is best.
Comment #9
hanno commentedlet's first enable multilangual support for an individual entity. Views search are also based on the individual items.
Comment #11
clemens.tolboomAttached patch adds alterURI code.
You can use (currently) two placeholders:
{langcode}{id}These can be used like
https://www.rijksmuseum.nl/api/{langcode}/collectionand is used fetching the list or a single item.The use of
{id}is for discussion as fetching a list or item has currently hardcoded ID position aka appending the IDhttps://www.rijksmuseum.nl/api/{langcode}/collection/XYZ-12Using
https://www.rijksmuseum.nl/api/{langcode}/collection/{id}as endpoint would fail for the list as ID is empty and is not scrubbed of the endpoint URI yet.Comment #12
clemens.tolboomWhat I tested was
Comment #13
clemens.tolboomComment #14
pefferen commentedFor me, the patch in #11 works for single items for placeholder {langcode}, I tested with the Rijksmuseum API as well.
With the {id} placeholder I get an 404 on said API, this is because the id is still appended in function `Rest::load($id)` . In this case we could append the ID at the end of the url, only if no '{id}' is present in the configured URL.
Comment #15
pefferen commentedThe patch to append the entity ID only when there is no '{id}' specified in the endpoint.
Comment #16
clemens.tolboomComment #17
davidferlay commentedHi guys,
Using {langcode} in External Entities configuration is helpful but it is arbitrary and implies that the API endpoint or parameter is expecting exactly the langcode value
https://www.api-endpoint-example.com/api/de/collectionbecausede={langcode}https://www.api-endpoint-example.com/api/german/collectionbecausegerman!={langcode}I believe we should adopt a more generic and Drupal-way approach to solve the multilingual need :
That would be very powerful, flexible and support all use-cases I can think of: different endpoints per language, different parameters, different field mapping, etc
Comment #18
andypostI think it could use event or hook to allow mapping for case when locale needs it - another case is
pt-BROtherwise it will need to decorate/replace plugin for custom needs
Comment #19
seorususHi guys,
I added a French interface translation.
Comment #22
piggito commentedFollowing suggestion at #17 I created MR https://git.drupalcode.org/project/external_entities/-/merge_requests/3 where I use config schema to expose "Field Mapping" and "Storage" settings to be translatable on UI.
Comment #23
piggito commentedComment #24
davidferlay commentedComment #25
davidferlay commentedThanks @piggito
Patch working as expected !
Comment #26
davidferlay commentedComment #28
pefferen commentedThanks for the work, the configuration translation seems the way to go, as it is more flexible and in line with the Drupal way.
Comment #29
pefferen commented