Generated with the help of an LLM.
Problem/Motivation
The attribution of the default OpenStreetMap base layer is defined in leaflet_leaflet_map_info() in leaflet.module as a raw string, without t():
'attribution' => '© <a href="https://www.openstreetmap.org/copyright" rel="noopener noreferrer">OpenStreetMap</a> contributors',
Because of this, the text cannot be translated through the interface translation system. On a non-English site the map shows an English attribution next to otherwise translated UI, and the string never appears in the locale source strings.
There is also no setting to add site-specific attribution to a map. Sites that show their own data on the map (for example an agency's records) have to add the text with CSS (.leaflet-control-attribution::before { content: "..." }) or by altering the map info in code. The CSS approach is not translatable and not accessible to assistive technology.
Steps to reproduce
- Install Drupal 11.4 with Leaflet 10.4.13, enable
localeandlanguage, and set the site (or interface) language to a non-English language such as Turkish. - Display any map with the default "OpenStreetMap" map (for example a Leaflet formatter or a Leaflet Views style).
- Look at the attribution control at the bottom right of the map: "© OpenStreetMap contributors" is shown in English.
- Search the user interface translation page for "contributors": the string is not offered for translation.
Proposed resolution
- Make the default attribution translatable, for example by building it with
t()and a link placeholder, keeping therel="noopener noreferrer"link intact. - Optionally add an "Additional attribution" text field to the map settings (formatter and Views style). The value is passed to the map and added with
attributionControl.addAttribution(), so it is rendered inside the standard control, filtered withXss::filterAdmin(), and can be translated as configuration.
The two parts could also be split into separate issues if the maintainers prefer.
Remaining tasks
- Maintainer feedback on whether to handle both parts here or split them.
- Check whether the result of
hook_leaflet_map_info()is cached in a way that needs a language context once the string is translated. - Check
leaflet_more_mapsand other map definitions for the same untranslated attribution strings. - Patch, tests (kernel test for the translated string; functional JavaScript test for the extra attribution text), review.
User interface changes
If part 2 is accepted: a new optional "Additional attribution" text field in the map settings. The default attribution becomes available on the interface translation page.
API changes
None expected. A new optional map setting key is added; existing maps are unaffected when it is empty.
Data model changes
If part 2 is accepted: one new optional string key in the Leaflet map settings config schema, with an update path that leaves existing values empty.
Comments