Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Locale Detection Automation - Complete ✅

Successfully implemented automation to detect missing locale files in react-phone-hooks by comparing against locales available in dependent packages (antd and MUI).

Files Added

  1. scripts/check-locales/__main__.py

    • Python script that detects missing locales
    • Fetches antd locales directly from upstream GitHub repository: https://github.com/ant-design/ant-design/tree/master/components/locale
    • Fetches MUI locales directly from upstream GitHub repository: https://github.com/mui/material-ui/tree/master/packages/mui-material/src/locale
    • Filters out non-locale files (like context.ts, useLocale.ts) using regex pattern
    • Compares to identify missing locales
    • Generates concise GitHub issue body listing missing locales with their source packages
    • Clean implementation without comments, docstrings, or verbose output
    • Uses curl subprocess to fetch directory listings from GitHub API
  2. .github/workflows/locales.yml

    • Runs on push and pull requests to master branch (same triggers as tests.yml)
    • Creates/updates issues with missing-locales, translation, enhancement labels
    • Prevents duplicate issues by checking existing open issues
    • Permissions scoped to contents: read, issues: write
    • Follows the same coding style as update.yml workflow
    • Simplified workflow requiring only Python (no Node.js or npm dependencies needed)
    • Fixed syntax error by passing issue body via environment variable instead of template literal

Testing & Validation

✅ Script execution: Compiles successfully
✅ Python syntax: No errors
✅ Locale filtering: Only validates proper locale codes (e.g., enUS, zhCN, kuLatn)
✅ Non-locale filtering: Excludes utility files like context, useLocale
✅ Workflow syntax: Fixed backtick escaping issue in GitHub Actions script
✅ Action versions: Consistent with existing workflows
✅ Permissions: Properly scoped for security

Implementation Details

Locale name pattern: ^[a-z]{2,3}[A-Z][A-Za-z]{1,3}$

  • Matches: enUS, zhCN, arEG, kuLatn, beBY, psAF, mrIN
  • Excludes: context, useLocale, index

Antd locales: Fetched from GitHub API, file names like en_US.ts converted to enUS
MUI locales: Fetched from GitHub API, file names like enUS.ts used directly
Network: Uses curl subprocess to fetch from GitHub API with proper User-Agent headers

This implementation follows the same pattern as existing workflows and fetches data directly from upstream sources.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add automation to detect missing locales and generate translation issues</issue_title>
<issue_description>The react-phone-hooks relies on manually maintained locale files, and new languages added to antd-phone-input or mui-phone-input can be missing (e.g., enUS). So, create a script that:

  1. Checks all language keys used by dependent packages.
  2. Compares them against existing locale files in react-phone-hooks.
  3. Automatically opens a GitHub issue, mentioning all missing locales, requesting translation entries.

This should work similarly to the existing script that keeps phone validation patterns up-to-date.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits December 10, 2025 14:04
Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automation to detect missing locales and generate issues Add automation to detect missing locale translations from dependent packages Dec 10, 2025
Copilot AI requested a review from ArtyomVancyan December 10, 2025 14:16
@ArtyomVancyan
Copy link
Member

@copilot - Rename the check-missing-locales.yml to locales.yml and use the same coding style as the .github/workflows/update.yml does.

  • Move scripts/check-missing-locales/__main__.py to scripts/check-locales/__main__.py
  • Remove all comments, docstrings, emojis, and prints from the added code.
  • The mui_locales shouldn't be a static list - that is the idea of the script to fetch the upstream list of supported languages to compare.
  • Remove the newly created README.

…omments/prints, make MUI dynamic

Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot - Rename the check-missing-locales.yml to locales.yml and use the same coding style as the .github/workflows/update.yml does.

  • Move scripts/check-missing-locales/__main__.py to `scri...

Done in commit 56b4971. Changes made:

  • Renamed check-missing-locales.yml to locales.yml matching update.yml style
  • Moved scripts/check-missing-locales/ to scripts/check-locales/
  • Removed all comments, docstrings, emojis, and prints
  • Made mui_locales dynamic - now fetched from @mui/material/locale using Node.js subprocess
  • Removed the README file

@ArtyomVancyan
Copy link
Member

@copilot A few more adjustments:

  • Run the new workflow with the same triggers as the tests.yml - without a cron schedule.
  • Use a short report in the following format:
Update the translations, adding the following language keys:

 - `enUS` (`antd`, `mui`)
 - `kuIQ` (`antd`)

…rmat

Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot A few more adjustments:

  • Run the new workflow with the same triggers as the tests.yml - without a cron schedule.
  • Use a short report in the following format:...

Done in commit 0ab272f. Changes made:

  • Changed workflow triggers to match tests.yml (push/pull_request on master, removed cron schedule)
  • Updated report format to the requested short format showing locale keys with their source packages

@ArtyomVancyan
Copy link
Member

@copilot You shouldn't rely on https://github.com/typesnippet/react-phone-hooks/blob/master/development/src/ant-phone/locale.ts, instead, you should fetch the list from https://github.com/ant-design/ant-design/tree/master/components/locale (file names from this directory). In the same way, you should fetch the list of MUI-supported languages from https://github.com/mui/material-ui/tree/master/packages/mui-material/src/locale directory.

Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot You shouldn't rely on https://github.com/typesnippet/react-phone-hooks/blob/master/development/src/ant-phone/locale.ts, instead, you should fetch the list from `https://github.com/ant-desig...

Done in commit 2c740ea. Changes made:

  • Now fetches antd locales from https://github.com/ant-design/ant-design/tree/master/components/locale
  • Now fetches MUI locales from https://github.com/mui/material-ui/tree/master/packages/mui-material/src/locale
  • Removed dependency on local development files
  • Simplified workflow by removing Node.js setup and npm install steps

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/ant-design/ant-design/contents/components/locale
    • Triggering command: /usr/bin/python python scripts/check-locales/__main__.py (http block)
    • Triggering command: `/usr/bin/python python -c
      import json
      from urllib.request import urlopen

Test antd

with urlopen('REDACTED') as response:
files = json.loads(response.read())
antd_locales = []
for file in files:
if fil` (http block)

  • Triggering command: `/usr/bin/python python -c
    import json
    from urllib.request import Request, urlopen

Test antd

req = Request('REDACTED')
req.add_header('User-Agent', 'react-phone-hooks-locale-checker')
with urlopen(req) as resp` (http block)

  • https://api.github.com/repos/mui/material-ui/contents/packages/mui-material/src/locale
    • Triggering command: /usr/bin/python python scripts/check-locales/__main__.py (http block)
    • Triggering command: /usr/bin/curl curl -s -H User-Agent: react-phone-hooks REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@ArtyomVancyan
Copy link
Member

@copilot Workflow fails with the following error message:

Run actions/github-script@v7
  with:
    github-token: ***
    script: const issueBody = `Update the translations, adding the following language keys:
  
   - `beBY` (`mui`)
   - `context` (`antd`)
   - `enUS` (`antd`, `mui`)
   - `kuIQ` (`antd`)
   - `kuLatn` (`mui`)
   - `mrIN` (`antd`)
   - `psAF` (`mui`)
   - `useLocale` (`antd`)`;
  await github.rest.issues.create({
    owner: context.repo.owner,
    repo: context.repo.repo,
    title: 'Missing locale translations detected',
    body: issueBody,
    labels: ['missing-locales', 'translation', 'enhancement']
  });
  
    debug: false
    user-agent: actions/github-script
    result-encoding: json
    retries: 0
    retry-exempt-status-codes: 400,401,403,404,422
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.14.0/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.14.0/x64/lib
SyntaxError: Unexpected identifier 'beBY'
    at new AsyncFunction (<anonymous>)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:36187:16)
    at main (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:36285:26)
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:36260:1
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:36317:3
    at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:36320:12)
    at Module._compile (node:internal/modules/cjs/loader:1521:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)
    at Module.load (node:internal/modules/cjs/loader:1266:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
Error: Unhandled error: SyntaxError: Unexpected identifier 'beBY'
  • Add a filter that ignores non-language keys such as context and useLocale.
  • Rename the flow from "Update Locales" to "locales".

Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot Workflow fails with the following error message:

Run actions/github-script@v7...

Done in commit e63a075. Changes made:

  • Fixed workflow syntax error by passing issue body via environment variable instead of template literal (prevents backticks from breaking JavaScript)
  • Added regex filter ^[a-z]{2,3}[A-Z][A-Za-z]{1,3}$ to exclude non-locale files like context and useLocale
  • Renamed workflow from "Update Locales" to "locales"

@ArtyomVancyan ArtyomVancyan marked this pull request as ready for review December 10, 2025 16:31
@ArtyomVancyan ArtyomVancyan merged commit 7bf29b8 into master Dec 10, 2025
10 checks passed
@ArtyomVancyan ArtyomVancyan deleted the copilot/add-locale-detection-script branch December 10, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add automation to detect missing locales and generate translation issues

2 participants