I'm using Leaflet to show various pins for content that has both English and Welsh content, using D8's Language and Content Translation modules.
Normally, I can see the translated content by visiting the language URL e.g. http://localhost/cy to see the Welsh content.
However, in my map view, the map popups are not translated, when using for the description.
Now, I could use the 'Body' but then the popup is missing the title, despite that being selected.
I added a new field specifically for the map popup description, but it's not selectable n the dropdown for some reason?
I also made a new view for the content type, but that didn't help, the content was still in English.
How do I get translations to work?
On a side note - I can only get Leaflet (Old) to work. The 'new' Leaflet format doesn't work at all for me. There are no options to configure it properly. What gives?
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | fix_non_translated_entities-2913312-10.patch | 1.02 KB | mdixoncm |
| #8 | fix_non_translated_entities-2913312-1.patch | 1.06 KB | paul_canning |
Comments
Comment #2
paul_canning commentedI have set this to critical because I have a client that is relying on this feature working.
After a bit of digging, it looks like that when the entity is loaded, it loads the correct content based on the language, but the `$entity->language()` method returns the default site language, even though I'm browsing the translated site using the URL method. So now I'm unsure if this is a Leaflet issue or a Drupal Core issues, or both?
Can't Leaflet just use the entity field content (as this is correct all the time)?
Comment #3
paul_canning commentedAny ideas about this one folks?
It's super important I get this resolved.
Comment #4
dpliscoff commentedHi, paul_canning
I dont have a concrete solution for the issue (haven't got deep in it myself) but as a workaround you can translate the texts through twig using the %trans% tag.
I'm using this inside a custom text field in the view for the popups, with URL translation detection at site level and "Interface text language selected for page" in the view settings, with three languages available in the site. e.g.:
hope it helps
Comment #5
paul_canning commentedSadly it doesn't, as I get this error:
Based on the info I provided above about how the correct translated content is found, but the rendering language is incorrect, are you able to look at patching this?
Comment #6
paul_canning commentedAny update on this issue please?
Comment #7
paul_canning commentedSo I located the issue exactly, and managed to work out a fix.
The issue is line 421 of LeafletMap.php
The issue is that for what ever reason, whilst the View will find the correct content based on the translation language being used to view the View, the default langcode is being spat out by
$entity->langcode()(infact, it should actually be$entity->langcode()->getId())If you replace
$entity->langcode()with\Drupal::languageManager()->getCurrentLanguage()->getId()(to get the current site translation code), the rendered entity for the popup is now correctly translated.What is odd, is that if you simply select the title or description for the popup, it is correctly translated.
Comment #8
paul_canning commentedComment #9
MaskOta commentedSetting to needs review because a patch was provided
Comment #10
mdixoncm commentedRe-rolled patch against latest dev version
Comment #11
itamair commentedHi folks ... sorry I cannot review this now. Is the last patch working properly? Might this be considered ready for commit into dev?
This issue seem to address the Leaflet View integration matter. Is the Leaflet Formatter affected by the same language problem?
Might this patch be integrated to fix also the Leaflet Formatter issue, eventually?
Please ... if someone can run a deeper and possibly final review on this and mark the issue as RTBC eventually.
Comment #12
itamair commentedthis seems already fixed in the last versions
Comment #13
itamair commented