mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +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 ;-)
|
# use this theme ;-)
|
||||||
theme = "hugo-theme-relearn"
|
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]
|
# make sure your defaultContentLanguage is the first one in the [languages]
|
||||||
# array below, as the theme needs to make assumptions on it
|
# array below, as the theme needs to make assumptions on it
|
||||||
defaultContentLanguage = "en"
|
defaultContentLanguage = "en"
|
||||||
|
@ -126,6 +123,7 @@ title = "Hugo Relearn Theme"
|
||||||
[languages.pir]
|
[languages.pir]
|
||||||
title = "Cap'n Hugo Relearrrn Theme"
|
title = "Cap'n Hugo Relearrrn Theme"
|
||||||
weight = 2
|
weight = 2
|
||||||
|
languageCode = "art-pir"
|
||||||
languageName = "Arrr! ☠ Pirrrates ☠"
|
languageName = "Arrr! ☠ Pirrrates ☠"
|
||||||
# Language dependend settings:
|
# Language dependend settings:
|
||||||
# Use case https://gohugo.io/content-management/multilingual/#translation-by-content-directory
|
# 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") }}
|
{{- $pagefield := cond (ne $content nil) nil (.pagefield | default "Content") }}
|
||||||
{{- $writenotice := cond (ne .writenotice nil) .writenotice false }}
|
{{- $writenotice := cond (ne .writenotice nil) .writenotice false }}
|
||||||
{{- $langtrg := "pir" }}
|
{{- $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 }}
|
{{- $baseURL := urls.Parse site.BaseURL }}
|
||||||
{{- $baseURLpath := $baseURL.Path | default "/" }}
|
{{- $baseURLpath := $baseURL.Path | default "/" }}
|
||||||
{{- $l := $page.RelPermalink }}
|
{{- $l := $page.RelPermalink }}
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
{{- break }}
|
{{- break }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if eq $page.Lang $langtrg }}
|
{{- if eq $page.Language.Lang $langtrg }}
|
||||||
{{- if $writenotice }}
|
{{- if $writenotice }}
|
||||||
{{- partial "shortcodes/notice.html" (dict
|
{{- partial "shortcodes/notice.html" (dict
|
||||||
"page" $page
|
"page" $page
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
{{- partialCached "page-meta.hugo" . .RelPermalink }}
|
{{- partialCached "page-meta.hugo" . .RelPermalink }}
|
||||||
{{- $outputFormat := partial "output-format.hugo" . }}
|
{{- $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>
|
<head>
|
||||||
{{- partial "meta.html" . }}
|
{{- partial "meta.html" . }}
|
||||||
{{- $title := .Title }}
|
{{- $title := .Title }}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
{{- if eq $index 0 }}
|
{{- if eq $index 0 }}
|
||||||
<xhtml:link rel="alternate" hreflang="x-default" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />
|
<xhtml:link rel="alternate" hreflang="x-default" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />
|
||||||
{{- end }}
|
{{- 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 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</url>
|
</url>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
{{- errorf "The Relearn theme requires Hugo %s or later" $hugoVersion }}
|
{{- errorf "The Relearn theme requires Hugo %s or later" $hugoVersion }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- 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>
|
<head>
|
||||||
{{- partial "meta.html" . }}
|
{{- partial "meta.html" . }}
|
||||||
{{- $page := . }}
|
{{- $page := . }}
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
{{- if eq $index 0 }}
|
{{- if eq $index 0 }}
|
||||||
<link href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}" rel="alternate" hreflang="x-default">
|
<link href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}" rel="alternate" hreflang="x-default">
|
||||||
{{- end }}
|
{{- 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 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
|
|
|
@ -75,18 +75,9 @@
|
||||||
<label class="a11y-only" for="R-select-language">{{ T "Language" }}</label>
|
<label class="a11y-only" for="R-select-language">{{ T "Language" }}</label>
|
||||||
<select id="R-select-language" onchange="location = baseUri + this.value;">
|
<select id="R-select-language" onchange="location = baseUri + this.value;">
|
||||||
{{- $page := .Page }}
|
{{- $page := .Page }}
|
||||||
{{- $pageLang := .Page.Lang }}
|
{{- $pageLang := .Page.Language.Lang }}
|
||||||
{{- range .Page.AllTranslations }}
|
{{- range .Page.AllTranslations }}
|
||||||
{{- $translation := . }}
|
<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>
|
||||||
{{- 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 }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
<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 }}
|
</div>{{ if $link }}</form>{{ end }}
|
||||||
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
|
{{- $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)) }}
|
{{- $contentlangs := (union (slice | append (.Site.Params.additionalContentLanguage | default slice)) (slice $pageBaseLang)) }}
|
||||||
{{- $quotedcontentlangs := slice }}
|
{{- $quotedcontentlangs := slice }}
|
||||||
{{- $missingcontentlangs := slice }}
|
{{- $missingcontentlangs := slice }}
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
{{- $pattern := .pattern | default "" }}
|
{{- $pattern := .pattern | default "" }}
|
||||||
{{- $defaultUrlPrefix := strings.TrimRight "/" $page.RelPermalink }}
|
{{- $defaultUrlPrefix := strings.TrimRight "/" $page.RelPermalink }}
|
||||||
{{- if .IsTranslated -}}
|
{{- 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 }}
|
{{- $defaultLanguagePage := index (where $page.AllTranslations "Language.Lang" $defaultLanguage) 0 }}
|
||||||
{{- $defaultUrlPrefix = strings.TrimRight "/" $defaultLanguagePage.RelPermalink }}
|
{{- $defaultUrlPrefix = strings.TrimRight "/" $defaultLanguagePage.RelPermalink }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
Loading…
Reference in a new issue