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 !
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3344293-event-dispatch.patch | 569 bytes | ekes |
| #5 | processor-dont-work-with-custom-langcode-3344293-5.patch | 608 bytes | gilles_webstanz |
Comments
Comment #2
ekes commentedYou 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.
Comment #3
gilles_webstanz commentedWow ! Thank you ekes ! I will do that.
Have a nice week !
Comment #4
gilles_webstanz commentedComment #5
gilles_webstanz commentedRe 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 !
Comment #6
gilles_webstanz commentedComment #7
gilles_webstanz commentedComment #8
ekes commentedRather than do that do you want to try this:
(also attached as a patch file).
Comment #9
gilles_webstanz commentedThank you ekes for this solution !
It works !
Have a nice day !
Comment #11
ekes commentedMany thanks for reviewing that. Sorry for the delay, now pushed into the 2.x branch. I'll make a new minor bugfix release.