i18n_context twig helper for other than current document
BlackbitDevs opened this issue · comments
Use case: Link to localized document in the current language. For example if you had documents /de/impressum
and /en/imprint
and want to link to the correct page from the start page /de
or /en
. /de/impressum
and /en/imprint
are linked with the Localization Tool
Currently there is the i18n_context
twig helper but this can only fetch linked variants of current document (or am I missing something?).
Perhaps we could either add an option to call i18n_context
with another document than the current one.
Or even better would be if we introduced a twig helper which you can provide a document object (or its full path) and a locale - and you automatically get the URL for the document in the desired language (based on linked languages of the given document).
A twig helper would be the better way. Good one!
I spent way too much time on this :). But now, this is possible on dev-master.
In case you're still interested: https://github.com/dachcom-digital/pimcore-i18n/blob/master/docs/21_CustomI18nContextLookUp.md
We refactored the complete I18n bootstrap for this, but I think it was worth the time. The workflow is much cleaner now.
Would love to hear some feedback before we're going to tag this.
Love it!
The only thing I am wondering about:
{% set object_context = i18n_create_context_by_entity(pimcore_object(16), { _locale: 'en', object_id: 16 }) %}
Is there a difference to
{% set object_context = i18n_create_context_by_entity(pimcore_object(16), { _locale: 'en' }) %}
?
Or the other way around, what happens when doing
{% set object_context = i18n_create_context_by_entity(pimcore_object(16), { _locale: 'en', object_id: 123 }) %}
Good catch, I just pushed the correct examples. In your third example, the object_id: 123 would be ignored, since the entity property is stronger in i18n_create_context_by_entity
which will then call the corresponding link generator!
Ok, sounds good to me. Big thanks for the effort!