Open
Conversation
Adapter to support .yaml files Created by: https://github.com/klaymov
andrew000
reviewed
Apr 15, 2025
aiogram_i18n/cores/yaml_core.py
Outdated
| self._load_locales() | ||
|
|
||
| def _load_locales(self): | ||
| for filename in os.listdir(self.path): |
Contributor
There was a problem hiding this comment.
Use Path and it's methods from pathlib instead of os
aiogram_i18n/cores/yaml_core.py
Outdated
|
|
||
| def _load_locales(self): | ||
| for filename in os.listdir(self.path): | ||
| if filename.endswith('.yaml') or filename.endswith('.yml'): |
aiogram_i18n/cores/yaml_core.py
Outdated
| pass | ||
| return text | ||
|
|
||
| # full project in: https://github.com/klaymov/aiogram_i18n-yaml_core |
Contributor
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adapter to support .yaml files
Created by: https://github.com/klaymov