From f6c53358f895391cc3e09266bfb5f3cbd97bda60 Mon Sep 17 00:00:00 2001 From: Rinary <72972221+Rinary1@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:39:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2?= =?UTF-8?q?=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=82=D0=BE=D1=80=D0=B5?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20(#494)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * upd * upd * fix path * NO YAML PARSER ZAEBALA SHLUHA * План, как видеть все пр-ы где изменяют локализацию * new labeler * no more ru symbols in ghost role component * upd --- .github/CODEOWNERS | 1 + .github/labeler.yml | 4 +++ .github/workflows/validate-locale.yml | 6 ++-- Tools/_sunrise/Schemas/validate_yml.py | 44 +++++++++++--------------- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c5c402ea4e..a1ea9a110e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -66,3 +66,4 @@ # Ping for all PRs * @VigersRay +/Resources/Locale/ @Rinary1 diff --git a/.github/labeler.yml b/.github/labeler.yml index 94ae2c1c53..55027c6cad 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -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. diff --git a/.github/workflows/validate-locale.yml b/.github/workflows/validate-locale.yml index d33f224bc3..34ee6fb98c 100644 --- a/.github/workflows/validate-locale.yml +++ b/.github/workflows/validate-locale.yml @@ -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/ \ No newline at end of file diff --git a/Tools/_sunrise/Schemas/validate_yml.py b/Tools/_sunrise/Schemas/validate_yml.py index dfe0353541..1553e67d68 100644 --- a/Tools/_sunrise/Schemas/validate_yml.py +++ b/Tools/_sunrise/Schemas/validate_yml.py @@ -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())