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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

VISIOS created an issue. See original summary.

borisson_’s picture

I don't think that possible yet. I'd be grand to do this + have a test for it.

VISIOS’s picture

Joris, 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

borisson_’s picture

@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.

borisson_’s picture

Category: Support request » Bug report
Status: Active » Needs review
FileSize
3.61 KB

Patch + test attached. Config schema upgrade not yet included, doing that now.

borisson_’s picture

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.

borisson_’s picture

Status: Needs review » Fixed

Committed and pushed, thanks again @VISIOS

  • borisson_ committed dbc4750 on 8.x-1.x
    Issue #2893374 by borisson_: Translate url alias
    
VISIOS’s picture

Joris, 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

borisson_’s picture

Status: Fixed » Active

Reverting back to active, will take a look at this later this week.

borisson_’s picture

Status: Active » Needs review
FileSize
2.62 KB

Started work, doesn't work yet.

borisson_’s picture

FileSize
3.24 KB
2.8 KB

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.

borisson_’s picture

Issue tags: +Need tests

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.

borisson_’s picture

FileSize
2.75 KB
5.66 KB

Written a test, but no fix yet.

Status: Needs review » Needs work

The last submitted patch, 14: translate_url_alias-2893374-14.patch, failed testing. View results

borisson_’s picture

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.

VISIOS’s picture

Thanks 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.

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
2.51 KB
5.48 KB

Default/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.)

borisson_’s picture

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?

VISIOS’s picture

@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.

mr.baileys’s picture

Status: Needs review » Needs work

Hmm... That means we'll need to look at the test coverage in the patch and see what's lacking there...

mr.baileys’s picture

@VISIOS: just to be sure, you did clear your cache prior to testing after applying the patch?

VISIOS’s picture

@mr.baileys Yes, I did clear the cache after applying the patch.

borisson_’s picture

Status: Needs work » Needs review
FileSize
6.47 KB
1.5 KB

Adds the required testcoverage, but it doesn't pass yet.

Status: Needs review » Needs work

The last submitted patch, 24: translate_url_alias-2893374-24.patch, failed testing. View results

borisson_’s picture

Status: Needs work » Needs review
Issue tags: -Need tests
FileSize
1.37 KB
6.76 KB

Test should be green now.

StryKaizer’s picture

For 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

borisson_’s picture

Status: Needs review » Needs work

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.

borisson_’s picture

Status: Needs work » Needs review
FileSize
5.09 KB
5.57 KB

This applies #28.

borisson_’s picture

Status: Needs review » Needs work

This implemenatation will not work with pretty paths.

VISIOS’s picture

Thanks 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.

borisson_’s picture

I can repeat the problem. I expanded the testcoverage and now those fail as well. Trying to fix it.

borisson_’s picture

Status: Needs work » Needs review
FileSize
7.09 KB
8.13 KB

Improves test coverage and get's the code to pass them.

borisson_’s picture

FileSize
1007 bytes
8.37 KB
VISIOS’s picture

I 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.

borisson_’s picture

@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.

borisson_’s picture

Issue summary: View changes
FileSize
486.5 KB

So, I tested this with multiple facets and this works, here's a gif of it in action.

VISIOS’s picture

Probably 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?

borisson_’s picture

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

VISIOS’s picture

I 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!

borisson_’s picture

Status: Needs review » Needs work

I found the culprit: I did not set a key for the facet source. After setting a key the url alias is translated. Hooray!

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.

borisson_’s picture

Status: Needs work » Needs review

I can't reproduce that. To test I did the following:

  1. Uninstalled the facets module
  2. Installed the facets module
  3. Created a new facet, translated the url alias
  4. Placed the block
  5. Navigated to the search view, selected a facet and changed the language
VISIOS’s picture

Hi 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?

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Going to commit this later today.

borisson_’s picture

Status: Reviewed & tested by the community » Fixed

  • borisson_ committed 32fb92c on 8.x-1.x
    Issue #2893374 by borisson_, mr.baileys, VISIOS, StryKaizer: Translate...

Status: Fixed » Closed (fixed)

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