mapbox-gl-geocoder icon indicating copy to clipboard operation
mapbox-gl-geocoder copied to clipboard

Translate error labels

Open lapchenkovbyu opened this issue 5 years ago • 9 comments

Hi everyone!

Even when 'de-DE' locale for geocoder is set (as it is referenced at example), 'No resutls found' error is displayed in English, rather then in locale selected.

Expected behavior: Localized error output.

Example may be found here - official documentation page Screenshot from 2019-12-16 16-08-50

lapchenkovbyu avatar Dec 16 '19 15:12 lapchenkovbyu

Hi! This isn't yet implemented. The codebase was recently enhanced to allow the search placeholder to be localised by default, so this could be extended to include the other error text strings.

See https://github.com/mapbox/mapbox-gl-geocoder/blob/master/lib/localization.js

Are you interested in submitting a PR to implement this? I'm happy to help review one.

andrewharvey avatar Dec 16 '19 21:12 andrewharvey

I’m not sure if I am able to invest some time right now, but it’s definitely a nice little thing to do. If it will be still open as soon as I will have some free time- I will definitely make an effort

пн, 16 дек. 2019 г. в 23:48, Andrew Harvey [email protected]:

Hi! This isn't yet implemented. The codebase was recently enhanced to allow the search placeholder to be localised by default, so this could be extended to include the other error text strings.

See https://github.com/mapbox/mapbox-gl-geocoder/blob/master/lib/localization.js

Are you interested in submitting a PR to implement this? I'm happy to help review one.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-gl-geocoder/issues/328?email_source=notifications&email_token=AG7NCSDVDSB6ICKG6PYAG4TQY7ZUJA5CNFSM4J3LM3VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHAG5BA#issuecomment-566259332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG7NCSB3TZ3EHH74MP5UWDTQY7ZUJANCNFSM4J3LM3VA .

lapchenkovbyu avatar Dec 17 '19 01:12 lapchenkovbyu

Hey guys,

I found a workaround to this issue using the DOMSubtreeModified event listener. I added this event listener to the 'suggestions' class that holds the 'No results found' message. In the code below I'll show how to translate this message and the 'Search' placeholder of the search input as well. I'm working with angular btw.

  setupGeocoder() {
    var geocoder = new MapboxGeocoder({
      accessToken: Mapboxgl.accessToken,
      language: 'pt-BR',
      mapboxgl: Mapboxgl
    });

    // Place the search input outside the map
    document.getElementById('geocoder').appendChild(geocoder.onAdd(this.map));

    // Translate the search input placeholder
    document.getElementsByClassName('mapboxgl-ctrl-geocoder--input')[0].setAttribute('placeholder', 'Pesquise por cidade, rua, bairro ou CEP');

    // Translate the 'no records found' message
    document.getElementsByClassName('suggestions')[0].addEventListener("DOMSubtreeModified", this.onChange.bind(this));
  }

  onChange(event) {
    if (event.path[0].innerText === "No results found") {
      event.path[0].innerHTML = event.path[0].innerHTML.replace("No results found", "Nenhum resultado encontrado.");
    }
  }

gregoryscode avatar Jun 16 '20 02:06 gregoryscode

Thank you for your idea, though grabbing element from a DOM tree directly is on surface, and was never considered a good practice. I think we can do something about this in a nearest future, as I have some time now for this kind of entertainment ;-)

Regards

вт, 16 июня 2020 г. в 05:40, Gregory Perozzo [email protected]:

Hey guys,

I found a workaround to this issue using the DOMSubtreeModified event listener. I added this event listener to the 'suggestions' class that holds the 'No results found' message. In the code below I'll show how to translate this message and the 'Search' placeholder of the search input as well. I'm working with angular btw.

setupGeocoder() { var geocoder = new MapboxGeocoder({ accessToken: Mapboxgl.accessToken, language: 'pt-BR', mapboxgl: Mapboxgl });

// Place the search input outside the map
document.getElementById('geocoder').appendChild(geocoder.onAdd(this.map));

// Translate the search input placeholder
document.getElementsByClassName('mapboxgl-ctrl-geocoder--input')[0].setAttribute('placeholder', 'Pesquise por cidade, rua, bairro ou CEP');

// Translate the 'no records found' message
document.getElementsByClassName('suggestions')[0].addEventListener("DOMSubtreeModified", this.onChange.bind(this));

}

onChange(event) { if (event.path[0].innerText === "No results found") { event.path[0].innerHTML = event.path[0].innerHTML.replace("No results found", "Nenhum resultado encontrado."); } }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-gl-geocoder/issues/328#issuecomment-644496215, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG7NCSEGGAP7FFR77KWKZZTRW3LR5ANCNFSM4J3LM3VA .

lapchenkovbyu avatar Jun 16 '20 06:06 lapchenkovbyu

I can pass a locale option when instantiating a new map. Something like this for the geocoder GUI would be very nice indeed!

kreba avatar Aug 28 '20 14:08 kreba

+1

knitzie2 avatar Sep 21 '21 11:09 knitzie2

Hey guys,

I found a workaround to this issue using the DOMSubtreeModified event listener. I added this event listener to the 'suggestions' class that holds the 'No results found' message. In the code below I'll show how to translate this message and the 'Search' placeholder of the search input as well. I'm working with angular btw.

  setupGeocoder() {
    var geocoder = new MapboxGeocoder({
      accessToken: Mapboxgl.accessToken,
      language: 'pt-BR',
      mapboxgl: Mapboxgl
    });

    // Place the search input outside the map
    document.getElementById('geocoder').appendChild(geocoder.onAdd(this.map));

    // Translate the search input placeholder
    document.getElementsByClassName('mapboxgl-ctrl-geocoder--input')[0].setAttribute('placeholder', 'Pesquise por cidade, rua, bairro ou CEP');

    // Translate the 'no records found' message
    document.getElementsByClassName('suggestions')[0].addEventListener("DOMSubtreeModified", this.onChange.bind(this));
  }

  onChange(event) {
    if (event.path[0].innerText === "No results found") {
      event.path[0].innerHTML = event.path[0].innerHTML.replace("No results found", "Nenhum resultado encontrado.");
    }
  }

it work for me!! thanks!!

pnavarretec01 avatar Mar 21 '22 20:03 pnavarretec01

CSS solution: .mapbox-gl-geocoder--no-results { display: none; }

luisdoniad avatar Jan 26 '23 11:01 luisdoniad

..mmh, i was able to work around with:

    geocoder.on('results', () => {
        const noResults = document.querySelector('.mapbox-gl-geocoder--error.mapbox-gl-geocoder--no-results')
        if (noResults) {
          noResults.innerHTML = 'Keine Strassennamen in Basel gefunden.'
        }
      })

dev7ch avatar Mar 02 '23 14:03 dev7ch