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?

Comments

paul_canning created an issue. See original summary.

paul_canning’s picture

Priority: Normal » Critical

I 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)?

paul_canning’s picture

Any ideas about this one folks?

It's super important I get this resolved.

dpliscoff’s picture

Hi, 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.:

{% trans %}
<h4>{{ title }}</h4>
<small>{{ type }}</small>
<small>{{ description }}</small>
{% endtrans %}

hope it helps

paul_canning’s picture

Sadly it doesn't, as I get this error:

PHP message: Uncaught PHP Exception Twig_Error_Syntax: "The text to be translated with "trans" can only contain references to simple variables"

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?

paul_canning’s picture

Any update on this issue please?

paul_canning’s picture

So I located the issue exactly, and managed to work out a fix.

The issue is line 421 of LeafletMap.php

$build = $this->entityManager->getViewBuilder($entity->getEntityTypeId())->view($entity, $this->options['view_mode'], $entity->language());

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.

paul_canning’s picture

MaskOta’s picture

Priority: Critical » Normal
Status: Active » Needs review

Setting to needs review because a patch was provided

mdixoncm’s picture

Re-rolled patch against latest dev version

itamair’s picture

Hi 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.

itamair’s picture

this seems already fixed in the last versions

itamair’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.