Follow nav links based on language selection

Hi all. I’ve been struggling for days with trying to get links to “redirect”(?) to pages that correspond to the selected language.

Here is the partial:

						<div class="nav-item1 sand">
								<a class="link pr" href="https://www.eigo.quest">{{ i18n "eigo.quest" }}</a>
						</div>
						<div class="nav-item2">
								<a class="link pr" href="{{ .Site.BaseURL }}">{{ i18n "Home" }}</a>
								<a class="link pr" href="{{ .Site.BaseURL }}blog/">{{ i18n "Blog" }}</a>
								<a class="link pr" href="{{ .Site.BaseURL }}about/">{{ i18n "About" }}</a>
								<a class="link pr" href="{{ .Site.BaseURL }}contact/">{{ i18n "Contact" }}</a>
								{{ if .Site.IsMultiLingual }}
								{{ range .Site.Languages }}
								{{ if eq . $.Site.Language }}
									{{ range $.Translations }}
										<a href="{{ .Permalink }}" class="">{{ .Language.LanguageName }}</a>
									{{ end }}
								{{ end }}
								{{ end }}
								{{ end }}
						</div>

Here is the hugo.toml config:

baseURL = "https://www.eigo.quest/"
relativeURLs = true
languageCode = "en-us"
title = "Eigo Quest"
theme = "grid"
summaryLength = 30

# Multi-lang Settings
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = false  # Enable this to have language codes in subdirectories

[languages]
  [languages.en]
    languageName = "English"
    weight = 1
    title = "Eigo Quest"
  [languages.ja]
    languageName = "Japanese"
    weight = 2
    title = "英語クエスト"

[outputFormats]
  [outputFormats.RSS]
    mediaType = "application/rss+xml"
    baseName = "feed"

[[cascade]]
  [cascade._build]
    list = 'always'
    render = 'never'
  [cascade._target]
    path = "/home/**"

[taxonomies]
tag = "tags"
category = "categories"

[markup.goldmark.renderer]
unsafe = true

# Redirect to /en/ as the default homepage
#[[redirects]]
#  from = "/"
#  to = "/en/"
#  status = 301

Any help would be appreciated. Thanks

Here is the tree structure:

.
├── archetypes
│   └── default.md
├── assets
│   ├── css
│   │   ├── splide-custom.css
│   │   └── style.css
│   ├── images
│   │   └── bitmap.png
│   └── js
│       ├── script.js
│       └── splide-custom.js
├── content
│   ├── _index.md
│   ├── about
│   │   ├── _index.ja.md
│   │   ├── _index.md
│   │   ├── about.ja.md
│   │   └── about.md
│   ├── blog
│   │   ├── _index.md
│   │   ├── clones.ja.md
│   │   └── clones.md
│   ├── contact
│   │   ├── hitomi.ja.md
│   │   ├── hitomi.md
│   │   ├── mgk.ja.md
│   │   └── mgk.md
│   └── home
│       ├── _index.md
│       ├── do.en.md
│       ├── do.ja.md
│       ├── do.md
│       ├── dont.ja.md
│       ├── dont.md
│       ├── intro.ja.md
│       ├── intro.md
│       ├── pricing.ja.md
│       ├── pricing.md
│       ├── schedule.ja.md
│       ├── schedule.md
│       ├── scl.ja.md
│       └── scl.md
├── hugo.toml
├── i18n
│   ├── en.yaml
│   └── ja.yaml
├── public
│   ├── about
│   │   ├── about
│   │   │   └── index.html
│   │   ├── feed.xml
│   │   └── index.html
│   ├── blog
│   │   ├── clones
│   │   │   └── index.html
│   │   ├── feed.xml
│   │   └── index.html
│   ├── categories
│   │   ├── feed.xml
│   │   ├── index.html
│   │   └── warm-takes
│   │       ├── feed.xml
│   │       └── index.html
│   ├── contact
│   │   ├── feed.xml
│   │   ├── hitomi
│   │   │   └── index.html
│   │   ├── index.html
│   │   └── mgk
│   │       └── index.html
│   ├── css
│   │   ├── splide-custom.css
│   │   ├── splide-custom.min.css
│   │   ├── style.css
│   │   └── style.min.css
│   ├── en
│   │   ├── index.html
│   │   └── sitemap.xml
│   ├── feed.xml
│   ├── fonts
│   │   ├── mplus
│   │   │   ├── Mplus2-Black.woff2
│   │   │   ├── Mplus2-Bold.woff2
│   │   │   ├── Mplus2-ExtraBold.woff2
│   │   │   ├── Mplus2-ExtraLight.woff2
│   │   │   ├── Mplus2-Light.woff2
│   │   │   ├── Mplus2-Medium.woff2
│   │   │   ├── Mplus2-Regular.woff2
│   │   │   ├── Mplus2-SemiBold.woff2
│   │   │   └── Mplus2-Thin.woff2
│   │   └── poppins
│   │       ├── Poppins-Black.woff2
│   │       ├── Poppins-BlackItalic.woff2
│   │       ├── Poppins-Bold.woff2
│   │       ├── Poppins-BoldItalic.woff2
│   │       ├── Poppins-ExtraBold.woff2
│   │       ├── Poppins-ExtraBoldItalic.woff2
│   │       ├── Poppins-ExtraLight.woff2
│   │       ├── Poppins-ExtraLightItalic.woff2
│   │       ├── Poppins-Italic.woff2
│   │       ├── Poppins-Light.woff2
│   │       ├── Poppins-LightItalic.woff2
│   │       ├── Poppins-Medium.woff2
│   │       ├── Poppins-MediumItalic.woff2
│   │       ├── Poppins-Regular.woff2
│   │       ├── Poppins-SemiBold.woff2
│   │       ├── Poppins-SemiBoldItalic.woff2
│   │       ├── Poppins-Thin.woff2
│   │       └── Poppins-ThinItalic.woff2
│   ├── images
│   │   └── bitmap.png
│   ├── index.html
│   ├── ja
│   │   ├── about
│   │   │   ├── about
│   │   │   │   └── index.html
│   │   │   ├── feed.xml
│   │   │   └── index.html
│   │   ├── blog
│   │   │   ├── clones
│   │   │   │   └── index.html
│   │   │   ├── feed.xml
│   │   │   └── index.html
│   │   ├── categories
│   │   │   ├── feed.xml
│   │   │   ├── index.html
│   │   │   └── warm-takes
│   │   │       ├── feed.xml
│   │   │       └── index.html
│   │   ├── contact
│   │   │   ├── feed.xml
│   │   │   ├── hitomi
│   │   │   │   └── index.html
│   │   │   ├── index.html
│   │   │   └── mgk
│   │   │       └── index.html
│   │   ├── feed.xml
│   │   ├── home
│   │   │   ├── feed.xml
│   │   │   └── index.html
│   │   ├── index.html
│   │   ├── sitemap.xml
│   │   └── tags
│   │       ├── feed.xml
│   │       ├── index.html
│   │       └── woes
│   │           ├── feed.xml
│   │           └── index.html
│   ├── js
│   │   ├── script.js
│   │   ├── script.min.js
│   │   ├── splide-custom.js
│   │   └── splide-custom.min.js
│   ├── sitemap.xml
│   └── tags
│       ├── feed.xml
│       ├── index.html
│       └── woes
│           ├── feed.xml
│           └── index.html
├── resources
│   └── _gen
│       └── images
│           └── images
│               └── bitmap_hu336fec14705e3968627feb5fb8c73bb1_4410272_500x0_resize_q85_box_3.png
├── static
│   └── fonts
│       ├── mplus
│       │   ├── Mplus2-Black.woff2
│       │   ├── Mplus2-ExtraBold.woff2
│       │   └── Mplus2-Regular.woff2
│       └── poppins
│           ├── Poppins-Black.woff2
│           ├── Poppins-ExtraBold.woff2
│           └── Poppins-Regular.woff2
├── themes
│   └── grid
│       ├── archetypes
│       │   └── default.md
│       ├── hugo.toml
│       ├── layouts
│       │   ├── 404.html
│       │   ├── _default
│       │   │   ├── about.html
│       │   │   ├── backup
│       │   │   │   └── list.html
│       │   │   ├── baseof.html
│       │   │   ├── blog.html
│       │   │   ├── contact.html
│       │   │   ├── ideas.html
│       │   │   ├── list.html
│       │   │   ├── single.html
│       │   │   ├── taxonomy.html
│       │   │   ├── term.html.bak
│       │   │   ├── terms.html
│       │   │   └── url.html.bak
│       │   ├── index.html
│       │   ├── partials
│       │   │   ├── breadcrumbs.html
│       │   │   ├── footer.html
│       │   │   ├── head.html
│       │   │   ├── header.html
│       │   │   ├── home
│       │   │   │   ├── section1.html
│       │   │   │   ├── section2.html
│       │   │   │   ├── section3.html
│       │   │   │   └── section4.html
│       │   │   ├── image.html
│       │   │   ├── nextprev.html
│       │   │   ├── slider.html
│       │   │   ├── top-blog.html
│       │   │   └── top-home.html
│       │   └── shortcodes
│       │       ├── arrow.html
│       │       ├── cards.html
│       │       ├── img.html
│       │       └── table.html
│       ├── static
│       │   ├── css
│       │   │   ├── splide-custom.css
│       │   │   └── style.css
│       │   ├── fonts
│       │   │   ├── mplus
│       │   │   │   ├── Mplus2-Black.woff2
│       │   │   │   ├── Mplus2-Bold.woff2
│       │   │   │   ├── Mplus2-ExtraBold.woff2
│       │   │   │   ├── Mplus2-ExtraLight.woff2
│       │   │   │   ├── Mplus2-Light.woff2
│       │   │   │   ├── Mplus2-Medium.woff2
│       │   │   │   ├── Mplus2-Regular.woff2
│       │   │   │   ├── Mplus2-SemiBold.woff2
│       │   │   │   └── Mplus2-Thin.woff2
│       │   │   └── poppins
│       │   │       ├── Poppins-Black.woff2
│       │   │       ├── Poppins-BlackItalic.woff2
│       │   │       ├── Poppins-Bold.woff2
│       │   │       ├── Poppins-BoldItalic.woff2
│       │   │       ├── Poppins-ExtraBold.woff2
│       │   │       ├── Poppins-ExtraBoldItalic.woff2
│       │   │       ├── Poppins-ExtraLight.woff2
│       │   │       ├── Poppins-ExtraLightItalic.woff2
│       │   │       ├── Poppins-Italic.woff2
│       │   │       ├── Poppins-Light.woff2
│       │   │       ├── Poppins-LightItalic.woff2
│       │   │       ├── Poppins-Medium.woff2
│       │   │       ├── Poppins-MediumItalic.woff2
│       │   │       ├── Poppins-Regular.woff2
│       │   │       ├── Poppins-SemiBold.woff2
│       │   │       ├── Poppins-SemiBoldItalic.woff2
│       │   │       ├── Poppins-Thin.woff2
│       │   │       └── Poppins-ThinItalic.woff2
│       │   ├── images
│       │   │   └── bitmap.png
│       │   └── js
│       │       ├── script.js
│       │       └── splide-custom.js
│       └── theme.toml
└── tree

First, never use .Site.BaseURL in your templates; this is an artifact from several years ago that will hopefully be deprecated at some point.

Second, I encourage to use the menu system instead of hardcoding your nav links.

Third, if you are unwilling to use the menu system, look at the relLangURL function in the documentation.

3 Likes

Thank you!