-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
tpl/lang: Add lang.Language template function #12212
Comments
To me it would make slightly more sense to have this as a method on {{ if .Translations }}
{{ $targetLang := .Language }}
<ul>
{{ range .AllTranslations }}
<li><a href="{{ .RelPermalink }}">{{ .LanguageName $targetLang }}</a></li>
{{ end }}
</ul>
{{ end }} Which means that we would need a better name than We have a related issue in #7844 |
My preference would be to implement this as function first. It seems like this would be the most flexible, and the API in a language switcher seems clean to me:
I have a working implementation if you wish to proceed. Having said that, the need for this functionality was expressed here, but I haven't seen any similar requests. |
This is a pretty good idea from the forum, allowing you to get a translated language name from a language tag. One example (which may not be great) is a language switcher that displays "french" in three different languages on a three language site. For example:
Screencast.from.03-07-2024.12.32.25.PM.webm
Instead of using translation tables, use Go's language package that we already use for other things (no new dependencies).
Signature:
If TARGET is not provided, set to SRC.
A language switcher would look like this:
Reference: https://discourse.gohugo.io/t/get-a-translated-language-name-from-its-code/48697/8
The text was updated successfully, but these errors were encountered: