Skip to content

Commit a908332

Browse files
committed
[i18n] Initial multilingual support for redirects with ja example
1 parent 3b44fbf commit a908332

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

content/ja/docs/specs.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Specifications
3+
linkTitle: Specs ↗
4+
description: _Redirect page_
5+
weight: 960
6+
# _build: { render: link }
7+
redirect: /docs/specs # TODO: this will need to be /en/...
8+
redirects: [{ from: '*', to: ':splat' }]
9+
---
10+
11+
Netlify redirect target: [{{% param "title" %}}]({{% param "redirect" %}}).

layouts/index.redirects

+4
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@
7272
{{ end }}
7373
{{ return $result }}
7474
{{ end }}
75+
76+
{{/* Multilingual support */ -}}
77+
78+
{{ partial "redirects/sites.redirects" . | partial "func/trim-lines.html" -}}

layouts/partials/func/trim-lines.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{ range split . "\n" -}}
2+
{{ trim . " \t" }}
3+
{{ end -}}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{/* Redirect for default language when .LanguagePrefix is empty. */ -}}
2+
3+
{{ $defaultLang := "" -}}
4+
{{ with .Site.Sites.Default -}}
5+
{{ if eq .LanguagePrefix "" -}}
6+
{{ with .Language.Lang -}}
7+
{{ $defaultLang = . -}}
8+
/{{ . }} /
9+
/{{ . }}/* /:splat
10+
{{ end -}}
11+
{{ end -}}
12+
{{ end -}}
13+
14+
{{/* Process non-default languages. */ -}}
15+
16+
{{ range after 1 .Sites -}}
17+
18+
{{ $siteLang := .Language.Lang -}}
19+
20+
# Site localization {{ $siteLang }}
21+
{{ range $p := .Pages -}}
22+
23+
{{ range $p.Params.redirects -}}
24+
{{ $fallbackPage := partial "i18n/fallback-page.html" $p -}}
25+
{{ if or (eq $siteLang $defaultLang) (not $fallbackPage) -}}
26+
{{ $from := cond (strings.HasPrefix .from "/")
27+
.from
28+
(print $p.RelPermalink .from) -}}
29+
{{ $to := cond (strings.HasPrefix .to "/")
30+
.to
31+
(print $p.RelPermalink .to) -}}
32+
{{ $from | printf "%-35s" }} {{ $to }}
33+
{{ else -}}
34+
{{/* # {{ $p.RelPermalink }} */ -}}
35+
{{ end -}}
36+
{{ end -}}
37+
{{ end -}}
38+
39+
{{ end -}}

0 commit comments

Comments
 (0)