Skip to content

Commit b895b4c

Browse files
authored
[CI & i18n] i18n script and doc improvements (#4648)
1 parent 767f85d commit b895b4c

File tree

6 files changed

+385
-188
lines changed

6 files changed

+385
-188
lines changed

.github/workflows/check-i18n.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ on:
44
pull_request:
55

66
jobs:
7-
i18n-check:
7+
check-i18n:
88
name: I18N check
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 0 # all
14-
- run: scripts/i18n-check.sh -u
15-
- run: .github/workflows/scripts/i18n-check-helper.sh
14+
- name: Any files missing hash key?
15+
run: scripts/check-i18n.sh -n -x -v
16+
- name: Any files with invalid hash keys?
17+
run: scripts/check-i18n.sh -v
18+
- run: .github/workflows/scripts/check-i18n-helper.sh

.github/workflows/scripts/i18n-check-helper.sh renamed to .github/workflows/scripts/check-i18n-helper.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ if [[ -z $CHANGES ]]; then
1010
fi
1111

1212
cat <<EOS
13-
Some i18n pages are missing the 'default_lang_commit' front matter field.
14-
To fix this in your local development environment, run
13+
Some localization pages are missing the 'default_lang_commit' front matter
14+
field. To fix this in your local development environment, run
1515
16-
scripts/i18n-check.sh -u
16+
npm run fix:i18n:new
1717
18-
and commit the changes for your locale. Here are the list of pages that
18+
and commit the changes for your localization. Here are the list of pages that
1919
need to be updated:
2020
---
2121
EOS

content/en/docs/contributing/localization.md

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dropdown menu in the top nav.
1919

2020
## Keeping track of localized page drift {#track-changes}
2121

22-
One of the main challenges of maintaining localized pages is identifying when
22+
One of the main challenges of maintaining localized pages, is identifying when
2323
the corresponding English language pages have been updated. This section
2424
explains how we handle this.
2525

@@ -28,19 +28,21 @@ explains how we handle this.
2828
When a localized page is written, such as `content/zh/<some-path>/page.md`, this
2929
translation is based on a specific [`main` branch commit][main] of the
3030
corresponding English language version of the page at
31-
`content/en/<some-path>/page.md`. Every localized page identifies this commit in
32-
the page's front matter as follows:
31+
`content/en/<some-path>/page.md`. In this repository, every localized page
32+
identifies the English page commit in the localized page's front matter as
33+
follows:
3334

3435
```markdown
3536
---
3637
title: Your localized page title
3738
...
3839

39-
## default_lang_commit: <commit-hash-of-main-for-default-language-page>
40+
default_lang_commit: <commit-hash-of-main-for-default-language-page>
4041
```
4142

4243
The front matter above would be in `content/zh/<some-path>/page.md`. The commit
43-
corresponds to the latest commit of `content/en/<some-path>/page.md` in `main`.
44+
would correspond to the latest commit of `content/en/<some-path>/page.md` in
45+
`main`.
4446

4547
### Tracking changes to English pages
4648

@@ -49,25 +51,26 @@ corresponding localized pages that need updating by running the following
4951
command:
5052

5153
```console
52-
$ scripts/i18n-check.sh
54+
$ npm run check:i18n
5355
1 1 content/en/docs/kubernetes/_index.md - content/zh/docs/kubernetes/_index.md
5456
...
5557
```
5658

57-
Specify the path to your localization to restrict the output, for example:
59+
You can restrict the target pages to one or more localizations by providing
60+
path(s) like this:
5861

5962
```sh
60-
scripts/i18n-check.sh content/zh
63+
npm run check:i18n -- content/zh
6164
```
6265

6366
### Viewing change details
6467

6568
For any given localized pages that need updating, you can see the diff details
6669
of the corresponding English language pages by using the `-d` flag and providing
67-
the paths to your localized pages. For example:
70+
the paths to your localized pages, or omit the paths to see all. For example:
6871

6972
```console
70-
$ scripts/i18n-check.sh -d content/zh/docs/kubernetes
73+
$ npm run check:i18n -- -d content/zh/docs/kubernetes
7174
diff --git a/content/en/docs/kubernetes/_index.md b/content/en/docs/kubernetes/_index.md
7275
index 3592df5d..c7980653 100644
7376
--- a/content/en/docs/kubernetes/_index.md
@@ -87,12 +90,20 @@ index 3592df5d..c7980653 100644
8790
As you create pages for your localization, remember to add `default_lang_commit`
8891
to the page front matter along with an appropriate commit hash from `main`.
8992

90-
If your translation is based on an English page in `main` at `HEAD`, then run
91-
the following command to automatically add `default_lang_commit` to your page
92-
file's front matter using the commit hash at `HEAD`:
93+
If your page translation is based on an English page in `main` at `<hash>`, then
94+
run the following command to automatically add `default_lang_commit` to your
95+
page file's front matter using the commit `<hash>`. You can specify `HEAD` as an
96+
argument if your pages are now synced with `main` at `HEAD`. For example:
9397

9498
```sh
95-
scripts/i18n-check.sh -u <PATH-TO-YOUR-NEW-FILES>
99+
npm run check:i18n -- -n -c 1ca30b4d content/ja
100+
npm run check:i18n -- -n -c HEAD content/zh/docs/concepts
101+
```
102+
103+
To list localization page files with missing hash keys, run:
104+
105+
```sh
106+
npm run check:i18n -- -n
96107
```
97108

98109
### Updating `default_lang_commit` for existing pages
@@ -105,11 +116,32 @@ commit hash.
105116

106117
If your localized page now corresponds to the English language version in `main`
107118
at `HEAD`, then erase the commit hash value in the front matter, and run the
108-
update command given in the previous section to automatically refresh the
119+
**add** command given in the previous section to automatically refresh the
109120
`default_lang_commit` field value.
110121

111122
{{% /alert %}}
112123

124+
If you have batch updated all of your localization pages that had drifted, you
125+
can update the commit hash of these files using the `-u` flag followed by a
126+
commit hash or 'HEAD' to use `main@HEAD`.
127+
128+
```sh
129+
npm run check:i18n -- -c <hash> <PATH-TO-YOUR-NEW-FILES>
130+
npm run check:i18n -- -c HEAD <PATH-TO-YOUR-NEW-FILES>
131+
```
132+
133+
{{% alert title="Important" %}}
134+
135+
When you use `HEAD` as a hash specifier, the script will use the hash of `main`
136+
at HEAD in your **local environment**. Make sure that you fetch and pull `main`,
137+
if you want HEAD to correspond to `main` in GitHub.
138+
139+
{{% /alert %}}
140+
141+
### Script help
142+
143+
For more details about the script, run `npm run check:i18n -- -h`.
144+
113145
## New localizations
114146

115147
(Section To Be Completed soon with information about how to propose a new

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"cd:public": "cd public &&",
4242
"check:filenames": "test -z \"$(npm run -s _ls-bad-filenames)\" || npm run -s _filename-error",
4343
"check:format": "npm run _check:format && npm run _check:format:ja+zh || (echo '[help] Run: npm run fix:format'; exit 1)",
44+
"check:i18n": "scripts/check-i18n.sh",
4445
"check:links:internal": "npm run _check:links:internal",
4546
"check:links": "npm run _check:links",
4647
"check:markdown": "scripts/check-markdown-wrapper.sh",
@@ -58,7 +59,10 @@
5859
"fix:dict": "find content layouts -name \"*.md\" -print0 | xargs -0 scripts/normalize-cspell-front-matter.pl",
5960
"fix:filenames": "npm run _rename-to-kebab-case",
6061
"fix:format": "npm run format",
61-
"fix:i18n": "scripts/i18n-check.sh -u",
62+
"fix:i18n:all": "scripts/check-i18n.sh -a -c HEAD",
63+
"fix:i18n:drifted": "scripts/check-i18n.sh -c HEAD",
64+
"fix:i18n:new": "scripts/check-i18n.sh -n -c HEAD",
65+
"fix:i18n": "npm run fix:i18n:new",
6266
"fix:markdown": "npm run check:markdown -- --fix",
6367
"fix:refcache": "npm run check:links",
6468
"fix:submodules": "npm run _sync",

0 commit comments

Comments
 (0)