-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
allow languagePrefix to be defined via config #8279
Comments
Should do that. I could also think of a way where you use I can't find the place where it's written, but the language slug can be anything and is not covered by rules, you just need to be careful where you define language related things so that you are using fragen/questions instead of de/en. |
Yes, that works but messes up i18n, since "fragen" and "questions" would be used as Lang identifiers. Even when |
Sorry for my short on-the-phone answer earlier. For me, it's a bit confusing, what hugo/docs/content/en/variables/page.md Lines 87 to 88 in 04b8985
But it seems that in some (most?) cases it's just the key used in the languages config (de/en, or fragen/questions). I could work around that, by setting a - {{ .Site.Language.Lang }}
+ {{ .Site.LanguageCode }} {{ range .Translations }}
- {{ .Lang }}
+ {{ .Language.Params.LanguageCode }} But it still breaks for some hugo internals, like i18n, where I get errors, not unlike #7838, |
I believe what you really want actually ability to let non-primary language generated without as primary language default to be generated without language subdir, but also can be controlled via meanwhile, secondary language always generated inside it's Example:
Expected generated structure
|
@pamubay Yes, kind of. But wouldn't your content directory structure break the default translation mapping, and would require me to put a It's all a bit confusing, that's why my initial thought was to just be able to define which language prefix to use and setting |
Setting a language prefix to a content type, if you could, would fail as soon as you added another content type. Please try this site: git clone --single-branch -b hugo-github-issue-8279 https://github.com/jmooring/hugo-testing hugo-github-issue-8279
cd hugo-github-issue-8279
hugo server |
@jmooring Thanks for creating the sample. I tried your sample and also adopting to my usecase. But it's not producing my desired result. So I don't want to set the "language prefix" to a content type but to the language itself. I while back, I played around a bit and got a proof-of-concept "working" (it made some test fails if I remember correctly): https://gist.github.com/fnordfish/100564ed0190452dd7136c66bd600961 (Some background: I generate parts of a larger website using hugo. And that site already has some pretty pinned down URL schema - so I cannot simply go with the defaults) |
I've update the test site to remove the lang code from section URLs. diffcommit 0d27800b0bcc9372b3438d8563acccdfef7ba5b8
Author: Joe Mooring <joe.mooring@veriphor.com>
Date: Thu Nov 4 12:38:47 2021 -0700
Remove lang code from section URLs
diff --git a/content/books/_index.de.md b/content/books/_index.de.md
index 6260afc87..68e5d74ab 100644
--- a/content/books/_index.de.md
+++ b/content/books/_index.de.md
@@ -2,6 +2,6 @@
title = 'Bücher'
date = 2021-11-04T09:49:05-07:00
draft = false
-url = '/de/bücher/'
+url = '/bücher/'
+++
This is content/books/_index.de.md
diff --git a/content/books/_index.en.md b/content/books/_index.en.md
index 7428a2fdc..b692b4335 100644
--- a/content/books/_index.en.md
+++ b/content/books/_index.en.md
@@ -2,5 +2,6 @@
title = 'Books'
date = 2021-11-04T09:48:59-07:00
draft = false
+url = '/books/'
+++
This is content/books/_index.en.md
diff --git a/content/books/_index.es.md b/content/books/_index.es.md
index 910a33fb7..86c5cb68d 100644
--- a/content/books/_index.es.md
+++ b/content/books/_index.es.md
@@ -2,6 +2,6 @@
title = 'Libros'
date = 2021-11-04T10:01:30-07:00
draft = false
-url = '/es/libros/'
+url = '/libros/'
+++
This is content/books/_index.es.md
diff --git a/content/questions/_index.de.md b/content/questions/_index.de.md
index bca45b752..8b2449907 100644
--- a/content/questions/_index.de.md
+++ b/content/questions/_index.de.md
@@ -2,6 +2,6 @@
title = 'Fragen'
date = 2021-11-04T09:49:05-07:00
draft = false
-url = '/de/fragen/'
+url = '/fragen/'
+++
This is content/questions/_index.de.md
diff --git a/content/questions/_index.en.md b/content/questions/_index.en.md
index 9dac5a0c5..2fd269849 100644
--- a/content/questions/_index.en.md
+++ b/content/questions/_index.en.md
@@ -2,5 +2,6 @@
title = 'Questions'
date = 2021-11-04T09:48:59-07:00
draft = false
+url = '/questions/'
+++
This is content/questions/_index.en.md
diff --git a/content/questions/_index.es.md b/content/questions/_index.es.md
index 426855edc..48605d6c0 100644
--- a/content/questions/_index.es.md
+++ b/content/questions/_index.es.md
@@ -2,6 +2,6 @@
title = 'Preguntas'
date = 2021-11-04T10:01:30-07:00
draft = false
-url = '/es/preguntas/'
+url = '/preguntas/'
+++
This is content/questions/_index.es.md This gets you most of the way there, I think. However, the pages within each section still have the language code. Will that work? Please pull changes and test again. I'm spending time on this because, if we're going to propose a change, I want to make sure we understand what we're trying to change and why. |
I think this issue is mostly about permalinks and ease-of-use. You can achieve the desired results by:
But this is a lot of error-prone data entry, and is probably fragile over time. We could also achieve the desired results by:
|
@jmooring Thanks again, happy to test anything. I think that's kind of what I'm doing as my current workaround. I put an explicit |
Just to add: Taxonomy stuff should also be nested under the common prefix. eg: |
This would be addressed by #8279 (comment). |
Just to make sure we're on the same page, I've applied my patch to hugo-HEAD and adapted your sample project to use the new config. Not saying that it has to be done that way, but that's the outcome I'm looking for: fnordfish/hugo-testing@44922b2#commitcomment-59488119 Another sample with permalinks: |
I'm closing this. The proposal as defined the title is not something we're going to do. |
@bep Fair enough. Do you think it's something that could eventually be done using Permalink options? Or is this setup not a thing hugo will support in the foreseeable future? |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
In my multilingual project, I'd like to be able to have more control over the generated URLs.
I'd like to be able to define which
languagePrefix
is used, instead of the language key.As an example:
http://base/en/some-post
->http://base/questions/some-post
http://base/de/some-post
->http://base/fragen/some-post
I've tried to just use those translations as keys in the translations config, which produced the right document structure, but broke i18n, because the keys are no longer language codes.
I've also tired to just use hard-code the entire
url
as page params, which also worked for pages, but had no effect on the home page.hugo/hugolib/site.go
Lines 1294 to 1297 in 04b8985
Instead of using
lang.Lang
, we could extendLanguage
with aLanguagePrefix
, which could default toLang
?The text was updated successfully, but these errors were encountered: