Skip to content

Commit aa8380e

Browse files
committed
[i18n] Support localization of page-not-translated banner
1 parent 8d115a9 commit aa8380e

File tree

10 files changed

+115
-34
lines changed

10 files changed

+115
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: # Bogus entry for markdownlint
3+
_build: { list: never, render: never }
4+
---
5+
6+
<i class="fa-solid fa-circle-info" style="margin-left: -1.5rem"></i> You are
7+
viewing the **English version** of this page because it has not yet been
8+
translated. Interested in helping out? See [Contributing](/docs/contributing/).

content/en/announcements/_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ cascade:
44
type: docs
55
params:
66
hide_feedback: true
7+
disable_translation_not_found_msg: true
78
---

content/en/docs/demo/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: OpenTelemetry Demo Documentation
2+
title: OpenTelemetry Demo Docs
33
linkTitle: Demo
44
cascade:
55
repo: https://github.com/open-telemetry/opentelemetry-demo

content/ja/announcements/_index.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
title: お知らせ
33
cascade:
44
type: docs
5-
default_lang_commit: 48eac183a4dd74946d5a45fa436cfc6052f30532
5+
params:
6+
hide_feedback: true
7+
disable_translation_not_found_msg: true
8+
default_lang_commit: 48eac183a4dd74946d5a45fa436cfc6052f30532 # patched
69
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: # Bogus entry for markdownlint
3+
_build: { list: never, render: never }
4+
---
5+
6+
<i class="fa-solid fa-circle-info" style="margin-left: -1.5rem"></i> Você está
7+
visualizando a versão em **versão em inglês** desta página porque ela ainda não
8+
foi traduzida. Possui interesse em ajudar? Veja
9+
[como contribuir](/docs/contributing/).

content/pt/announcements/_index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ cascade:
44
type: docs
55
params:
66
hide_feedback: true
7-
default_lang_commit: 2291fd884421f8a0bb47c72327c0681fdf116225
7+
disable_translation_not_found_msg: true
8+
default_lang_commit: 2291fd884421f8a0bb47c72327c0681fdf116225 # patched
89
---

hugo.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ module:
321321
target: content
322322
lang: es
323323
# fallback pages
324+
- source: content/en/_includes
325+
target: content/_includes
326+
lang: es
324327
- source: content/en/announcements
325328
target: content/announcements
326329
lang: es
@@ -334,19 +337,28 @@ module:
334337
target: content
335338
lang: fr
336339
# fallback pages
340+
- source: content/en/_includes
341+
target: content/_includes
342+
lang: fr
337343
- source: content/en/announcements
338344
target: content/announcements
339345
lang: fr
340346
- excludeFiles: specs/*
341347
source: content/en/docs
342348
target: content/docs
343349
lang: fr
350+
# - source: content/en/ecosystem
351+
# target: content/ecosystem
352+
# lang: fr
344353

345354
## ja
346355
- source: content/ja
347356
target: content
348357
lang: ja
349358
# fallback pages
359+
- source: content/en/_includes
360+
target: content/_includes
361+
lang: ja
350362
- source: content/en/announcements
351363
target: content/announcements
352364
lang: ja
@@ -360,6 +372,9 @@ module:
360372
target: content
361373
lang: zh
362374
# fallback pages
375+
- source: content/en/_includes
376+
target: content/_includes
377+
lang: zh
363378
- source: content/en/announcements
364379
target: content/announcements
365380
lang: zh
@@ -373,6 +388,9 @@ module:
373388
target: content
374389
lang: pt
375390
# fallback pages
391+
- source: content/en/_includes
392+
target: content/_includes
393+
lang: pt
376394
- source: content/en/announcements
377395
target: content/announcements
378396
lang: pt

layouts/docs/td-content-after-header.html

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
{{ $pageProseLang := partial "i18n/lang.html" . -}}
22
{{ $siteLang := .Site.Language -}}
33

4-
{{ if ne $siteLang $pageProseLang -}}
4+
{{ if and
5+
(ne $siteLang $pageProseLang)
6+
(not (.Param "disable_translation_not_found_msg"))
7+
-}}
8+
{{ with partial "_inline/ot-page-not-found-banner.html" . -}}
9+
<div class="pageinfo pageinfo-secondary">
10+
<div class="ps-4">
11+
{{ . }}
12+
</div>
13+
</div>
14+
{{ end -}}
15+
{{ end -}}
516

6-
<div class="pageinfo pageinfo-secondary">
7-
<p class="ps-4">
8-
<i class="fa-solid fa-circle-info" style="margin-left: -1.5rem"></i>
9-
You are viewing the <strong>English version</strong> of this page because it
10-
has not yet been translated. Interested in helping out? See
11-
<a href="/docs/contributing/">Contributing</a>.
12-
</p>
13-
</div>
17+
{{ define "partials/_inline/ot-page-not-found-banner.html" }}
18+
{{ $path := "page-not-translated-msg.md" -}}
19+
{{ $args := (dict
20+
"path" $path
21+
"page" .Page) -}}
22+
{{ $page := partial "func/find-include.html" $args -}}
23+
{{ with $page -}}
24+
{{ .Content }}
25+
{{ else -}}
26+
{{ $lang := .Page.Language.Lang -}}
27+
{{ warnf "_inline/ot-page-not-found-banner: '%s' not found from page %s (%s)" $path .Page.Path $lang -}}
28+
{{ end -}}
29+
{{ end -}}
1430

15-
{{- end -}}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{/*
2+
Args: .path .page
3+
4+
Looks for the page specified by .path, starting from .page, moving up the
5+
.Parent relation if necessary. If .path isn't explicitly absoulte or relative,
6+
"_includes/" is prepended to it.
7+
8+
*/ -}}
9+
10+
{{ $path := .path -}}
11+
{{ if not (or
12+
(strings.HasPrefix $path "/" )
13+
(strings.HasPrefix $path "."))
14+
-}}
15+
{{ $path = printf "_includes/%s" $path -}}
16+
{{ end -}}
17+
18+
{{ $result := partial "func/_find-include.html" (dict "path" $path "page" .page) -}}
19+
{{ return $result -}}
20+
21+
{{ define "partials/func/_find-include.html" -}}
22+
{{ $result := "" -}}
23+
{{ $page_to_include := .page.GetPage .path -}}
24+
25+
{{ with $page_to_include -}}
26+
{{ $result = . }}
27+
{{ else -}}
28+
{{ $parent := .page.Parent -}}
29+
{{ if $parent -}}
30+
{{ $result = partial "func/_find-include.html" (dict "path" .path "page" $parent) -}}
31+
{{end -}}
32+
{{ end -}}
33+
34+
{{ return $result -}}
35+
{{ end -}}

layouts/shortcodes/include.md

+12-21
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,17 @@
22
calls to shortcodes. */ -}}
33

44
{{ $path := .Get 0 -}}
5-
{{ if not (or
6-
(strings.HasPrefix $path "/" )
7-
(strings.HasPrefix $path "."))
8-
-}}
9-
{{ $path = printf "_includes/%s" $path -}}
10-
{{ end -}}
11-
12-
{{ template "getPage" (dict "ctx" . "path" $path "page" .Page) -}}
5+
{{ $page := partial "func/find-include.html" (dict "path" $path "page" .Page) -}}
6+
{{ with $page -}}
7+
{{ .Content -}}
8+
{{ else -}}
9+
{{ $msg := printf
10+
"Can't include '%s': file not found in page or ancestor contexts of page %s."
11+
$path .Page.Path -}}
12+
{{ warnf $msg -}}
1313

14-
{{ define "getPage" -}}
15-
{{ $page_to_include := .page.GetPage .path -}}
16-
{{ with $page_to_include -}}
17-
{{ .Content -}}
18-
{{ else -}}
19-
{{ $parent := .page.Parent -}}
20-
{{ if $parent -}}
21-
{{ template "getPage" (dict "ctx" .ctx "path" .path "page" $parent) -}}
22-
{{ else -}}
23-
{{ warnf "File not found: %s in page: %s" .path .ctx.Page.Path -}}
24-
**ERROR**: File not found: {{ .path }}.
25-
{{end -}}
26-
{{ end -}}
14+
<div class="alert alert-warning">
15+
<div class="h4 alert-heading">INTERNAL SITE ERROR</div>
16+
{{ $msg }}
17+
</div>
2718
{{ end -}}

0 commit comments

Comments
 (0)