.TranslationKey vs .File.BaseFileName

Continuing the discussion from Easiest way to embed code from source files:

@jmooring

I was curious about how .TranslationKey would be different then .File.BaseFileName for a page.

The docs just say:

the key used to map language translations of the current page. See Multilingual Mode for more information.

But then when I looked here:

I realized that if a content page file has no language suffix, like foo.md, both path.Base .TranslationKey and .File.BaseFileName will be identical => foo.

But if the content file were named foo.en.md, .File.BaseFileName would be (I think) foo.en, but path.Base .TranslationKey would still be foo.

Just creating this small post if my future self searched something related :slight_smile: .

1 Like

I will give you my example:

kontakt.md

url: '/kontakt/'
translationKey: kontakt

contact.en.md

url: '/en/contact/'
translationKey: kontakt

Two different files, despite that .en.md refers to which language rile is pointing towards, the filenames are different and URLs are not that same.

translationKey is connecting these two pages together, so when you will put this in your head

{{ if .IsTranslated }}
    {{ range .Translations }}
      <link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}">
    {{ end }}
      <link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}">
  {{ end }}

The output will be

<link rel=alternate hreflang=en href=/en/contact/>
<link rel=alternate hreflang=pl href=/kontakt/>

This is how two different filenames, different URLs are connected together based on TranslationKey


You can stick to

contact.md (for main language)

and

contact.en.md (for other EN as secondary language)

and they will be connected through BaseFileName even if URLs will be different etc.