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 all commits
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/).
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
2 changes: 1 addition & 1 deletion content/en/docs/languages/js/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ weight: 20

{{% docs/languages/index-intro js /%}}

{{% include browser-instrumentation-warning.md %}}
{{% include "./_browser-instrumentation-warning.md" %}}

## Version Support

Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/languages/js/getting-started/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Learn how to add OpenTelemetry to your browser app
weight: 20
---

{{% include browser-instrumentation-warning.md %}}
{{% include "./_browser-instrumentation-warning.md" %}}

While this guide uses the example application presented below, the steps to
instrument your own application should be similar.
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/languages/js/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ above, you have a `TracerProvider` setup for you already. You can continue with

#### Browser

{{% include browser-instrumentation-warning.md %}}
{{% include "./_browser-instrumentation-warning.md" %}}

First, ensure you've got the right packages:

Expand Down
2 changes: 2 additions & 0 deletions content/ja/announcements/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
title: お知らせ
cascade:
type: docs
params:
hide_feedback: true
default_lang_commit: 48eac183a4dd74946d5a45fa436cfc6052f30532
---
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/).
2 changes: 1 addition & 1 deletion content/pt/docs/languages/js/getting-started/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 20
default_lang_commit: 7cb1bd39726fc03698164ee17fe9087afdac054c
---

{{% include browser-instrumentation-warning.md %}}
{{% include "./_browser-instrumentation-warning.md" %}}

Embora este guia utilize o exemplo de aplicação apresentada abaixo, as etapas
para instrumentar a sua própria aplicação devem ser similares.
Expand Down
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
49 changes: 37 additions & 12 deletions layouts/docs/td-content-after-header.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
{{ $pageProseLang := partial "i18n/lang.html" . -}}
{{ $siteLang := .Site.Language -}}

{{ if ne $siteLang $pageProseLang -}}

<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>

{{- end -}}
{{/*

The disable_translation_not_found_msg param isn't currently used and I suspect
that we won't need it, but I'll wait until the following feature is implemented
before removing the code:

https://github.com/open-telemetry/opentelemetry.io/issues/6340

*/ -}}

{{ 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 -}}

{{ 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 -}}

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 absolute 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 -}}