Валидатор локализации (#491)

* init

* fix capitulation

* fix path

* fix tags

* upd

* пустой коммит

* fix !type:
This commit is contained in:
Rinary 2024-10-11 19:38:18 +03:00 committed by GitHub
parent 73d44d4657
commit 75ea945a2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -23,3 +23,4 @@ jobs:
- name: Validate Locales
run: |
python3 Tools/_sunrise/Schemas/validate_yml.py Resources/

View file

@ -31,16 +31,29 @@ def check_dir(dir: str):
def check_yml(yml_path: str):
try:
with open(yml_path, "r", encoding="utf-8") as file:
data = yaml.load(file, Loader=yaml.Loader)
content = file.read()
# Удаляем строки с тегами !type:
filtered_content = remove_type_tags(content)
# Загружаем оставшийся текст в формате YAML
data = yaml.safe_load(filtered_content)
# Проверка нужных полей на русские символы
for key in ['name', 'description', 'suffix']:
if key in data and has_russian_chars(data[key]):
add_error(yml_path, f"Поле '{key}' содержит русские символы.")
except yaml.YAMLError as e:
add_error(yml_path, f"Ошибка чтения файла YAML: {e}")
except Exception as e:
add_error(yml_path, f"Ошибка чтения файла: {e}")
def remove_type_tags(content: str) -> str:
"""Удаляет строки с тегами !type:."""
lines = content.splitlines()
filtered_lines = [line for line in lines if '!type:' not in line]
return '\n'.join(filtered_lines)
def has_russian_chars(text: str) -> bool:
"""Проверяет, содержит ли текст русские символы."""
return bool(re.search(r'[а-яА-Я]', text))