publiccode.si/site/layouts/shortcodes/translation_status.html

48 lines
2.0 KiB
HTML

{{- $allgood := true -}} <!-- "allgood" will say whether all translations are fine -->
{{- range .Site.Pages -}} <!-- range through all pages -->
{{- $uptodate := true -}} <!-- reset uptodate var -->
{{- $main_date := .Lastmod -}} <!-- last modification date of EN file -->
{{- range .Translations -}} <!-- range through all translations of .Page -->
{{- if and (.IsTranslated) (.IsPage) -}}
{{- $i18n_date := .Lastmod -}}
{{- if ($main_date.After $i18n_date) -}} <!-- EN .Lastmod is newer than .Lastmod of translation -->
{{- $uptodate = false -}} <!-- at least one translation failed -->
{{- $allgood = false -}} <!-- at least one translation failed -->
{{- end -}}
{{- end -}}
{{- end -}}
{{- if eq $uptodate false }} <!-- if at least one translation failed -->
<h3><a href="{{ .Permalink }}">{{ .File.Path }}</a></h3>
<table class="transstatus">
<thead><tr>
<th>Lang</th>
<th>Page</th>
<th>Translation date</th>
<th>Original date</th>
<th>Version Diff</th>
</tr></thead>
{{ $main_date := .Lastmod -}} <!-- same logic as above, now with output -->
{{- $main_version := .Params.version -}} <!-- "version" value of file's front matter -->
{{ range sort .Translations ".Lang" }}
{{- if and (.IsTranslated) (.IsPage) -}}
{{- $i18n_date := .Lastmod -}}
{{- $i18n_version := .Params.version -}}
{{- if ($main_date.After $i18n_date) -}}
<tr>
<td>{{ .Lang | upper }}</td>
<td><a href="{{ .Permalink }}">{{ .File.Path }}</a></td>
<td>{{ $i18n_date.Format "2006-01-02" }} (v{{ $i18n_version }})</td>
<td>{{ $main_date.Format "2006-01-02" }} (v{{ $main_version }})</td>
<td>{{ sub $main_version $i18n_version }}</td>
</tr>
{{- end -}}
{{- end -}}
{{ end }}
</table>
{{- end -}}
{{- end -}}
{{- if eq $allgood true -}}
<p style="text-align:center;">Everything is up to date! &#128077;</p>
{{- end -}}