- Issue created by @gilles_webstanz
- 🇳🇱Netherlands ekes
You can use the language event that gets called [https://git.drupalcode.org/project/snowball_stemmer/-/blob/2.x/src/Stemm... to do just that.
The module uses it, so these are examples of implementations of the event https://git.drupalcode.org/project/snowball_stemmer/-/tree/2.x/src/Event...
One of those subscribers does in fact do what you want (almost) https://git.drupalcode.org/project/snowball_stemmer/-/blob/2.x/src/Event...Because the (I think IETF) way of writing language codes is 'en-gb' (British English), 'en-za' (South African English), 'de-at' (Austrian German), 'fr-be' (Belgian French). Drupal an example 'pt-br' in it's standard language list https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/lib/Drupal/...
With the event your, I think site specific as it's the other way round case, can be covered by implementing the event subscriber in a site module.
- 🇧🇪Belgium gilles_webstanz
Wow ! Thank you ekes ! I will do that.
Have a nice week !
- Status changed to Closed: works as designed
over 1 year ago 7:42am 27 February 2023 - 🇧🇪Belgium gilles_webstanz
Re Ekes,
The EventSubscriber didn't work for me...
The reason the code didn't work is that it never passed into the languageCodeAlter function.
In the getSubscribeEvents function, the event name is 'Drupal\snowball_stemmer\Event\SetLanguageEvent' and not the constant SetLanguageEvent::LANGUAGE_CODE ( = 'snowball_stemmer.set_language_code' ).
The patch must surely be improved. I'm posting a patch that solved my problem.
Have a nice day !
- Status changed to Needs work
over 1 year ago 9:44am 27 February 2023 - 🇳🇱Netherlands ekes
Rather than do this do you want to try this:
diff --git a/src/Stemmer.php b/src/Stemmer.php index fd9129e..56e6bf0 100644 --- a/src/Stemmer.php +++ b/src/Stemmer.php @@ -70,7 +70,7 @@ class Stemmer { public function setLanguage($language) { try { $language_event = new SetLanguageEvent($language); - $this->eventDispatcher->dispatch($language_event); + $this->eventDispatcher->dispatch($language_event, SetLanguageEvent::LANGUAGE_CODE); $this->stemmers[$language] = StemmerFactory::create($language_event->getLanguageCode()); $this->language = $language; return TRUE
(also attached as a patch file).
- Status changed to Needs review
over 1 year ago 7:21am 15 March 2023 - 🇧🇪Belgium gilles_webstanz
Thank you ekes for this solution !
It works !
Have a nice day !
- Status changed to Fixed
over 1 year ago 2:17pm 1 April 2023 - 🇳🇱Netherlands ekes
Many thanks for reviewing that. Sorry for the delay, now pushed into the 2.x branch. I'll make a new minor bugfix release.
Automatically closed - issue fixed for 2 weeks with no activity.