We’re running a headless BloomreachDX instance which we expose via the HAL api to a microservice which receives call from the application.
For this application we expose content manageable labels for buttons etc through resourcebundles in multiple languages. If a translation isn’t found the HAL api returns the default resourcebundle. Basically we want the same functionality but for rich text for this (mainly) static system content. Without editing html manually in strings, but by using using something like the CKEditor.
We can think of multiple solutions. For example we can create a documenttype with a key and value (richtext) and customize the endpoint.
But we ‘feel’ there should be a simpeler solution. Any suggestions?
Hi Yves,
How about a document per richtext value item and using the standard hippo documentation translation feature? I mean:
- For example, if you look at https://cms.demo.onehippo.com/?1&path=/content/documents/hippogogreen/about/about, you will see the translation languages button next to “View” menu in the document editor. So business users are able to switch and edit each translated document easily.
- You can access an English content through /site/…/about.html or your specific Plain JAX-RS service URLs instead, for instance. For French, it could be /site/fr/…/about.html, depending on your host/mount configurations.
- Anyway, my point is, whether you use normal HstComponent or JAX-RS components, your custom code may switch to the default English content if a specific translated document is not found.
In this approach, end users are able to edit content in multiple locales more easily. You still have flexibility to construct mount/sitemap and content resolution whether you use hst component or rest api. If you have a specific document node type, then it’s also possible to provide a pagesable list view experience as well.
Just my two cents,
Woonsan
Thank you Woosan. Is it also possible, for that solution, to do a HAL api call with an xpath query in which you only use the root mount, with the path of the base version of that document, and return the matching translationid of a locale?
Yes, it should be possible. Mount mapped with a specific locale is just a layer on top of HST-2, the delivery tier, not JCR level. So, using xpath to select a different content with parameters including the translation locale property of a document should work.
Woonsan
Great. Unfortunately I’m not quite getting the query working…
This works to get the required translationid
//element(*, myhippo:mydocument)[(@myhippo:title, ‘Example title’)]/@hippotranslation:id
And this works to get the required document based on the translation id
//element(*, myhippo:mydocument)[@hippotranslation:id=‘31e740fe-8247-4efe-81e7-f16c558c3707’ and hippotranslation:locale=‘no’]
Now I would like to to the above in a single action.
//element(*, myhippo:mydocument)[@hippotranslation:id=’{TRANSLATION ID of DOCUMENT X FOUND BY TITLE}’ and hippotranslation:locale=‘no’]
My current request
http://localhost:8080/site/api/myhippo:mydocument?_scope=/content/documents&_expr=(@hippotranslation:id=‘6c5a8b63-d30a-48cf-baf2-36feb49556b4’ and @hippotranslation:locale=‘gb’)
Any suggestions?
I can’t find any option to make it in single query.
One possible option is:
- Suppose you define a new document type, myhippo:mydocument, to keep those richtext based variations with key field(s) (title or whatever).
- Basically, make a JCR query against the default language always, not translated language directly.
- Then add a custom JcrContentHalResourceProcessor [1] to decorate the result if the node type is ‘myhippo:mydocument’, by reading any custom parameter (i.e,
RequestContextProvider.get().getServletRequest().getParameter("lang");
), finding if there’s a translated document (see HippoDocumentBean#getAvailableTranslations()
[2]) for the default locale document and finally injecting some more translated data into the resource
if found.
Regards,
Woonsan
[1] https://www.onehippo.org/library/enterprise/services-features/content-hal-api/customizing-the-content-hal-add-on.html
[2] https://www.onehippo.org/library/concepts/content-beans/get-all-available-translations-of-some-folder-or-document-in-a-jsp.html
1 Like
Thank you. I think that indeed wil become our strategy.