mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
i18n: support for languageCode and standard Hugo options #733
This commit is contained in:
parent
5d058ea7ba
commit
42b604b4fb
8 changed files with 11 additions and 22 deletions
|
@ -24,9 +24,6 @@ themesdir = "../.."
|
|||
# use this theme ;-)
|
||||
theme = "hugo-theme-relearn"
|
||||
|
||||
# the main language of this site; also an automatic pirrrate translation is
|
||||
# available in this showcase
|
||||
languageCode = "en"
|
||||
# make sure your defaultContentLanguage is the first one in the [languages]
|
||||
# array below, as the theme needs to make assumptions on it
|
||||
defaultContentLanguage = "en"
|
||||
|
@ -126,6 +123,7 @@ title = "Hugo Relearn Theme"
|
|||
[languages.pir]
|
||||
title = "Cap'n Hugo Relearrrn Theme"
|
||||
weight = 2
|
||||
languageCode = "art-pir"
|
||||
languageName = "Arrr! ☠ Pirrrates ☠"
|
||||
# Language dependend settings:
|
||||
# Use case https://gohugo.io/content-management/multilingual/#translation-by-content-directory
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
{{- $pagefield := cond (ne $content nil) nil (.pagefield | default "Content") }}
|
||||
{{- $writenotice := cond (ne .writenotice nil) .writenotice false }}
|
||||
{{- $langtrg := "pir" }}
|
||||
{{- $langsrc := cond (eq $page.Lang $langtrg) (.langsrc | default "en") $page.Lang }}
|
||||
{{- $langsrc := cond (eq $page.Language.Lang $langtrg) (.langsrc | default "en") $page.Language.Lang }}
|
||||
{{- $baseURL := urls.Parse site.BaseURL }}
|
||||
{{- $baseURLpath := $baseURL.Path | default "/" }}
|
||||
{{- $l := $page.RelPermalink }}
|
||||
|
@ -34,7 +34,7 @@
|
|||
{{- break }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if eq $page.Lang $langtrg }}
|
||||
{{- if eq $page.Language.Lang $langtrg }}
|
||||
{{- if $writenotice }}
|
||||
{{- partial "shortcodes/notice.html" (dict
|
||||
"page" $page
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
{{- partialCached "page-meta.hugo" . .RelPermalink }}
|
||||
{{- $outputFormat := partial "output-format.hugo" . }}
|
||||
<html lang="{{ .Page.Language | default "en" }}" dir="{{ T "Reading-direction" | default "ltr" }}">
|
||||
<html lang="{{ .Page.Language.LanguageCode | default "en" }}" dir="{{ T "Reading-direction" | default "ltr" }}">
|
||||
<head>
|
||||
{{- partial "meta.html" . }}
|
||||
{{- $title := .Title }}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
{{- if eq $index 0 }}
|
||||
<xhtml:link rel="alternate" hreflang="x-default" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />
|
||||
{{- end }}
|
||||
<xhtml:link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />
|
||||
<xhtml:link rel="alternate" hreflang="{{ .Language.LanguageCode }}" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
</url>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
{{- errorf "The Relearn theme requires Hugo %s or later" $hugoVersion }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
<html lang="{{ .Page.Language | default "en" }}" dir="{{ T "Reading-direction" | default "ltr" }}">
|
||||
<html lang="{{ .Page.Language.LanguageCode | default "en" }}" dir="{{ T "Reading-direction" | default "ltr" }}">
|
||||
<head>
|
||||
{{- partial "meta.html" . }}
|
||||
{{- $page := . }}
|
||||
|
@ -39,7 +39,7 @@
|
|||
{{- if eq $index 0 }}
|
||||
<link href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}" rel="alternate" hreflang="x-default">
|
||||
{{- end }}
|
||||
<link href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}" rel="alternate" hreflang="{{ .Language.Lang }}">
|
||||
<link href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}" rel="alternate" hreflang="{{ .Language.LanguageCode }}">
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
|
|
|
@ -75,18 +75,9 @@
|
|||
<label class="a11y-only" for="R-select-language">{{ T "Language" }}</label>
|
||||
<select id="R-select-language" onchange="location = baseUri + this.value;">
|
||||
{{- $page := .Page }}
|
||||
{{- $pageLang := .Page.Lang }}
|
||||
{{- $pageLang := .Page.Language.Lang }}
|
||||
{{- range .Page.AllTranslations }}
|
||||
{{- $translation := . }}
|
||||
{{- range $siteLanguages }}
|
||||
{{- if eq $translation.Lang .Lang }}
|
||||
{{- if eq $pageLang .Lang }}
|
||||
<option id="R-{{ $translation.Lang }}" value="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" $translation "basename" $basename) }}" lang="{{ $translation.Lang }}" selected>{{ .LanguageName }}</option>
|
||||
{{- else }}
|
||||
<option id="R-{{ $translation.Lang }}" value="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" $translation "basename" $basename) }}" lang="{{ $translation.Lang }}">{{ .LanguageName }}</option>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
<option id="R-{{ .Language.Lang }}" value="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "basename" $basename) }}" lang="{{ .Language.LanguageCode }}"{{ if eq $pageLang .Language.Lang }} selected{{ end }}>{{ .Language.LanguageName }}</option>
|
||||
{{- end }}
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<button class="search-clear" type="button" data-search-clear="" title="{{ T "Clear-search" }}"><i class="fas fa-times" title="{{ T "Clear-search" }}"></i></button>
|
||||
</div>{{ if $link }}</form>{{ end }}
|
||||
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
|
||||
{{- $pageBaseLang := replaceRE "([a-z]+).*" "${1}" .Page.Lang }}
|
||||
{{- $pageBaseLang := replaceRE "([a-z]+).*" "${1}" .Page.Language.LanguageCode }}
|
||||
{{- $contentlangs := (union (slice | append (.Site.Params.additionalContentLanguage | default slice)) (slice $pageBaseLang)) }}
|
||||
{{- $quotedcontentlangs := slice }}
|
||||
{{- $missingcontentlangs := slice }}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
{{- $pattern := .pattern | default "" }}
|
||||
{{- $defaultUrlPrefix := strings.TrimRight "/" $page.RelPermalink }}
|
||||
{{- if .IsTranslated -}}
|
||||
{{- $defaultLanguage := (index $page.Site.Home.AllTranslations 0).Lang }}
|
||||
{{- $defaultLanguage := (index $page.Site.Home.AllTranslations 0).Language.Lang }}
|
||||
{{- $defaultLanguagePage := index (where $page.AllTranslations "Language.Lang" $defaultLanguage) 0 }}
|
||||
{{- $defaultUrlPrefix = strings.TrimRight "/" $defaultLanguagePage.RelPermalink }}
|
||||
{{- end }}
|
||||
|
|
Loading…
Reference in a new issue