Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i18n] Support localization of page-not-translated banner #6339

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions content/en/_includes/page-not-translated-msg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: # Bogus entry for markdownlint
_build: { list: never, render: never }
---

<i class="fa-solid fa-circle-info" style="margin-left: -1.5rem"></i> You are
viewing the **English version** of this page because it has not yet been
translated. Interested in helping out? See [Contributing](/docs/contributing/).
1 change: 1 addition & 0 deletions content/en/announcements/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ cascade:
type: docs
params:
hide_feedback: true
disable_translation_not_found_msg: true
---
2 changes: 1 addition & 1 deletion content/en/docs/demo/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: OpenTelemetry Demo Documentation
title: OpenTelemetry Demo Docs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title tweak in passing; it felt too long otherwise! (I'd even consider dropping the "Docs", given that this is under the Docs section of the website :)).

linkTitle: Demo
cascade:
repo: https://github.com/open-telemetry/opentelemetry-demo
Expand Down
5 changes: 4 additions & 1 deletion content/ja/announcements/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
title: お知らせ
cascade:
type: docs
default_lang_commit: 48eac183a4dd74946d5a45fa436cfc6052f30532
params:
hide_feedback: true
disable_translation_not_found_msg: true
default_lang_commit: 48eac183a4dd74946d5a45fa436cfc6052f30532 # patched
---
10 changes: 10 additions & 0 deletions content/pt/_includes/page-not-translated-msg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: # Bogus entry for markdownlint
_build: { list: never, render: never }
default_lang_commit: 8d115a9df96c52dbbb3f96c05a843390d90a9800
---

<i class="fa-solid fa-circle-info" style="margin-left: -1.5rem"></i> Você está
visualizando a versão em **versão em inglês** desta página porque ela ainda não
foi traduzida. Possui interesse em ajudar? Veja
[como contribuir](/docs/contributing/).
3 changes: 2 additions & 1 deletion content/pt/announcements/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ cascade:
type: docs
params:
hide_feedback: true
default_lang_commit: 2291fd884421f8a0bb47c72327c0681fdf116225
disable_translation_not_found_msg: true
default_lang_commit: 2291fd884421f8a0bb47c72327c0681fdf116225 # patched
---
18 changes: 18 additions & 0 deletions hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ module:
target: content
lang: es
# fallback pages
- source: content/en/_includes
target: content/_includes
lang: es
- source: content/en/announcements
target: content/announcements
lang: es
Expand All @@ -334,19 +337,28 @@ module:
target: content
lang: fr
# fallback pages
- source: content/en/_includes
target: content/_includes
lang: fr
- source: content/en/announcements
target: content/announcements
lang: fr
- excludeFiles: specs/*
source: content/en/docs
target: content/docs
lang: fr
# - source: content/en/ecosystem
# target: content/ecosystem
# lang: fr

## ja
- source: content/ja
target: content
lang: ja
# fallback pages
- source: content/en/_includes
target: content/_includes
lang: ja
- source: content/en/announcements
target: content/announcements
lang: ja
Expand All @@ -360,6 +372,9 @@ module:
target: content
lang: zh
# fallback pages
- source: content/en/_includes
target: content/_includes
lang: zh
- source: content/en/announcements
target: content/announcements
lang: zh
Expand All @@ -373,6 +388,9 @@ module:
target: content
lang: pt
# fallback pages
- source: content/en/_includes
target: content/_includes
lang: pt
- source: content/en/announcements
target: content/announcements
lang: pt
Expand Down
35 changes: 25 additions & 10 deletions layouts/docs/td-content-after-header.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
{{ $pageProseLang := partial "i18n/lang.html" . -}}
{{ $siteLang := .Site.Language -}}

{{ if ne $siteLang $pageProseLang -}}
{{ if and
(ne $siteLang $pageProseLang)
(not (.Param "disable_translation_not_found_msg"))
-}}
{{ with partial "_inline/ot-page-not-found-banner.html" . -}}
<div class="pageinfo pageinfo-secondary">
<div class="ps-4">
{{ . }}
</div>
</div>
{{ end -}}
{{ end -}}

<div class="pageinfo pageinfo-secondary">
<p class="ps-4">
<i class="fa-solid fa-circle-info" style="margin-left: -1.5rem"></i>
You are viewing the <strong>English version</strong> of this page because it
has not yet been translated. Interested in helping out? See
<a href="/docs/contributing/">Contributing</a>.
</p>
</div>
{{ define "partials/_inline/ot-page-not-found-banner.html" }}
{{ $path := "page-not-translated-msg.md" -}}
{{ $args := (dict
"path" $path
"page" .Page) -}}
{{ $page := partial "func/find-include.html" $args -}}
{{ with $page -}}
{{ .Content }}
{{ else -}}
{{ $lang := .Page.Language.Lang -}}
{{ warnf "_inline/ot-page-not-found-banner: '%s' not found from page %s (%s)" $path .Page.Path $lang -}}
{{ end -}}
{{ end -}}

{{- end -}}
35 changes: 35 additions & 0 deletions layouts/partials/func/find-include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{/*
Args: .path .page

Looks for the page specified by .path, starting from .page, moving up the
.Parent relation if necessary. If .path isn't explicitly absoulte or relative,
"_includes/" is prepended to it.

*/ -}}

{{ $path := .path -}}
{{ if not (or
(strings.HasPrefix $path "/" )
(strings.HasPrefix $path "."))
-}}
{{ $path = printf "_includes/%s" $path -}}
{{ end -}}

{{ $result := partial "func/_find-include.html" (dict "path" $path "page" .page) -}}
{{ return $result -}}

{{ define "partials/func/_find-include.html" -}}
{{ $result := "" -}}
{{ $page_to_include := .page.GetPage .path -}}

{{ with $page_to_include -}}
{{ $result = . }}
{{ else -}}
{{ $parent := .page.Parent -}}
{{ if $parent -}}
{{ $result = partial "func/_find-include.html" (dict "path" .path "page" $parent) -}}
{{end -}}
{{ end -}}

{{ return $result -}}
{{ end -}}
33 changes: 12 additions & 21 deletions layouts/shortcodes/include.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@
calls to shortcodes. */ -}}

{{ $path := .Get 0 -}}
{{ if not (or
(strings.HasPrefix $path "/" )
(strings.HasPrefix $path "."))
-}}
{{ $path = printf "_includes/%s" $path -}}
{{ end -}}

{{ template "getPage" (dict "ctx" . "path" $path "page" .Page) -}}
{{ $page := partial "func/find-include.html" (dict "path" $path "page" .Page) -}}
{{ with $page -}}
{{ .Content -}}
{{ else -}}
{{ $msg := printf
"Can't include '%s': file not found in page or ancestor contexts of page %s."
$path .Page.Path -}}
{{ warnf $msg -}}

{{ define "getPage" -}}
{{ $page_to_include := .page.GetPage .path -}}
{{ with $page_to_include -}}
{{ .Content -}}
{{ else -}}
{{ $parent := .page.Parent -}}
{{ if $parent -}}
{{ template "getPage" (dict "ctx" .ctx "path" .path "page" $parent) -}}
{{ else -}}
{{ warnf "File not found: %s in page: %s" .path .ctx.Page.Path -}}
**ERROR**: File not found: {{ .path }}.
{{end -}}
{{ end -}}
<div class="alert alert-warning">
<div class="h4 alert-heading">INTERNAL SITE ERROR</div>
{{ $msg }}
</div>
{{ end -}}