Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show only language dependent taxonomies #40

Open
Sogl opened this issue Oct 8, 2022 · 24 comments
Open

Show only language dependent taxonomies #40

Sogl opened this issue Oct 8, 2022 · 24 comments

Comments

@Sogl
Copy link

Sogl commented Oct 8, 2022

In my site I see all languages taxonomylist (PL and RU in my case):
image

How to show only current lang taxlist?

P.S. Is #22 a right workaround?

@mariekreativ
Copy link

Having the same experience as the OP, as described in this thread: https://discourse.getgrav.org/t/taxonomylist-is-displaying-the-tags-of-all-languages/23481

@marcocevoli
Copy link

Same here. It only changes to the correct language after I reload the page where the list is.

@skinofthesoul
Copy link

I would like to confirm that this problem is dependent on having LangSwitcher installed – in a fresh multilanguage Grav install the taxonomies are displayed only in their language, as expected. Adding LangSwitcher to the plugins results in all the tags of every language displayed.

@sebastian0119
Copy link

I partly agree with @skinofthesoul :
It has to do with LangSwitch, but I believe that it has to do specifically with caching.

I have a site with two languages (English + Spanish). Upon cleaning the cache and being located in either of the two languages, the tag list is fine. When switching to the other one, suddenly all tags from both languages are displayed.

Example: when located in Spanish, after clearing the cache and reloading the page, I get a clean list of tags in Spanish. If I then switch to English, I get a list of Spanish + English tags.

Sames works the other way round: when located in English, clear cache + reload page = clean list of tags in English. Then switching to Spanish results in list with English + Spanish.

@skinofthesoul
Copy link

Interesting! I just tried that on my fairly fresh test installation, and it does NOT work like that for me – clearing the cache has no effect on the muddled tags.

@rhukster
Copy link
Member

Can someone create a zip bundle of the exact setup for you that causes issues? I have not been able to replicate this issue with any of my multi-site setups.

@skinofthesoul
Copy link

Try this – languages are English and German, taxonomy list on the blog page shows three German tags and one English no matter what. Admin login is "admin" and "Admin1234!" (or copy in your own file of course).

@rhukster
Copy link
Member

rhukster commented Mar 18, 2024

Ok, so the root cause of this is langswitcher plugin. Specifically the newish translated URLs functionality. This works by looping though all the languges and building the routes up for the other languages. The unintended consequence of this is that it also re-initializes the taxonomy as part of that process. As it has already initialized once, for the 'active' language, it just keeps appending the other language's taxonomy to the taxonomy object.

This is a bit more fo a complex issue to solve that I had hoped for. I need to think of the best approach the keeps the translated URL functionality in langswitcher, but doesn't reinitialize everything causing taxonomy to get poluted with other languages. Alternatively I could rewrite how Taxonomy is processed and prefix everything with active language. This might be the better solution overall, but there could be other unforsee implciations.

Short tterm fix is to turn off that translated_urls feature in langswitcher.

@sebastian0119
Copy link

That's my setup, with some sample data.

I left the user/env configuration intact, because I have been testing with the built-in grav server. BTW: I do not even have to run a clearcache to reproduce this issue (which suggests that it maybe does not have to do with grav's internal cache?); I can just stop the built-in webserver and start it again and reproduce as described in my previous post.

I have been reluctant to upload this version to my formal webserver, but could eventually do so. There, an Apache is running. I can however reproduce the same issue on my local Apache.

@sebastian0119
Copy link

Short tterm fix is to turn off that translated_urls feature in langswitcher.

Yes, I can confirm this and this works currently for me. Thanks!

@rhukster
Copy link
Member

Try this – languages are English and German, taxonomy list on the blog page shows three German tags and one English no matter what. Admin login is "admin" and "Admin1234!" (or copy in your own file of course).

BTW, you need to rename your item.md files in article 2 and 3 to item.en.md.. this is part of your problem, but not the main issue as i've mentioned above.

@rhukster
Copy link
Member

I think i have a solution.. Please test with this replacement for system/src/Grav/Common/Taxonomy.php (backup the original file first:
Taxonomy.php.zip

@sebastian0119
Copy link

Yepp - works well for me!

@skinofthesoul
Copy link

Yes, perfect! Thank you!

@sebastian0119
Copy link

Sorry, but I need to pick this issue up again.

The fix worked for the taxonomy list in different languages. But I believe it broke something in page collections that are based on taxonomy options.

This is my frontmatter that works with the original version of Taxonomy.php (just the relevant parts):

title: Comercio
root_of_blog: true
content:
    items:
        - '@taxonomy.category': [comercio]
    limit: 6
    order:
        by: date
        dir: desc
    pagination: true
    url_taxonomy_filters: true

When applying the fix, I am getting the following error message:

Twig \ Error \ RuntimeError
An exception has been thrown during the rendering of a template ("Undefined array key "es"").

And it refers to …/system/src/Grav/Common/Taxonomy.php:150

You can see an example here, but being it a public site, there is not much more detail; I can provide additional detail and logs if required.

@rhukster
Copy link
Member

rhukster commented Apr 6, 2024

I'll take a look.

@rhukster
Copy link
Member

rhukster commented Apr 8, 2024

@sebastian0119 can you please provide the stacktrace for this error from the logs/grav.log file? I can't reproduce this.

@rhukster
Copy link
Member

rhukster commented Apr 8, 2024

Also would be super helpful if i could get a copy of your 'user' folder so i can test that and see what you are doing different to me. perahps put it up on cloud hosting somewhere, and send a link to devs @ getgrav.org.

@sebastian0119
Copy link

@sebastian0119 can you please provide the stacktrace for this error from the logs/grav.log file? I can't reproduce this.

Sure; please find attached the stacktrace from grav.log

@rhukster
Copy link
Member

rhukster commented Apr 8, 2024

The problem is the error is defnitely in the Twig.. So it's probably something with your theme. I'll need a copy of your site to debug further, but this error is not coming from Taxonomy.php that I can see.

@sebastian0119
Copy link

Also would be super helpful if i could get a copy of your 'user' folder...

Just sent it to you.

@sebastian0119
Copy link

The problem is the error is defnitely in the Twig.. So it's probably something with your theme. I'll need a copy of your site to debug further, but this error is not coming from Taxonomy.php that I can see.

Strange though, because be just switching out the modified system/src/Grav/Common/Taxonomy.php from above with the original one, the site runs fine, without making any changes to pages or templates.

Anyway, I sent you the user directory with a working (or not working ;-) ) example.

Thanks in advance.

@rhukster
Copy link
Member

rhukster commented Apr 8, 2024

I tested with your user folder and it worked fine for me. I suggest using this version: https://raw.githubusercontent.com/getgrav/grav/afb5b02e5750f0f9c0bcc73de5d3f62947881722/system/src/Grav/Common/Taxonomy.php

Couple of things:

  1. If you are using mulitlang while things generally 'work' with using default.md for your default language. You should rename all your default lang files to use .es.md. In the admin, it will cause weird situations where it might save a file as default.es.md and leave your 'old' default.md. Causing confusion as to which one is being used. You should also just do it for consistency.
  2. In your sidebar/default.md (aside from adding the .es, you should use markdown links rather than HTML. This will ensure the routes work in all setups. Right now all those links are broken for me in my testing site because i have a subdirectory. Alternatively, enable twig processing on the page and use the {{ url() }} function to fix the URLs.

@sebastian0119
Copy link

Yepp - the updated Taxonomy.php did the trick. Thanks so much.

And thanks for the recommendations! I'll implement them right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants