Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinary1 committed Oct 11, 2024
1 parent d3094b7 commit 86c19b1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/validate-locale.yml
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/
56 changes: 56 additions & 0 deletions Tools/_sunrise/Schemas/validate_yml.py
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())

0 comments on commit 86c19b1

Please sign in to comment.