Правки в валидаторе локализаций (#494)

* upd

* upd

* fix path

* NO YAML PARSER ZAEBALA SHLUHA

* План, как видеть все пр-ы где изменяют локализацию

* new labeler

* no more ru symbols in ghost role component

* upd
This commit is contained in:
Rinary 2024-10-12 17:39:13 +03:00 • committed by GitHub
parent fc05b743ba
commit f6c53358f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 29 deletions

1
.github/CODEOWNERS vendored
View file

@ -66,3 +66,4 @@
# Ping for all PRs
* @VigersRay
/Resources/Locale/ @Rinary1

4
.github/labeler.yml vendored
View file

@ -16,6 +16,10 @@
- changed-files:
- any-glob-to-any-file: '**/*.swsl'
"Изменения: Локализация":
- changed-files:
- any-glob-to-any-file: '**/*.ftl'
"Нет C#":
- changed-files:
# Equiv to any-glob-to-all as long as this has one matcher. If ALL changed files are not C# files, then apply label.

View file

@ -4,8 +4,7 @@ on:
push:
branches: [ staging, trying ]
pull_request:
paths:
- '**/*.yml'
types: [ opened, reopened, synchronize, ready_for_review ]
jobs:
validate_ymls:
@ -22,5 +21,4 @@ jobs:
pip install --no-cache-dir PyYAML
- name: Validate Locales
run: |
python3 Tools/_sunrise/Schemas/validate_yml.py Resources/
python3 Tools/_sunrise/Schemas/validate_yml.py Resources/Prototypes/

View file

@ -3,9 +3,8 @@
import argparse
import os
import re
import yaml
from glob import iglob
from typing import Any, List
from typing import List
errors: List["LocaleError"] = []
@ -19,7 +18,7 @@ def main() -> int:
check_dir(dir)
for error in errors:
print(f"{error.path}: {error.message}")
print(f"{error.path} (строка {error.line}): {error.message}")
return 1 if errors else 0
@ -31,39 +30,34 @@ def check_dir(dir: str):
def check_yml(yml_path: str):
try:
with open(yml_path, "r", encoding="utf-8") as file:
content = file.read()
# Удаляем строки с тегами !type:
filtered_content = remove_type_tags(content)
content = file.readlines()
# Загружаем оставшийся текст в формате YAML
data = yaml.safe_load(filtered_content)
# Оставляем только строки с ключами 'name:', 'description:', 'suffix:', 'rules:'
filter_and_check(content, yml_path)
# Проверка нужных полей на русские символы
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}")
add_error(yml_path, -1, 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 filter_and_check(content: List[str], yml_path: str):
key_pattern = re.compile(r'^(name|description|suffix|rules):\s*(.+)')
for i, line in enumerate(content, start=1):
match = key_pattern.match(line.strip())
if match:
key, value = match.groups()
if has_russian_chars(value):
add_error(yml_path, i, f"Поле '{key}' содержит русские символы.")
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))
def add_error(yml: str, line: int, message: str):
errors.append(LocaleError(yml, line, message))
class LocaleError:
def __init__(self, path: str, message: str):
def __init__(self, path: str, line: int, message: str):
self.path = path
self.line = line
self.message = message
exit(main())