Hi all,
I'm building a multilingual site and would like to have 2 different urls for my section list page.
The content is as follows:
|___product
|___ _index.md
|___ product-1.md
|___ product-1.fr.md
Currently, by default, hugo generates /product and /product/product-1 which is expected.
For multilingual purpose, I want to achieve:
English:
/product
/product/product-1
French:
/produit
/produit/produit-1
I can achieve /produit/produit-1 by permalinks configuration in config.toml but I don't know how to generate /produit one which will still use my section template page under theme/layouts/section/product.html (same for both language).
Any idea would be very appreciated.
Thanks a lot.
P/S: I tried with putting url and slug in _index.md and that seems not working although the content of the file is picked up correctly in the template.
This is issue is referenced by this discussion.
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
Just thought I'd chime in and say that this is my single biggest issue using Hugo at the moment, and I think probably the only major roadblock to really powerful multilingual sites.
In my case, I have for example a notes section. In English, I want that section to have the title "Notes", the list page to appear at http://example.com/notes/, and the pages to be at eg. http://example.com/notes/on-making-a-website.html.
But, in Japanese, I need that section to have the title 鎰忚 (iken), the list page to appear at http://example.com/ja/iken/ and the pages to be at eg. http://example.com/ja/iken/saito-wo-tukuru.html.
At the moment, I can get the subpages to have the correct output path (http://example.com/ja/iken/saito-wo-tukuru.html), by using
Languages:
ja:
permalinks:
notes: /iken/:slug
in my config.yaml, but the list page permalink will still come out at http://example.com/ja/notes/.
Even using rewrite rules on Netlify, and throwing some hack-y code into templates and shortlinks using a Param listing these problem sections (ie. index .Site.Params.slugPatches (.Get 0)), I still can't get the permalinks in .Translations to match up.
It means I can't have a URL that makes sense in the target language, and there's no possible workaround that I can find.
On the other hand, if the section's output folder was named after the slug value in the section's frontmatter, just like for single pages, the system would work perfectly (and make a lot of immediate sense). Sections could be correctly translated, and the pages in the sections would have a correctly translated path.
Then, in /content/notes/_index.ja.md I could just put
---
title: 鎰忚
slug: iken
---
instead of all those workarounds/.Site.Params/redirect rules.
I have the same issue now, trying to switch to hugo for an existing site. The concept of _index.[lang].md files for sections is great, and it's one of the biggest issues.
Hi,
I would like to outline the need of this functionality a bit more. Starting with the following three threads in the forum, which are all (more or less) related to this matter. Some of them even explain how to work around this, which, in some case, might actually be applicable.
Multi language support and the need for translating parts of an url is, IMHO, one of the most reasonable use cases for overwriting section names with it's language-specific counterpart.
Yes, it is possible to accomplish that with the permalink configurations in hugo's config. file - as described in the forums. Though, it only works for the first level in the folder structure. Deeper sub-sections can't be overwritten with this approach.
Ideally, the slug parameter in the front matter for /content/section-name/subsectionA/_index.en.md would overwrite subsectionA in the output. I could also think of some build step, where section names get checked with the i18n function against existing translations (e.g. in hugolib/permalinks.go). An existing translation would then replace the original section name.
If anybody has other ideas, feel free to share them.
Hopefully, with this I was able to emphasize a bit more on the realness of this feature request.
@bep, I would love to see you starting to take this issue a bit more serious, even though the feature might not be important for you personally.
The guy is releasing patches twice a week give him a break. I'm just reacting to this last paragraph.
Now .34 resolves the section slug issue. You can now add one to your section _index.md.
Yet it still doesn't solve your problem ?
My posts are stored in content/post and yet, my section slug is /blog thanks to .34
https://regisphilibert.com/blog/
Without a doubt, all contributors do an amazing work and I am very thankful for all their effort. I was just citing his own words, which, at least to me, seems to show a bit of an inappropriate attitude in that context.
Regarding .34, I couldn't find any hint of this issue being solved in the release. I already installed the latest release and noticed no difference in the behaviour already described.
Currently, I am also thinking about creating a commercial multi-language website with Hugo and I really like the multi-language support Hugo offers, it makes it really easy and you can see the time and hard work which were invested by contributors, but I have one deal breaker and that is that I didn't find any way to override the section URL. Without the support of overridable sections is the multi-language support good but not usable in anything but private blogs.
So I would really appreciate the enhancement else the only other way to create a commercial multi-language website would to create for each language there own Hugo project which makes it viable but that's it.
The guy is releasing patches twice a week give him a break. I'm just reacting to this last paragraph.
Now .34 resolves the section slug issue. You can now add one to your section _index.md.
Yet it still doesn't solve your problem ?
My posts are stored in content/post and yet, my section slug is /blog thanks to .34
https://regisphilibert.com/blog/
@regisphilibert
Can you maybe link or post a example code, would appreciate it. Because it has no effect in my multi-language setup.
Hi,
This is currently the only issue we've identified preventing us from moving from Drupal to Hugo. Hopefully, there will be a way to achieve that in a future update.
@jonjbar Does the solution @regisphilibert posted here solve your issue? https://github.com/gohugoio/hugo/issues/3354#issuecomment-359936838
@budparr I already mentioned above, and happily confirm again that https://github.com/gohugoio/hugo/issues/3354#issuecomment-359936838 does not work for me (v0.36.1). Maybe @regisphilibert has some permalinks applied in the global config file, but again, that approach wont work for nested sections and is merly a workaround.
@lucendio I understand your problem and yes my comment can help you. I was able to achieve multilingual subsection url overriding using 0.37.
You do have to mention the parent section new url in the subsection url parameter.
If you point me to a repo of some sort I'd try and take a look.
Cheers.
@regisphilibert Interesting. Would you mind posting a simple example or point me to the section in the docs showing how to achieve this?
Any hint or enlightenment is much apprechiated. (the repo of concern can be found here)
thx, L
Ok give it a look here: https://github.com/regisphilibert/rp_hugo/tree/greeting-test/
You're not going to be able to fork it as is because the theme is a private submodule but you can still download it and use any theme of your chosing.
Then, look at config.toml where permalinks are set.
And then inside content/post, you'll find the __greeting__ sub section. Give it a look.
I didn't have time to check templates for it, but if you compile Hugo, you'll see the directory are generated the way you want.
@regisphilibert Thank you for the sample. Still learning Hugo here but I believe that this is working due to the fact that you have only one section with the following in your config.toml file:
[languages.fr.permalinks]
post = "blogue/:year/:month/:slug/"
Without that, and if you have multiple sections (e.g. have "blog" section and "products" section...) you can't use the _index.md trick to override the URL of sub-pages.
In other words, you can't have multiple translatable sections:
/blog/ -> /blogue
/product -> /produit
...
Or perhaps I am missing something ?
Are you saying that (from config.toml)
[languages.fr.permalinks]
post = "blogue/:year/:month/:title/"
product = "produit/:title"
is not working ?
@regisphilibert thank you for the example. But sadly this still does not work for sub-sections or scales for multiple sections (as @jonjbar pointed out). The user experience I'd like to see, or I think this thread here is looking for, is described here. In short, it's something around the lines of, the ability to overwrite slug (meaning the part of the url for its specific path level) in its corresponding _index.[$Lang].md front matter.
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
any news on this?
This. Feature. Would. Be. Really. Awesome.
I came up with a solution supporting nested sections assigning custom slugs
for each language, no matter their depth in dir structure. It requires:
~
[languages]
[languages.en]
contentDir = "content/en"
languageName = "English"
weight = 10
[languages.es]
title = "Sitio ..."
contentDir = "content/es"
languageName = "Espa帽ol"
weight = 20
~
Set translationKey for _index.md and pages and their slug as
directory name or filename; I use the slug of the
section/page being translated as the translation key, for example for
/content/en/foo/_index.md:
EN: /content/en/foo/
translationKey = "foo"
ES: /content/es/foo-slug-in-spanish/
translationKey = "foo"
Same process for pages.
Then each level of the hierarchy will have its corresponding page in
the other language, and subdirectories will also be translated.
Applied this approach in this theme, for example for:
EN
content/en/foo-first-level-section/foo-second-level/_index.md<link rel="alternate" hreflang="es" href="https://marcanuy.github.io/simpleit-hugo-theme/es/foo-seccion-primer-nivel/foo-segundo-nivel/" />ES
content/es/foo-seccion-primer-nivel/foo-segundo-nivel/_index.md<link rel="alternate" hreflang="en" href="https://marcanuy.github.io/simpleit-hugo-theme/foo-first-level-section/foo-second-level/" />@bep Are there plans about an easier solution than just published workaround by @marcanuy ? This feature is really important for many multilingual sites.
@bep it was closed from another issue, but I don't see any reference to it from #5681
Was it fixed?
It's not been implemented. The PR enables to localize Pages via FrontMatter property 'url'.
What's asked for here is to enable that for sections the same way.
And have it picked up when accessing permalinks as well.
Most helpful comment
Just thought I'd chime in and say that this is my single biggest issue using Hugo at the moment, and I think probably the only major roadblock to really powerful multilingual sites.
In my case, I have for example a
notessection. In English, I want that section to have the title "Notes", the list page to appear athttp://example.com/notes/, and the pages to be at eg.http://example.com/notes/on-making-a-website.html.But, in Japanese, I need that section to have the title 鎰忚 (iken), the list page to appear at
http://example.com/ja/iken/and the pages to be at eg.http://example.com/ja/iken/saito-wo-tukuru.html.At the moment, I can get the subpages to have the correct output path (
http://example.com/ja/iken/saito-wo-tukuru.html), by usingin my
config.yaml, but the list page permalink will still come out athttp://example.com/ja/notes/.Even using rewrite rules on Netlify, and throwing some hack-y code into templates and shortlinks using a Param listing these problem sections (ie.
index .Site.Params.slugPatches (.Get 0)), I still can't get the permalinks in.Translationsto match up.It means I can't have a URL that makes sense in the target language, and there's no possible workaround that I can find.
On the other hand, if the section's output folder was named after the
slugvalue in the section's frontmatter, just like for single pages, the system would work perfectly (and make a lot of immediate sense). Sections could be correctly translated, and the pages in the sections would have a correctly translated path.Then, in
/content/notes/_index.ja.mdI could just putinstead of all those workarounds/.Site.Params/redirect rules.