Skip to content

Commit e7c30e9

Browse files
authored
[i18n] Render-link fix: prepend lang code when page exists (#5554)
1 parent d619b83 commit e7c30e9

File tree

7 files changed

+110
-21
lines changed

7 files changed

+110
-21
lines changed

.htmltest.yml

+34
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,44 @@ IgnoreDirs:
1010
# DO NOT EDIT! IgnoreDirs list is auto-generated from markdown file front matter.
1111
# Ignore blog index pages for all locales and in all blog sections (top-level and years)
1212
- ^(../)?blog/(\d+/)?page/\d+
13+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
14+
- ^es/docs/concepts/glossary/
15+
- ^es/docs/concepts/instrumentation/zero-code/
16+
- ^es/docs/concepts/signals/baggage/
17+
- ^es/docs/zero-code/php/
18+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
19+
- ^fr/docs/concepts/glossary/
20+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
21+
- ^ja/docs/concepts/components/
22+
- ^ja/docs/concepts/glossary/
23+
- ^ja/docs/concepts/signals/baggage/
24+
- ^ja/docs/languages/erlang/sampling/
25+
- ^ja/docs/languages/js/sampling/
26+
- ^ja/docs/languages/ruby/sampling/
27+
- ^ja/docs/zero-code/php/
1328
# TODO drop next line after https://github.com/open-telemetry/opentelemetry.io/issues/5423 is fixed for ja pages:
1429
- ^ja/docs/concepts/instrumentation/libraries/
30+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
31+
- ^pt/docs/concepts/components/
32+
- ^pt/docs/concepts/glossary/
33+
- ^pt/docs/concepts/signals/baggage/
34+
- ^pt/docs/languages/erlang/instrumentation/
35+
- ^pt/docs/languages/erlang/sampling/
36+
- ^pt/docs/languages/js/instrumentation/
37+
- ^pt/docs/languages/js/sampling/
38+
- ^pt/docs/languages/net/instrumentation/
39+
- ^pt/docs/languages/net/libraries/
40+
- ^pt/docs/languages/net/shim/
41+
- ^pt/docs/languages/php/instrumentation/
42+
- ^pt/docs/languages/python/instrumentation/
43+
- ^pt/docs/languages/ruby/instrumentation/
44+
- ^pt/docs/languages/ruby/sampling/
45+
- ^pt/docs/zero-code/php/
1546
# TODO drop next line after https://github.com/open-telemetry/opentelemetry.io/issues/5423 is fixed for pt pages:
1647
- ^pt/docs/concepts/instrumentation/libraries/
48+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
49+
- ^zh/docs/concepts/signals/baggage/
50+
- ^zh/docs/zero-code/php/
1751
# DO NOT EDIT! IgnoreDirs list is auto-generated from markdown file front matter.
1852
IgnoreInternalURLs: # list of paths
1953
IgnoreURLs: # list of regexs of paths or URLs to be ignored

content/es/docs/_index.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
title: Documentación
33
linkTitle: Docs
44
menu: { main: { weight: 10 } }
5+
htmltest:
6+
IgnoreDirs:
7+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
8+
- ^es/docs/concepts/glossary/
9+
- ^es/docs/concepts/instrumentation/zero-code/
10+
- ^es/docs/concepts/signals/baggage/
11+
- ^es/docs/zero-code/php/
512
default_lang_commit: f7cb8b65a478450d80d703b34c8473c579702108
613
---
714

content/fr/docs/what-is-opentelemetry.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ title: Qu'est-ce qu'OpenTelemetry ?
33
description:
44
Une brève explication de ce qu'est OpenTelemetry, et de ce qu'il n'est pas.
55
weight: 150
6+
htmltest:
7+
IgnoreDirs:
8+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
9+
- ^fr/docs/concepts/glossary/
610
default_lang_commit: 71833a5f8b84110dadf1e98604b87a900724ac33
711
---
812

content/ja/docs/_index.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
---
22
title: ドキュメント
33
menu: { main: { weight: 10 } }
4+
htmltest:
5+
IgnoreDirs:
6+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
7+
- ^ja/docs/concepts/components/
8+
- ^ja/docs/concepts/glossary/
9+
- ^ja/docs/concepts/signals/baggage/
10+
- ^ja/docs/languages/erlang/sampling/
11+
- ^ja/docs/languages/js/sampling/
12+
- ^ja/docs/languages/ruby/sampling/
13+
- ^ja/docs/zero-code/php/
414
default_lang_commit: c2cd5b14
515
---
616

content/pt/docs/_index.md

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
title: Documentação
33
linkTitle: Docs
44
menu: { main: { weight: 10 } }
5+
htmltest:
6+
IgnoreDirs:
7+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
8+
- ^pt/docs/concepts/components/
9+
- ^pt/docs/concepts/glossary/
10+
- ^pt/docs/concepts/signals/baggage/
11+
- ^pt/docs/languages/erlang/instrumentation/
12+
- ^pt/docs/languages/erlang/sampling/
13+
- ^pt/docs/languages/js/instrumentation/
14+
- ^pt/docs/languages/js/sampling/
15+
- ^pt/docs/languages/net/instrumentation/
16+
- ^pt/docs/languages/net/libraries/
17+
- ^pt/docs/languages/net/shim/
18+
- ^pt/docs/languages/php/instrumentation/
19+
- ^pt/docs/languages/python/instrumentation/
20+
- ^pt/docs/languages/ruby/instrumentation/
21+
- ^pt/docs/languages/ruby/sampling/
22+
- ^pt/docs/zero-code/php/
523
default_lang_commit: 2d88c10e1a14220a88a6e4859acb4047f49b6519
624
---
725

content/zh/docs/_index.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
22
title: 文档
33
menu: { main: { weight: 10 } }
4+
htmltest:
5+
IgnoreDirs:
6+
# TODO drop next lines after https://github.com/open-telemetry/opentelemetry.io/issues/5555 is fixed for these pages:
7+
- ^zh/docs/concepts/signals/baggage/
8+
- ^zh/docs/zero-code/php/
49
default_lang_commit: 6e35a949
510
---
611

layouts/_default/_markup/render-link.html

+32-21
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,44 @@
44

55
Localization link processing
66

7-
The following code block will prefix the page language code to an
8-
absolute path when:
7+
The following code will prefix $url with the language code of this page when:
98

109
- This page's localization isn't the default localization (English)
11-
- The URL is an absolute path that doesn't start with any of the following:
12-
- A language code, such as `ja`
13-
- A path segment other than `docs`, since current OTel localizations only
14-
offer translations for at most doc pages.
10+
- $url is an absolute path -- that is, it starts with /
11+
- The $url target page exists in this locale
1512

1613
*/ -}}
1714

18-
{{ $defaultLang := "en" -}} {{/* TODO: can we avoid hard coding this value? */ -}}
19-
{{ $lang := .Page.Language.Lang -}}
20-
{{ if ne $lang $defaultLang -}}
21-
{{ $langPathPrefix := add "/" $lang "/" -}}
22-
{{ if and (hasPrefix $url $langPathPrefix) .Page.File -}}
23-
{{ warnf "File %s: avoid prefixing the following link path with '%s': %s"
24-
.Page.File.Filename $langPathPrefix $url -}}
25-
{{ else if and (hasPrefix $url "/")
26-
(not (findRE "^/(blog|community|docs/specs|ecosystem|status)/?" $url))
27-
-}}
28-
{{ if and false (not (findRE "^/[a-z][a-z](-[a-zA-Z]{2})?/" $url)) -}}
29-
{{ $url = add $langPathPrefix (strings.TrimPrefix "/" $url) -}}
15+
{{ if hasPrefix $url "/" -}}
16+
{{/* Hard-coded default lang since it's what's most efficient and won't change :) */ -}}
17+
{{ $defaultLang := "en" -}}
18+
{{ $lang := .Page.Language.Lang -}}
19+
{{ if ne $lang $defaultLang -}}
20+
{{ $langPathPrefix := add "/" $lang "/" -}}
21+
{{ if and (hasPrefix $url $langPathPrefix) .Page.File -}}
22+
{{ warnf "File %s: drop unnecessary '%s' prefix from %s"
23+
.Page.File.Filename $langPathPrefix $url -}}
24+
{{ else -}}
25+
{{ $u := urls.Parse $url -}}
26+
{{ $localizedPagePath := add $langPathPrefix (strings.TrimPrefix "/" $url) -}}
27+
{{/*
28+
Look for the page (referenced by $url) in this page's locale's site.
29+
Note that .Page.GetPage exclusively looks for the given path in the same locale as .Page.
30+
*/ -}}
31+
{{ with .Page.GetPage $u.Path -}}
32+
{{/* warnf "Found url %s -> page %s. -- relRef %s" $localizedPagePath . (.RelRef (dict "path" $url))*/ -}}
33+
{{/* Assert (eq $localizedPagePath (.RelRef (dict "path" $url))) */ -}}
34+
{{ $url = $localizedPagePath -}}
35+
{{ else -}}
36+
{{/* Use $url as is, letting the link checker report any issues. */ -}}
37+
{{/* warnf "Render-link: locale %s doesn't have the page %s (%s)" $lang $url $localizedPagePath */ -}}
38+
{{ end -}}
3039
{{ end -}}
3140
{{ end -}}
3241
{{ end -}}
3342

34-
3543
{{/* General link-render processing */ -}}
3644

37-
{{ $url := .Destination -}}
3845
{{ $isExternal := hasPrefix $url "http" -}}
3946
{{ if $isExternal -}}
4047
{{ if findRE "^https://opentelemetry.io/\\w" $url -}}
@@ -61,4 +68,8 @@
6168
>
6269
{{- .Text | safeHTML -}}
6370
</a>
64-
{{- /* This comment ensures that all trailing whitespace is trimmed. */ -}}
71+
72+
{{- /*
73+
cSpell:ignore warnf
74+
This comment ensures that all trailing whitespace is trimmed.
75+
*/ -}}

0 commit comments

Comments
 (0)