Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi there,
I'm trying to use Facets on a multilingual site and have some problems to make urls work in different languages.
Is Facets suitable for multilingual sites at all when we want to have translated urls? I have added an url alias for my view in a different language but when clicking the facets links, it will alway link to the original view path.
Is it possible to translate the url alias of a facet? The module prints the translated term name of a taxonomy, this is fine, but the generated URL uses the facets' url alias which seems not the be translatable.
Thanks in advance,
Sev
Comment | File | Size | Author |
---|---|---|---|
#34 | translate_url_alias-2893374-34.patch | 8.37 KB | borisson_ |
Comments
Comment #2
borisson_I don't think that possible yet. I'd be grand to do this + have a test for it.
Comment #3
VISIOS CreditAttribution: VISIOS commentedJoris, thanks for replying quickly. I'm impressed with the Facets module but the missing multilingual capabilities is kind of a deal breaker for me.
I'd be very happy to have a multi language solution for that. I can help testing but my coding skills would not really be helpful.
As this feature is crucial for a client project, I can sponsor the development of this feature. Are you interested in paid work to make this feature happen?
Thanks,
Sev
Comment #4
borisson_@VISIOS I don't have a self-employed status - but I asked my bosses here and we'd be willing to do this trough the company. I also wouldn't mind doing this in my own time. But having the time to do this during the day should help get this done a lot sooner.
If you'd like; you can contact me trough joris.vercammen@dazzle.be - I'll forward the request to my boss and he'll get back to you with a quote.
Not sure if you'd like me to do just this issue - or also do #2827808: Facets on multilangual site. (which is also multilingual-related), but having the time to write a decent test-case for this issue will make it easier to fix the other issue as well.
Comment #5
borisson_Patch + test attached. Config schema upgrade not yet included, doing that now.
Comment #6
borisson_I just looked into an upgrade path, and looks like that is not needed, doing a cache-rebuild is sufficient for the translatable field to be picked up.
Comment #7
borisson_Committed and pushed, thanks again @VISIOS
Comment #9
VISIOS CreditAttribution: VISIOS commentedJoris, thank you for you work on this feature. I just ran some tests on this using the alpha-11 with query strings as url processor as I still having problems with facets pretty paths.
It's now working very well with an URL alias for the view path. The correct path for the other languages is picked up when changing languages via the language switcher. Thumbs up!
Translating the URL alias that identifies the facet also works fine but only when I stay on that language or use the navigation to get to the facets page without any parameters. Using the language switcher the url alias for the facet is not translated resulting in a mismatched url that has no connection to the facet. The expected user behaviour would be to show the faceted search in the other language.
E.g. facet for filtering different product categories
facet URL alias in german: produkte
translated facet URL alias in english: products
german: /de/facets?f%5B0%5D=produkte%3A1 (one taxonomy term in facet selected)
clicking the language switcher results in:
english: /en/facets-en-url?f%5B0%5D=produkte%3A1
Is this possible to fix?
Best,
Severin
Comment #10
borisson_Reverting back to active, will take a look at this later this week.
Comment #11
borisson_Started work, doesn't work yet.
Comment #12
borisson_Refactored the code to be easier to read, it currently almost works.
Will need to write a test as well to check this behavior, when we have that, it might be easier to find out the reason why it's currently only working in one direction. I'm sure I'm missing something but I can't seem to find how to resolve it.
Comment #13
borisson_I've tried writing a test for this, but I can't seem to find a way to fix this. I also don't know how to fix the actual issue.
I'm going to need some help on this.
Comment #14
borisson_Written a test, but no fix yet.
Comment #16
borisson_I spent another hour looking at this today and I have no clue how to resolve this, I'm going to leave this waiting 'till drupalcamp Antwerp/Drupalcon, where there's other people around to help with this issue.
Comment #17
VISIOS CreditAttribution: VISIOS commentedThanks for the update Joris and the prospect of getting this done with the help of others. I guess I'm using a workaround
of using one short url alias for all languages for now (e.g. 'p' for a facets filtering products, 'c' for a facet filtering color. Not very good for SEO and speaking URLs. My project is due in october therefore there might be a solution which would be awesome.
Thankfully the url alias for the view path is now picked up which was a real blocker for using facets. Thanks for your work on fixing this.
Comment #18
mr.baileysDefault/source language does not have a language override, so I think the current patch fails when trying to get an override for the source language, which does not exist. Rather than working with/querying the language overrides ourselves, we should just use the existing pattern for working with translated config (see "Language overrides" in https://www.drupal.org/docs/8/api/configuration-api/configuration-overri...).
Patch attached (interdiff against re-rolled patch from #14, tests should pass.)
Comment #19
borisson_Thanks so much for helping figuring this out @mr.baileys. I'll have a better look at the patch when I get home from vacation but at first glance this looks very solid.
@VISIOS, can you test this patch to see if it fixes your previous problem?
Comment #20
VISIOS CreditAttribution: VISIOS commented@mr.baileys Thanks for you patch. I tried it with latest 8.x-1.x-dev and the patch applied cleanly.
@borisson_ Unfortunately it did not solve the problem with the translated name of facet that is used in the URL. When switching languages, the facet name in the URL stays the same.
Comment #21
mr.baileysHmm... That means we'll need to look at the test coverage in the patch and see what's lacking there...
Comment #22
mr.baileys@VISIOS: just to be sure, you did clear your cache prior to testing after applying the patch?
Comment #23
VISIOS CreditAttribution: VISIOS commented@mr.baileys Yes, I did clear the cache after applying the patch.
Comment #24
borisson_Adds the required testcoverage, but it doesn't pass yet.
Comment #26
borisson_Test should be green now.
Comment #27
StryKaizerFor the url_alias part, I would use label type for the url_alias property, which should fix this for every url processor, no?
Did not check the facet_source path translation part, but I guess we should take into account url aliasses for views_page facet sources when retrieving the facet source url (and isBeingRendered).
Not sure we should create an extra processor for this
Comment #28
borisson_Just discussed this with @StryKaizer and we shouldn't make this work with an outbound processor but instead we should use https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Language%.... That's much more lightweight and a more targetted solution to the problem.
Back to needs work. If we get the test to pass with that hook that would be great. Possibly we'll have to do this after #2861586: Make it easier to programmatically generate facet links is resolved, or we should extend that api to include a
$language
parameter.Comment #29
borisson_This applies #28.
Comment #30
borisson_This implemenatation will not work with pretty paths.
Comment #31
VISIOS CreditAttribution: VISIOS commentedThanks for the update Joris.
Unfortunately the "facet url alias" stays the same when switching languages via the language switcher link. I'm not using pretty paths, the patch applied cleanly, I did run drush cr, and tried with drupal 8.3.5 and 8.4.1.
Comment #32
borisson_I can repeat the problem. I expanded the testcoverage and now those fail as well. Trying to fix it.
Comment #33
borisson_Improves test coverage and get's the code to pass them.
Comment #34
borisson_Comment #35
VISIOS CreditAttribution: VISIOS commentedI tested the patch which applied cleanly but unfortunately the link is not using the translated url alias in the language switcher after a drush cr.
Comment #36
borisson_@VISIOS, I don't understand, I've written so much testcoverage for this now. I don't get why it's not working. I've tested it locally and it works. As you can see by the coverage I created and translated the url alias into 4 languages and then switch between the different languages to see if the facet is updated.
Do you happen to have multiple facets on the same page? That's the only usecase that I haven't tested yet - but it should work, I think.
Comment #37
borisson_So, I tested this with multiple facets and this works, here's a gif of it in action.
Comment #38
VISIOS CreditAttribution: VISIOS commentedProbably we're talking about different things. When I translate the "name of facet used in the url" (see: Setting) this name/parameter is not changed in the URL when switching languages. This means that an english URL is using the german name of the facet and vice versa.
Please see this screencast: https://www.drupal.org/files/issues/facets-url-alias.gif
I dont't know if this doable at all but it somehow breaks a solid multilanguage URL structure. Especially when we are able to use pretty urls someday, when Facets Pretty Path is working stable).
Do you understand what I mean in comparison to your findings and tests?
Comment #39
borisson_I understand what you mean, that's exactly the usecase I tested as well, I was using
cb9f66dc2e055150dbd7df6c44380b281fe0fe75
as the facets-version when testing, (dev release of 3 days ago), this should still work with the most recent dev version, are you using that version or an older version of facets?In the testing I was doing you can also see the "author" url alias changing when clicking the language switcher - but it's too small to see when embedded in the issue, the full view might be easier: https://www.drupal.org/files/issues/facets.gif
Comment #40
VISIOS CreditAttribution: VISIOS commentedI found the culprit: I did not set a key for the facet source. After setting a key the url alias is translated. Hooray!
Because the field is not mandatory I somehow ignored it. Probably this has to be set mandatory or the explanation should state, that this is also recommended to use translated aliases.
Anyhow, thanks for your excellent work on this!
Comment #41
borisson_We shouldn't make that a hard requirement, if that's happening this might be a bug that we need to fix. I'll look into this. Setting this to needs work to investigate. If it turns out to be a bug - I'll open a new issue.
This can go back to needs review if:
1. I can't reproduce that behavior,
2. A new issue is opened detailing the problem.
Comment #42
borisson_I can't reproduce that. To test I did the following:
Comment #43
VISIOS CreditAttribution: VISIOS commentedHi Joris, I did the same steps as you (with latest dev from 11. Nov) but I again had to set a key for the facet search to get a translated url alias. Perhaps somebody else can test this and report back?
Comment #44
borisson_Going to commit this later today.
Comment #45
borisson_