Skip to content

Commit

Permalink
exclude current lang in navbar, better alignment, use languageName
Browse files Browse the repository at this point in the history
* exclude the currently used language to yield space in the navbar
* improve button optics and alignment in menu bar and collapsed menu
* use long language name as button text to make it more user friendly
* update documentation
  • Loading branch information
Kai Stierl committed Apr 13, 2020
1 parent 265148c commit 611a7ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion exampleSite/content/docs/multilingual/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@ for German website if those pages are not translated to German. For more
information on Hugo's Multilingual mode, please refer to [their documentation](https://gohugo.io/content-management/multilingual/).

In order to configure two languages, you need to update your main your
configuration. Here's an example from the official documentation:
configuration. Here's an example, derived from the official documentation:

```
DefaultContentLanguage = "en"
[languages]
[languages.en]
languageName = "English"
title = "My blog"
weight = 1
[languages.fr]
languageName = "Français"
title = "Mon blogue"
weight = 2
[params]
...
```

The `languageName` parameter is used as text on the language switcher buttons
in the navbar.

Please note that these parameters are added outside of `params` variable, inside
your configuration file (`config.toml`, `config.yaml`, `config.json`). This will
let Hugo know that there are two languages for this project and the default
Expand Down
10 changes: 6 additions & 4 deletions layouts/partials/fragments/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{{- else -}}
{{- printf " justify-content-end " -}}
{{- end -}} collapse show" id="navbarCollapse">
<ul class="navbar-nav">
<ul class="navbar-nav mr-2">
{{- if .Params.prepend -}}
{{- range sort .Params.prepend }}
{{- $isMenuCurrent := or (eq $.root.Permalink .url) (eq (printf "%s/" $.root.Permalink) .url) (eq $.root.Permalink (printf "%s/" .url)) -}}
Expand Down Expand Up @@ -102,9 +102,11 @@
{{- end }}
{{- if .Site.IsMultiLingual -}}
{{- range .Site.Languages }}
<a class="btn btn-secondary p-1 m-1" href="{{ delimit (slice "/" .) "" }}" role="button">
{{ . }}
</a>
{{- if ne .Lang $.Site.Language.Lang -}}
<a class="btn btn-secondary mr-1 my-2" href="{{ delimit (slice "/" .) "" }}" role="button">
{{ .LanguageName }}
</a>
{{- end -}}
{{- end -}}
{{- end }}
</div>
Expand Down

0 comments on commit 611a7ea

Please sign in to comment.