I opted to use the “Translation by content directory” option but in my case, the directory structure determines the permalinks (so no permalinks defined in config.toml). Most of my links are thus like section/nested-section/chapter-x/article.md
where only the article
part is translated but section/nested-section/chapter-x/
is not translated. I have already translated the _index.md
files inside the section, nested section and chapter-x folders. Is there a way to translate the folder names without losing the multilingual support?
Rename the section folder.
Folders used as a section will always use the folder name itself. Sections ignore frontmatter ‘translationKey’ (you can’t connect translated folders) and doesn’t use ‘slug’ and ‘title’ to generate it’s URL path, found in _index.md file, so it will always be based on the folder’s name itself.
But if you turn that folder into a taxonomy (declare it as a taxonomy in your config), then it will the title or slug in the _index.md file. This is what I do for my taxonomy URLs.
(EDIT: just tested it anyway and updated first paragraph)
I don’t want to use taxonomies. So it seems I will have to use the translation key option instead, which I tried to avoid.
Even translationKey doesn’t work, unless you found a workaround?
It didn’t work either. This seems to be a limitation of the translation system. The way I have configured the section, I don’t think taxonomies will work either.
If you are talking about having a translated “public url”, then you just have to manage this thru section/nested-section/chapter-x/_index.md
by adding this line in _index.md
frontmatter :
url: "my-translated-url-for-section-nested-section-chapter-x"
.
And keep your original same name section/nested-section/chapter-x/
in both language
Here is a test site demonstrating the content/URL organization if you can test with a second language of your choice.
I have not added this code, but here is what I have in config.toml (change into language of your choice)
[languages.lang1]
contentDir = 'content/lang1'
languageCode = 'lang-code'
languageName = 'Lang 1'
weight = 1
[languages.lang2]
contentDir = 'content/lang2'
languageCode = 'lang-code'
languageName = 'Lang 2'
weight = 2
and in baseof.html just after header,
{{ with .Translations }}
<p>Translations:
{{ range . }}
<a href="{{ .RelPermalink }}" rel="alternate" hreflang="{{ .Lang }}">{{ .Language.LanguageName }}</a>
{{ end }}
</p>
{{ end }}
I have about 18 chapters in my main site (in English) which follow either the content organization in chapter 1 or chapter 2. There are more than 400 articles. I want to translate the whole URL after the base URL.
The translationKey
in front matter works with:
Page type | Example path |
---|---|
Regular pages | content/posts/post-1.md |
Leaf bundles | content/posts/post-1/index.md |
Branch bundles | content/posts/_index.md |
Try it:
git clone --single-branch -b hugo-forum-topic-39226 https://github.com/jmooring/hugo-testing hugo-forum-topic-39226
cd hugo-forum-topic-39226
hugo server
Hi. Could you kindly clone my test site and test with it? I don’t want to change permalinks by adding /en/
since the content is already indexed. Renaming the folders is also not an option at this point.
Then set defaultContentLanguageInSubdir
to false
in your site config.
I just found a solution which involves adding the ur
l to the frontmatter for every file I want translated and changing all occurrences of slug
in the frontmattet to url
. That means though I will have to copy the full path depending on the file location and include it in the url. I also removed this code
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = 'false'
Now to the bigger task of translating over 500 articles and adding the URL frontmatter.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.