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 & CI] Add default_lang_commit to front matter of all non en pages #4612

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
1 change: 1 addition & 0 deletions content/ja/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: >-
効果的な観測を可能にする、高品質でユビキタスかつポータブルなテレメトリー
developer_note:
blocks/coverコラム(以下で使用)は、ファイル名に "background" を含む画像ファイルを背景画像として使用します。
default_lang_commit: 902043db
---

<div class="d-none"><a rel="me" href="https://fosstodon.org/@opentelemetry"></a></div>
Expand Down
1 change: 1 addition & 0 deletions content/zh/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ show_banner: true
developer_note:
下文所用的 blocks/cover 短代码将使用文件名中包含 "background"
的图像文件作为背景图。
default_lang_commit: 6e35a949
---

<div class="d-none"><a rel="me" href="https://fosstodon.org/@opentelemetry"></a></div>
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: 文档
menu: { main: { weight: 10 } }
default_lang_commit: 6e35a949
---

OpenTelemetry 也被称为 OTel,是一个供应商中立的、开源的[可观测性](concepts/observability-primer/#what-is-observability)框架,
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/concepts/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linkTitle: 概念
description: OpenTelemetry 核心概念
aliases: [concepts/overview]
weight: 170
default_lang_commit: d638c386
---

在本节中,你将了解 OpenTelemetry 项目的数据来源和关键组件。
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/concepts/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: 组件
description: 构成 OpenTelemetry 的主要组件
aliases: [data-collection]
weight: 20
default_lang_commit: 1ca30b4d
---

OpenTelemetry 项目目前由以下几个主要部分构成:
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/concepts/context-propagation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: 上下文传播
weight: 10
description: 了解实现分布式追踪的概念。
default_lang_commit: 7bb7dbb6
---

通过上下文传播,[信号](/docs/concepts/signals)可以相互关联,
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/concepts/semantic-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: 语义约定
description: 不同类型的操作和数据的通用名称。
weight: 30
default_lang_commit: 71d813acaa3dcb7d8ae3f96451406276f84242f4
---

OpenTelemetry 定义了[语义约定](/docs/specs/semconv/),
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/demo/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cascade:
repo: https://github.com/open-telemetry/opentelemetry-demo
weight: 2
cSpell:ignore: OLJCESPC
default_lang_commit: b7ee690154aacc8d6e43636af00743994fb6dc27
---

欢迎使用 [OpenTelemetry 演示](/ecosystem/demo/)文档,
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/kubernetes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: 使用 Kubernetes 部署 OpenTelemetry
linkTitle: Kubernetes
weight: 11
description: Using OpenTelemetry with Kubernetes
default_lang_commit: 54bc7873eaf53af1314feef7f91797d5d261a57b
---

## 介绍
Expand Down
1 change: 1 addition & 0 deletions content/zh/docs/what-is-opentelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: 什么是 OpenTelemetry?
description: 简短说明 OpenTelemetry 是什么,不是什么。
weight: 150
default_lang_commit: d638c386
---

OpenTelemetry
Expand Down
75 changes: 58 additions & 17 deletions scripts/i18n-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
#
# Inspired by https://github.com/kubernetes/website/blob/main/scripts/lsync.sh

DEFAULT_LANG="en"
DEFAULT_TARGET="content"
EXTRA_DIFF_ARGS="--numstat"
FLAG_UPDATE=""
FLAG_VERBOSE=""
I18N_DLC_KEY="default_lang_commit"
TARGET_PATHS=""

function _usage() {
cat <<EOS
Usage: $(basename "$0") [options] TARGET_PATH ...
Usage: $(basename "$0") [options] [TARGET_PATH ...]

For each localized page target, this script reports whether the English
language version of that page has changed since the localized file was
first written or last edited.

TARGET_PATH can be a single markdown file of a localized page, such as
'content/ja/_index.md', or a directory of localized pages, such as 'content/ja'.
The default TARGET_PATH is '$DEFAULT_TARGET'.

-h Output this usage info.
-d Output diff details.
-v Verbose mode.
-u Update, or add, target commit hashes to match the last commit they were updated from.
-v Enables verbose command progress and status output.
EOS
}

Expand All @@ -29,16 +36,19 @@ function usage() {
}

function process_CLI_args() {
while getopts ":hdv" opt; do
while getopts ":hduv" opt; do
case $opt in
h)
usage
;;
d)
EXTRA_DIFF_ARGS=""
;;
u)
FLAG_UPDATE=1
;;
v)
VERBOSE=1
FLAG_VERBOSE=1
;;
\?)
echo "ERROR: unrecognized flag: -$OPTARG"
Expand All @@ -48,48 +58,79 @@ function process_CLI_args() {
done

shift $((OPTIND-1))
if [ "$#" -lt 1 ]; then
echo "ERROR: target path argument is missing" >&2
usage 1
fi

TARGET_PATHS="$@"

if [[ -z "$TARGET_PATHS" ]]; then
TARGET_PATHS="$DEFAULT_TARGET"
if [[ -n $FLAG_VERBOSE ]]; then echo "INFO: using default target path: $TARGET_PATHS"; fi
fi

if [[ -f "TARGET_PATHS" && ! -e "$TARGET_PATHS" ]] ; then
echo "Path not found: '$TARGET_PATHS'" >&2
exit 2
fi
}

function update_i18n_hash() {
# Usage: update_i18n_hash <file> <commit>
#
# Adds to or updates the file's front matter's field
# $I18N_DLC_KEY with value <commit>.

local LASTCOMMIT="$1"
local f="$2"

if grep -q "^$I18N_DLC_KEY:" "$f"; then
perl -i -pe "s/(^$I18N_DLC_KEY):.*/\$1: $LASTCOMMIT/" "$f"
else
perl -i -0777 -pe "s/^(---.*?)(\n---\n)/\$1\n$I18N_DLC_KEY: $LASTCOMMIT\$2/sm" "$f"
fi
if [[ -n $FLAG_VERBOSE ]]; then
echo -e "i18n commit ID\t$f $LASTCOMMIT - updated"
fi
}

function main() {
process_CLI_args "$@"

if [ -f "$TARGET_PATHS" ] ; then
TARGETS="$TARGET_PATHS"
else
TARGETS=$(find $TARGET_PATHS -name "*.md")
TARGETS=$(find $TARGET_PATHS -name "*.md" -not -path "*/$DEFAULT_LANG/*")
if [[ -z "$TARGETS" ]]; then
echo "ERROR: target directory contains no markdown files: '$TARGET_PATHS'" >&2
exit 1
fi
# if [[ -n $VERBOSE ]]; then echo -e "All targets: $TARGETS"; fi
# if [[ -n $FLAG_VERBOSE ]]; then echo -e "All targets: $TARGETS"; fi
fi

SYNCED=1
for f in $TARGETS; do
# if [[ -n $VERBOSE ]]; then echo -e "Checking\t$f"; fi
# if [[ -n $FLAG_VERBOSE ]]; then echo -e "Checking\t$f"; fi
EN_VERSION=$(echo "$f" | sed "s/content\/.\{2,5\}\//content\/en\//g")

# Try to get commit ref from file front matter
LASTCOMMIT=$(perl -ne "print \"\$1\" if /^$I18N_DLC_KEY:\\s*(.*)/" "$f")
if [[ -z $LASTCOMMIT ]]; then
# Get commit hash from git commit info
LASTCOMMIT=$(git log -n 1 --pretty=format:%h -- "$f")
fi

if [[ -n $FLAG_UPDATE ]]; then
update_i18n_hash "$LASTCOMMIT" "$f"
fi

if [[ ! -e "$EN_VERSION" ]]; then
echo "Base file renamed or removed: $EN_VERSION"
echo -e "File not found\t$EN_VERSION - $f - $DEFAULT_LANG was removed or renamed"
SYNCED=0
continue
fi

LASTCOMMIT=$(git log -n 1 --pretty=format:%h -- "$f")
git diff --exit-code $EXTRA_DIFF_ARGS $LASTCOMMIT...HEAD "$EN_VERSION"
if [ $? -ne 0 ] ; then
DIFF=$(git diff --exit-code $EXTRA_DIFF_ARGS $LASTCOMMIT...HEAD "$EN_VERSION")
if [[ -n "$DIFF" ]]; then # [[ $? -ne 0 ]]
echo "$DIFF - $f"
SYNCED=0
elif [[ -n $VERBOSE ]]; then
elif [[ -n $FLAG_VERBOSE ]]; then
echo -e "File is in sync\t$f"
fi
done
Expand Down