Skip to content

Commit

Permalink
Merge pull request #807 from City-of-Helsinki/UHF-11176
Browse files Browse the repository at this point in the history
UHF-11176: Add addresslabel param to kartta.hel.fi links
  • Loading branch information
jeremysteerio authored Dec 19, 2024
2 parents af98db4 + 8bdb7b7 commit 73e8e7e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ enum ServiceMapLink {
*/
public function link(): string {
return match($this) {
ServiceMapLink::ROADWORK_EVENTS => 'eCBuut',
ServiceMapLink::CITYBIKE_STATIONS_STANDS => 'eCAduu',
ServiceMapLink::STREET_PARK_PROJECTS => 'eCBJGT',
ServiceMapLink::PLANS_IN_PROCESS => 'eCCv3K',
ServiceMapLink::ROADWORK_EVENTS => 'eDAB7W',
ServiceMapLink::CITYBIKE_STATIONS_STANDS => 'eDFeCc',
ServiceMapLink::STREET_PARK_PROJECTS => 'eDBTcc',
ServiceMapLink::PLANS_IN_PROCESS => 'eDB7Rk',
};
}

Expand Down
27 changes: 26 additions & 1 deletion public/modules/custom/helfi_etusivu/src/Servicemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Drupal\Component\Utility\Xss;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\helfi_etusivu\Enum\ServiceMapLink;
use GuzzleHttp\ClientInterface;
Expand All @@ -18,6 +20,8 @@
*/
final class Servicemap {

use StringTranslationTrait;

/**
* API URL for querying data.
*
Expand All @@ -31,6 +35,26 @@ final class Servicemap {
*/
private const SITE_URL = 'https://kartta.hel.fi/';

/**
* Gets the address label for a given service map link.
*
* @param \Drupal\helfi_etusivu\Enum\ServiceMapLink $link
* The service map link option.
* @param string $address
* The address for which the label is generated.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The address label corresponding to the service map link.
*/
private function getAddressLabel(ServiceMapLink $link, string $address) : TranslatableMarkup {
return match($link) {
ServiceMapLink::ROADWORK_EVENTS => $this->t('Street works and events near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']),
ServiceMapLink::CITYBIKE_STATIONS_STANDS => $this->t('City bike stations and bicycle racks near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']),
ServiceMapLink::STREET_PARK_PROJECTS => $this->t('Street and park projects near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']),
ServiceMapLink::PLANS_IN_PROCESS => $this->t('Plans under preparation near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']),
};
}

/**
* Constructs a new instance.
*
Expand Down Expand Up @@ -104,8 +128,9 @@ public function query(string $address, int $page_size = 1) : array {
public function getLink(ServiceMapLink $link, string $address) : string {
$langcode = $this->languageManager->getCurrentLanguage()->getId();
$query = [
'link' => $link->link(),
'addresslabel' => $this->getAddressLabel($link, $address),
'addresslocation' => Xss::filter($address),
'link' => $link->link(),
'setlanguage' => $langcode,
];

Expand Down
18 changes: 17 additions & 1 deletion public/modules/custom/helfi_etusivu/translations/fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ msgstr "Katu- ja puistohankkeet kartalla"

msgctxt "Helsinki near you"
msgid "Plans in process on map"
msgstr "Valmisteilla oleva kaavat kartalla"
msgstr "Valmisteilla olevat kaavat kartalla"

msgctxt "Helsinki near you"
msgid "Please enter an address"
Expand Down Expand Up @@ -184,3 +184,19 @@ msgstr "Yksi osoite-ehdotus löytyi."
msgctxt "Helsinki near you form"
msgid "@selectedItem @position of @count is highlighted"
msgstr "Vaihtoehto numero @position: @selectedItem korostettu. Vaihtoehtojen määrä: @count."

msgctxt "Helsinki near you address label"
msgid "Street works and events near the address @address"
msgstr "Katutyöt ja tapahtumat lähellä osoitetta @address"

msgctxt "Helsinki near you address label"
msgid "City bike stations and bicycle racks near the address @address"
msgstr "Kaupunkipyöräasemat ja pyörätelineet lähellä osoitetta @address"

msgctxt "Helsinki near you address label"
msgid "Street and park projects near the address @address"
msgstr "Katu- ja puistohankkeet lähellä osoitetta @address"

msgctxt "Helsinki near you address label"
msgid "Plans under preparation near the address @address"
msgstr "Valmisteilla olevat kaavat lähellä osoitetta @address"
16 changes: 16 additions & 0 deletions public/modules/custom/helfi_etusivu/translations/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,19 @@ msgstr "Det finns ett resultat tillgängligt."
msgctxt "Helsinki near you form"
msgid "@selectedItem @position of @count is highlighted"
msgstr "@selectedItem @position av @count är markerad"

msgctxt "Helsinki near you address label"
msgid "Street works and events near the address @address"
msgstr "Gatuarbeten och evenemang nära adressen @address"

msgctxt "Helsinki near you address label"
msgid "City bike stations and bicycle racks near the address @address"
msgstr "Stadscykelstationer och cykelställ nära adressen @address"

msgctxt "Helsinki near you address label"
msgid "Street and park projects near the address @address"
msgstr "Gatu- och parkprojekt nära adressen @address"

msgctxt "Helsinki near you address label"
msgid "Plans under preparation near the address @address"
msgstr "Detaljplaner under beredning nära adressen @address"

0 comments on commit 73e8e7e

Please sign in to comment.