Skip to content

Conversation

@klaymov
Copy link

@klaymov klaymov commented Apr 15, 2025

Adapter to support .yaml files

Created by: https://github.com/klaymov

Adapter to support .yaml files

Created by: https://github.com/klaymov
self._load_locales()

def _load_locales(self):
for filename in os.listdir(self.path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Path and it's methods from pathlib instead of os


def _load_locales(self):
for filename in os.listdir(self.path):
if filename.endswith('.yaml') or filename.endswith('.yml'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Path(...).suffix

pass
return text

# full project in: https://github.com/klaymov/aiogram_i18n-yaml_core
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove it

@JrooTJunior JrooTJunior requested a review from Copilot April 19, 2025 12:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for .yaml files by introducing a new translation core and updating corresponding tests and dependency configurations.

  • Added a new YAML core adapter in aiogram_i18n/cores/yaml_core.py.
  • Updated tests to include a yaml_core fixture and included PyYAML as a dependency.
  • Updated module initialization in init.py to export the new YamlCore.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/test_cores.py Added fixture for yaml_core to verify YAML translations support.
pyproject.toml Added PyYAML dependency under the yml dependency group.
aiogram_i18n/cores/yaml_core.py New implementation of YamlCore for loading YAML translations.
aiogram_i18n/cores/init.py Exported YamlCore to integrate with the core framework.

translations: Dict[str, Dict[str, Any]] = {}
locales = self._extract_locales(self.path)
for file_ext in (".yaml", ".yml"):
for locale, paths in self._find_locales(self.path, locales, file_ext).items():
Copy link

Copilot AI Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing file_ext as a string instead of a tuple may lead to incorrect behavior in _find_locales. Consider wrapping file_ext in a tuple, e.g. (file_ext,), to match the expected parameter type.

Suggested change
for locale, paths in self._find_locales(self.path, locales, file_ext).items():
for locale, paths in self._find_locales(self.path, locales, (file_ext,)).items():

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants