Skip to content

Commit 56b4971

Browse files
Refactor: Rename to locales.yml, move to check-locales, remove docs/comments/prints, make MUI dynamic
Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
1 parent 95d3b02 commit 56b4971

File tree

4 files changed

+114
-317
lines changed

4 files changed

+114
-317
lines changed
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
name: Check Missing Locales
1+
name: Update Locales
22

33
on:
44
schedule:
5-
# Run every Sunday at midnight UTC (similar to validation patterns workflow)
65
- cron: "0 0 * * 0"
7-
workflow_dispatch: # Allow manual triggering
86

97
jobs:
10-
check-locales:
8+
update:
119
runs-on: ubuntu-latest
1210
permissions:
1311
contents: read
@@ -20,11 +18,18 @@ jobs:
2018
- name: Setup Python
2119
uses: actions/setup-python@v3
2220

23-
- name: Check for missing locales
21+
- name: Setup Node
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 16.x
25+
26+
- name: Install dependencies
27+
run: cd development && npm install
28+
29+
- name: Check locales
2430
id: check
2531
continue-on-error: true
26-
run: |
27-
python scripts/check-missing-locales
32+
run: python scripts/check-locales
2833

2934
- name: Read issue body
3035
if: steps.check.outcome == 'failure'
@@ -36,24 +41,22 @@ jobs:
3641
echo "EOF" >> $GITHUB_OUTPUT
3742
fi
3843
39-
- name: Check if issue already exists
44+
- name: Check existing issue
4045
if: steps.check.outcome == 'failure'
4146
id: check_issue
4247
env:
4348
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4449
run: |
45-
# Check for open issues with the label "missing-locales"
4650
ISSUE_COUNT=$(gh issue list --label "missing-locales" --state open --json number --jq 'length')
4751
echo "existing_issues=$ISSUE_COUNT" >> $GITHUB_OUTPUT
4852
49-
- name: Create GitHub Issue
53+
- name: Create issue
5054
if: steps.check.outcome == 'failure' && steps.check_issue.outputs.existing_issues == '0'
5155
uses: actions/github-script@v7
5256
with:
5357
github-token: ${{ secrets.GITHUB_TOKEN }}
5458
script: |
5559
const issueBody = `${{ steps.issue_body.outputs.issue_body }}`;
56-
5760
await github.rest.issues.create({
5861
owner: context.repo.owner,
5962
repo: context.repo.repo,
@@ -62,20 +65,10 @@ jobs:
6265
labels: ['missing-locales', 'translation', 'enhancement']
6366
});
6467
65-
- name: Update existing issue
68+
- name: Update issue
6669
if: steps.check.outcome == 'failure' && steps.check_issue.outputs.existing_issues != '0'
6770
env:
6871
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6972
run: |
70-
# Get the issue number
7173
ISSUE_NUMBER=$(gh issue list --label "missing-locales" --state open --json number --jq '.[0].number')
72-
73-
# Add a comment to the existing issue
74-
gh issue comment $ISSUE_NUMBER --body "🔄 **Updated Check Results**
75-
76-
The automated locale check has been run again. Please see the latest findings above or re-run the workflow for current status."
77-
78-
- name: All locales present
79-
if: steps.check.outcome == 'success'
80-
run: |
81-
echo "✅ All locales are present! No missing locales detected."
74+
gh issue comment $ISSUE_NUMBER --body "The automated locale check has been run again."

scripts/check-locales/__main__.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import os
2+
import re
3+
import subprocess
4+
import sys
5+
from pathlib import Path
6+
7+
8+
project_root = Path(__file__).parent.parent.parent
9+
locale_file = project_root / "src" / "locale.ts"
10+
ant_locale_file = project_root / "development" / "src" / "ant-phone" / "locale.ts"
11+
12+
13+
with open(locale_file, 'r') as f:
14+
content = f.read()
15+
16+
locale_pattern = r'^export const (\w+) = \{'
17+
existing_locales = set(re.findall(locale_pattern, content, re.MULTILINE))
18+
19+
with open(ant_locale_file, 'r') as f:
20+
content = f.read()
21+
22+
import_pattern = r'^import (\w+) from "antd/es/locale/'
23+
antd_locales = set(re.findall(import_pattern, content, re.MULTILINE))
24+
25+
try:
26+
result = subprocess.run(
27+
['node', '-e', 'const locale = require("@mui/material/locale"); console.log(Object.keys(locale).join(","))'],
28+
cwd=project_root / "development",
29+
capture_output=True,
30+
text=True,
31+
timeout=10
32+
)
33+
if result.returncode == 0 and result.stdout.strip():
34+
mui_locales = set(result.stdout.strip().split(','))
35+
else:
36+
mui_locales = existing_locales
37+
except:
38+
mui_locales = existing_locales
39+
40+
missing_from_antd = antd_locales - existing_locales
41+
missing_from_mui = mui_locales - existing_locales
42+
all_missing = missing_from_antd | missing_from_mui
43+
44+
if all_missing:
45+
issue_body = "## Missing Locale Translations\n\n"
46+
issue_body += "This automated check has detected missing locale files in `react-phone-hooks` that are available in dependent packages.\n\n"
47+
issue_body += "### Summary\n\n"
48+
issue_body += f"**Total missing locales: {len(all_missing)}**\n\n"
49+
50+
missing_locales = {}
51+
if missing_from_antd:
52+
missing_locales['antd'] = missing_from_antd
53+
if missing_from_mui:
54+
missing_locales['mui'] = missing_from_mui
55+
56+
for source, locales in missing_locales.items():
57+
if locales:
58+
issue_body += f"### Missing from {source}\n\n"
59+
for locale in sorted(locales):
60+
issue_body += f"- `{locale}`\n"
61+
issue_body += "\n"
62+
63+
issue_body += "### Action Required\n\n"
64+
issue_body += "Please add translation entries for the missing locales listed above. Each locale should include:\n"
65+
issue_body += "- `searchNotFound`: Translation for \"Country not found\"\n"
66+
issue_body += "- `searchPlaceholder`: Translation for \"Search country\"\n"
67+
issue_body += "- `countries`: Object mapping English country names to translations\n\n"
68+
issue_body += "### Example Structure\n\n"
69+
issue_body += "```typescript\n"
70+
issue_body += "export const enUS = {\n"
71+
issue_body += " searchNotFound: \"Country not found\",\n"
72+
issue_body += " searchPlaceholder: \"Search country\",\n"
73+
issue_body += " countries: {\n"
74+
issue_body += " \"United States\": \"United States\",\n"
75+
issue_body += " \"United Kingdom\": \"United Kingdom\",\n"
76+
issue_body += " },\n"
77+
issue_body += "}\n"
78+
issue_body += "```\n\n"
79+
issue_body += "---\n"
80+
issue_body += "*This issue was automatically generated by the locale detection script.*\n"
81+
82+
output_file = Path("/tmp/missing_locales_issue.md")
83+
with open(output_file, 'w') as f:
84+
f.write(issue_body)
85+
86+
if os.getenv('GITHUB_OUTPUT'):
87+
with open(os.getenv('GITHUB_OUTPUT'), 'a') as f:
88+
f.write(f"has_missing=true\n")
89+
f.write(f"count={len(all_missing)}\n")
90+
91+
sys.exit(1)
92+
else:
93+
if os.getenv('GITHUB_OUTPUT'):
94+
with open(os.getenv('GITHUB_OUTPUT'), 'a') as f:
95+
f.write(f"has_missing=false\n")
96+
f.write(f"count=0\n")
97+
98+
sys.exit(0)

scripts/check-missing-locales/README.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)