Problem/Motivation

Hello everyone,

The module doesn't work on one of my projects where there are custom langcodes.

I have several different langcodes for a "same language" and in the part of the code that fetches the langcode, the module tries to associate it with a base langcode.

Example: fr-fr and be-fr for French from France and French from Belgium. Same for Dutch and German.

So I added conditions for the module to work.

This solves my problem but I don't know how to solve the problem in a more general way.

Proposed resolution

Maybe retrieve all langcodes and check if there is a part of a basic langcode in the custom langcodes (Ex: fr in be-fr).

I hope I've made myself clear. I still propose my patch even if it is very specific...

Have a nice day !

Comments

gilles_webstanz created an issue. See original summary.

ekes’s picture

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.

gilles_webstanz’s picture

Wow ! Thank you ekes ! I will do that.

Have a nice week !

gilles_webstanz’s picture

Status: Active » Closed (works as designed)
gilles_webstanz’s picture

StatusFileSize
new608 bytes

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 !

gilles_webstanz’s picture

gilles_webstanz’s picture

Status: Closed (works as designed) » Needs work
ekes’s picture

StatusFileSize
new569 bytes

Rather than do that 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).

gilles_webstanz’s picture

Status: Needs work » Needs review

Thank you ekes for this solution !

It works !

Have a nice day !

  • ekes committed 54e2c96d on 2.x
    Issue #3344293 by gilles_webstanz, ekes: Processor doesn't work with...
ekes’s picture

Status: Needs review » Fixed

Many thanks for reviewing that. Sorry for the delay, now pushed into the 2.x branch. I'll make a new minor bugfix release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.