|
| 1 | +import json |
1 | 2 | import os |
2 | 3 | import re |
3 | 4 | import subprocess |
|
7 | 8 |
|
8 | 9 | project_root = Path(__file__).parent.parent.parent |
9 | 10 | locale_file = project_root / "src" / "locale.ts" |
10 | | -ant_locale_file = project_root / "development" / "src" / "ant-phone" / "locale.ts" |
11 | | - |
12 | 11 |
|
13 | 12 | with open(locale_file, 'r') as f: |
14 | 13 | content = f.read() |
15 | 14 |
|
16 | 15 | locale_pattern = r'^export const (\w+) = \{' |
17 | 16 | existing_locales = set(re.findall(locale_pattern, content, re.MULTILINE)) |
18 | 17 |
|
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)) |
| 18 | +try: |
| 19 | + result = subprocess.run( |
| 20 | + ['curl', '-s', '-H', 'User-Agent: react-phone-hooks', |
| 21 | + 'https://api.github.com/repos/ant-design/ant-design/contents/components/locale'], |
| 22 | + capture_output=True, |
| 23 | + text=True, |
| 24 | + timeout=30 |
| 25 | + ) |
| 26 | + if result.returncode == 0 and result.stdout.strip(): |
| 27 | + files = json.loads(result.stdout) |
| 28 | + antd_locales = set() |
| 29 | + for file in files: |
| 30 | + if file['name'].endswith('.ts') and file['name'] != 'index.ts': |
| 31 | + locale_name = file['name'].replace('.ts', '').replace('_', '') |
| 32 | + antd_locales.add(locale_name) |
| 33 | + else: |
| 34 | + antd_locales = set() |
| 35 | +except: |
| 36 | + antd_locales = set() |
24 | 37 |
|
25 | 38 | try: |
26 | 39 | result = subprocess.run( |
27 | | - ['node', '-e', 'const locale = require("@mui/material/locale"); console.log(Object.keys(locale).join(","))'], |
28 | | - cwd=project_root / "development", |
| 40 | + ['curl', '-s', '-H', 'User-Agent: react-phone-hooks', |
| 41 | + 'https://api.github.com/repos/mui/material-ui/contents/packages/mui-material/src/locale'], |
29 | 42 | capture_output=True, |
30 | 43 | text=True, |
31 | | - timeout=10 |
| 44 | + timeout=30 |
32 | 45 | ) |
33 | 46 | if result.returncode == 0 and result.stdout.strip(): |
34 | | - mui_locales = set(result.stdout.strip().split(',')) |
| 47 | + files = json.loads(result.stdout) |
| 48 | + mui_locales = set() |
| 49 | + for file in files: |
| 50 | + if file['name'].endswith('.ts') and file['name'] != 'index.ts': |
| 51 | + locale_name = file['name'].replace('.ts', '') |
| 52 | + mui_locales.add(locale_name) |
35 | 53 | else: |
36 | | - mui_locales = existing_locales |
| 54 | + mui_locales = set() |
37 | 55 | except: |
38 | | - mui_locales = existing_locales |
| 56 | + mui_locales = set() |
39 | 57 |
|
40 | 58 | missing_from_antd = antd_locales - existing_locales |
41 | 59 | missing_from_mui = mui_locales - existing_locales |
|
0 commit comments