-
Notifications
You must be signed in to change notification settings - Fork 6
Added core to support .yaml files #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Adapter to support .yaml files Created by: https://github.com/klaymov
aiogram_i18n/cores/yaml_core.py
Outdated
self._load_locales() | ||
|
||
def _load_locales(self): | ||
for filename in os.listdir(self.path): |
There was a problem hiding this comment.
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
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'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Path(...).suffix
aiogram_i18n/cores/yaml_core.py
Outdated
pass | ||
return text | ||
|
||
# full project in: https://github.com/klaymov/aiogram_i18n-yaml_core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove it
There was a problem hiding this 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(): |
There was a problem hiding this comment.
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.
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.
Adapter to support .yaml files
Created by: https://github.com/klaymov