Skip to content

Commit b27512e

Browse files
committed
Add i18n consistency-checker
1 parent 9635fc4 commit b27512e

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: i18n check consistency and notify on GitHub Issues
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- .github/workflows/i18n-consistency-check.yml
9+
schedule:
10+
- cron: '0 0 1 * *'
11+
workflow_dispatch:
12+
13+
jobs:
14+
consistency-check:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
language: [ja, zh]
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
fetch-depth: '0'
23+
- name: Check consistency
24+
id: check-consistency
25+
run: |
26+
# Set the issue header
27+
issue="\
28+
# i18n Contents Consistency Issue\\n\
29+
\\n\
30+
The following files may have consistency issues with the English version. Please check and update the files.\\n\
31+
\\n\
32+
This issue is created when there is an update to content/en. It compares the git update history to let you know what updates are overdue. The issue should be closed when the update is complete.\\n"
33+
34+
for file in $(find patterns/2-structured -name '*.md'); do
35+
36+
# Get the translated file name and check if it exists
37+
i18n_filename=$(echo "$file" | sed 's/patterns\/2-structured/translation\/${{matrix.language}}\/patterns/g')
38+
if [[ ! -e "$i18n_filename" ]]; then
39+
continue
40+
fi
41+
echo $file
42+
echo $i18n_filename
43+
# Loop through all the files in the English directory
44+
# Get the last updated date of the original file and the translated file
45+
original_updated_at=$(date -d "$(git log -1 --format=%cd --date=iso $file)" +%s)
46+
i18n_content_updated_at=$(date -d "$(git log -1 --format=%cd --date=iso $i18n_filename)" +%s)
47+
48+
# print the last updated date of the original file and the translated file
49+
50+
# Check if the translated file is updated after the original file
51+
if [[ $(($original_updated_at - $i18n_content_updated_at)) -ge 1 ]]; then
52+
# Get the title of the content
53+
content_header=$(echo "$(cat "$file")" | grep -E '^title+' | sort -r | head -n1)
54+
content_title=$(echo "$content_header" | sed 's/title: //g')
55+
56+
# Get the days since the translated file is overdue
57+
days_since_overdue_updates=$(($(( $(date +%s) - $original_updated_at))/ 60 / 60 / 24))
58+
# Get the diff between the original file and the translated file
59+
original_last_update_hash=$(git log -1 --format=%H $file)
60+
# Get the parent hash of the original last update hash
61+
parent_hash=$(git log -1 --format=%P $original_last_update_hash)
62+
# Get the diff between the original file and the translated file
63+
64+
result=$(echo "$(git diff ${parent_hash} HEAD $file)" | sed '1,4 s/^/# /')
65+
echo -e "$result"
66+
67+
# Add the contents to the issue.md file
68+
issue+="<details><summary><b>$content_title</b> ($file)</summary>\\n\\n"
69+
issue+="- Original File(en): [$file](https://github.com/$GITHUB_REPOSITORY/blob/master/$file)\\n"
70+
issue+="- Translated File(${{matrix.language}}): [$i18n_filename](https://github.com/$GITHUB_REPOSITORY/blob/master/$i18n_filename)\\n"
71+
issue+="- [Diff on GitHub](https://github.com/yuhattor/innersourcecommons.org/compare/$i18n_last_update_hash...$original_last_update_hash)\\n"
72+
issue+="- Days since overdue updates: $days_since_overdue_updates days\\n"
73+
issue+="\`\`\`diff\\n"
74+
issue+="$result"
75+
issue+="\\n\`\`\`\\n"
76+
issue+="</details>\\n"
77+
echo -e "$issue" >> issue.md
78+
issue=""
79+
fi
80+
done
81+
- name: Create Issue
82+
run: |
83+
# Declare the flags
84+
declare -A flags=(
85+
["ja"]="🇯🇵 Japanese"
86+
["zh"]="🇨🇳 Chinese"
87+
)
88+
89+
# Set the issue title
90+
issue_title="${flags[${{matrix.language}}]}: Content Consistency Issue"
91+
92+
# Get the existing issue ID
93+
existing_issue_id=$(gh issue list -S "state:open type:issue title:$issue_title" | cut -f1)
94+
95+
# If the issue.md file exists, create a new issue or comment on the existing issue
96+
if [ -f issue.md ]; then
97+
if expr "$existing_issue_id" : '^[0-9]*$' >/dev/null; then
98+
gh issue comment "$existing_issue_id" -F issue.md -R $GITHUB_REPOSITORY
99+
else
100+
gh issue create -t "$issue_title" -F issue.md -R $GITHUB_REPOSITORY -l documentation
101+
fi
102+
fi
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)