-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Locale Validator | ||
|
||
on: | ||
push: | ||
branches: [ staging, trying ] | ||
pull_request: | ||
paths: | ||
- '**/*.yml' | ||
|
||
jobs: | ||
validate_ymls: | ||
name: Validate Locales | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3.6.0 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
pip install --no-cache-dir PyYAML | ||
- name: Validate Locales | ||
run: | | ||
python3 Tools/_Sunrise/Schemas/validate_yml.py Resources/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import os | ||
import re | ||
import yaml | ||
from glob import iglob | ||
from typing import Any, List | ||
|
||
errors: List["LocaleError"] = [] | ||
|
||
def main() -> int: | ||
parser = argparse.ArgumentParser("validate_yml.py", description="Validates YML files for Russian characters in specific fields.") | ||
parser.add_argument("directories", nargs="+", help="Directories to look for YML files in") | ||
|
||
args = parser.parse_args() | ||
|
||
for dir in args.directories: | ||
check_dir(dir) | ||
|
||
for error in errors: | ||
print(f"{error.path}: {error.message}") | ||
|
||
return 1 if errors else 0 | ||
|
||
def check_dir(dir: str): | ||
for yml_rel in iglob("**/*.yml", root_dir=dir, recursive=True): | ||
yml_path = os.path.join(dir, yml_rel) | ||
check_yml(yml_path) | ||
|
||
def check_yml(yml_path: str): | ||
try: | ||
with open(yml_path, "r", encoding="utf-8") as file: | ||
data = yaml.safe_load(file) | ||
|
||
# Проверка нужных полей на русские символы | ||
for key in ['name', 'description', 'suffix']: | ||
if key in data and has_russian_chars(data[key]): | ||
add_error(yml_path, f"Поле '{key}' содержит русские символы.") | ||
|
||
except Exception as e: | ||
add_error(yml_path, f"Ошибка чтения файла: {e}") | ||
|
||
def has_russian_chars(text: str) -> bool: | ||
"""Проверяет, содержит ли текст русские символы.""" | ||
return bool(re.search(r'[а-яА-Я]', text)) | ||
|
||
def add_error(yml: str, message: str): | ||
errors.append(LocaleError(yml, message)) | ||
|
||
class LocaleError: | ||
def __init__(self, path: str, message: str): | ||
self.path = path | ||
self.message = message | ||
|
||
exit(main()) |