From 63aa34bac3d34a5fc6090526247f07bcfdc5db30 Mon Sep 17 00:00:00 2001 From: Jere Ljungberg Date: Wed, 18 Dec 2024 13:45:49 +0200 Subject: [PATCH 1/3] UHF-11176: Add addresslabel param to kartta.hel.fi links --- .../helfi_etusivu/src/Enum/ServiceMapLink.php | 8 +++--- .../custom/helfi_etusivu/src/Servicemap.php | 26 ++++++++++++++++++- .../custom/helfi_etusivu/translations/fi.po | 18 ++++++++++++- .../custom/helfi_etusivu/translations/sv.po | 16 ++++++++++++ 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/public/modules/custom/helfi_etusivu/src/Enum/ServiceMapLink.php b/public/modules/custom/helfi_etusivu/src/Enum/ServiceMapLink.php index 53b2d352..cbf2dfcc 100644 --- a/public/modules/custom/helfi_etusivu/src/Enum/ServiceMapLink.php +++ b/public/modules/custom/helfi_etusivu/src/Enum/ServiceMapLink.php @@ -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', }; } diff --git a/public/modules/custom/helfi_etusivu/src/Servicemap.php b/public/modules/custom/helfi_etusivu/src/Servicemap.php index bef3f60c..7b8dc2a5 100644 --- a/public/modules/custom/helfi_etusivu/src/Servicemap.php +++ b/public/modules/custom/helfi_etusivu/src/Servicemap.php @@ -6,6 +6,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\helfi_etusivu\Enum\ServiceMapLink; use GuzzleHttp\ClientInterface; @@ -31,6 +32,28 @@ 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 => t('Street works and events near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), + ServiceMapLink::CITYBIKE_STATIONS_STANDS => t('City bike stations and bicycle racks near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), + ServiceMapLink::STREET_PARK_PROJECTS => t('Street and park projects near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), + ServiceMapLink::PLANS_IN_PROCESS => t('Plans under preparation near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), + }; + } + /** * Constructs a new instance. * @@ -104,8 +127,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, ]; diff --git a/public/modules/custom/helfi_etusivu/translations/fi.po b/public/modules/custom/helfi_etusivu/translations/fi.po index 44444406..61838294 100644 --- a/public/modules/custom/helfi_etusivu/translations/fi.po +++ b/public/modules/custom/helfi_etusivu/translations/fi.po @@ -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" @@ -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 oleva kaavat lähellä osoitetta @address" diff --git a/public/modules/custom/helfi_etusivu/translations/sv.po b/public/modules/custom/helfi_etusivu/translations/sv.po index 4a9bd6a5..29a5d1ef 100644 --- a/public/modules/custom/helfi_etusivu/translations/sv.po +++ b/public/modules/custom/helfi_etusivu/translations/sv.po @@ -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" From 2f0d9d03ccb2e2841f2b672da362d9b6989a59d8 Mon Sep 17 00:00:00 2001 From: Jere Ljungberg Date: Wed, 18 Dec 2024 15:45:15 +0200 Subject: [PATCH 2/3] UHF-11176: Fix phpcs --- .../modules/custom/helfi_etusivu/src/Servicemap.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/public/modules/custom/helfi_etusivu/src/Servicemap.php b/public/modules/custom/helfi_etusivu/src/Servicemap.php index 7b8dc2a5..80168e44 100644 --- a/public/modules/custom/helfi_etusivu/src/Servicemap.php +++ b/public/modules/custom/helfi_etusivu/src/Servicemap.php @@ -6,6 +6,7 @@ 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; @@ -19,6 +20,8 @@ */ final class Servicemap { + use StringTranslationTrait; + /** * API URL for querying data. * @@ -32,7 +35,6 @@ final class Servicemap { */ private const SITE_URL = 'https://kartta.hel.fi/'; - /** * Gets the address label for a given service map link. * @@ -44,13 +46,12 @@ final class Servicemap { * @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 => t('Street works and events near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), - ServiceMapLink::CITYBIKE_STATIONS_STANDS => t('City bike stations and bicycle racks near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), - ServiceMapLink::STREET_PARK_PROJECTS => t('Street and park projects near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), - ServiceMapLink::PLANS_IN_PROCESS => t('Plans under preparation near the address @address', ['@address' => $address], ['context' => 'Helsinki near you address label']), + 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']), }; } From 8bdb7b7c97e0b73b6093bd4f0cd5c9b2c22cd15e Mon Sep 17 00:00:00 2001 From: Jere Ljungberg Date: Thu, 19 Dec 2024 09:39:55 +0200 Subject: [PATCH 3/3] UHF-11176: Fix sneaky typo --- public/modules/custom/helfi_etusivu/translations/fi.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/modules/custom/helfi_etusivu/translations/fi.po b/public/modules/custom/helfi_etusivu/translations/fi.po index 61838294..3bee9a9d 100644 --- a/public/modules/custom/helfi_etusivu/translations/fi.po +++ b/public/modules/custom/helfi_etusivu/translations/fi.po @@ -199,4 +199,4 @@ msgstr "Katu- ja puistohankkeet lähellä osoitetta @address" msgctxt "Helsinki near you address label" msgid "Plans under preparation near the address @address" -msgstr "Valmisteilla oleva kaavat lähellä osoitetta @address" +msgstr "Valmisteilla olevat kaavat lähellä osoitetta @address"