jgazeau / shadocs

Shadocs Theme for Hugo
https://jgazeau.github.io/shadocs/
MIT License
51 stars 20 forks source link

[bug]: site with three languages: language switcher shows weird behaviour #156

Closed deining closed 1 year ago

deining commented 1 year ago

Steps that lead to the issue

Now start preview via hugo server.

Use the language switcher: it shows weird behaviour, you cannot switch properly to all three languages.

Expected behavior

Language switcher should behave correctly and switch properly to all three languages.

Reproducer

I can provide a GitHub repo for reproduction if needed. I don't think that is necessary, though.

Solution?

No response

jgazeau commented 1 year ago

Hi @deining ,

Indeed, don't know what I've made here but was not working indeed. It is fixed now, you can fetch the main branch 😉

deining commented 1 year ago

Hi @deining ,

Indeed, don't know what I've made here but was not working indeed. It is fixed now, you can fetch the main branch 😉

Hi Jojo,

I fetched the main branch and yes, it's working much better now.

There is a further issue, though:

How to repoduce:

git clone -b issue-156 https://github.com/deining/shadocs
cd shadocs/exampleSite
hugo server

Now visit http://localhost:1313/functionalities/: there is no German translation, but from the language selector, you actually can invoke the German translation (which displays an empty list page). I don't think this is the desired behaviour, I think the following code should prevent this from happening:

https://github.com/jgazeau/shadocs/blob/6ce47f9f8213d051e7dfb4b9c4202a1b76d64050/layouts/partials/theme/lang-selector.html#L26-L30

However, this code doesn't seem to have any effect, as demonstrated in my demo project:

https://github.com/deining/shadocs/blob/c43261d75579c4f7b6af35f93bb847cc9a8293cc/layouts/partials/theme/lang-selector.html#L37-L39

No error is thrown since translatedURL never equals an empty string.

Thanks for investigating!

jgazeau commented 1 year ago

@deining actually you are missing the _index.md file within the functionalities folder, but your folder is not empty which means that the folder and the url associated exist (Hugo is generating it automatically if at least one file exist in a folder). That's why you have the ban icon on the menu, because actually the url exists but the content is indeed empty as the physical file associated doesn't exists. If you add and index file in this folder the menu will be available correctly.

deining commented 1 year ago

@deining actually you are missing the _index.md file within the functionalities folder

I intentionally didn't put an _index.md file in the functionalities folder in order to simulate a constellation where no German translation is available (yet). Actual handling of this constellation is not optimal: German is shown in the language selector though there is no German translation available. Can this be improved?

jgazeau commented 1 year ago

I know but as I said, there is a url /de/functionalities because the folder functionalities is not empty. This is generated automatically by Hugo, and if you check the .Page.Translations content, you will see that there is actually a de translations. One solution would be to actually check for all translations found, try to retrieve the page content from the Url within the whole list of website pages, and if the content is empty do not display the translation....this is way to overkill for that specific case. Maybe you can ask in Hugo if there is something wrong with the translations or another way to check them.