-
Notifications
You must be signed in to change notification settings - Fork 6
refactor translation key generation in Jinja2Core #42
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
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 refactors the translation key generation in the Jinja2Core module to support a nested template structure by generating keys based on the relative file paths.
- Introduces a new parameter for a key separator.
- Constructs keys by joining parts of the file path relative to the locale folder.
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 refactors how translation keys are generated in Jinja2Core to support nested template structures.
- Introduces a key_separator parameter (defaulting to "-") in the initializer
- Replaces the use of file_path.stem with a joined key based on the relative file path parts
- Updates key generation in translations to support nested directories
Comments suppressed due to low confidence (2)
aiogram_i18n/cores/jinja2_core.py:25
- The default key_separator '-' may result in keys like 'main-buttons-settings' which do not directly match the dot notation (e.g., i18n.main.buttons.settings()) suggested in the PR description. Consider using '.' as the default delimiter if attribute-style access is intended.
key_separator: str = "-",
aiogram_i18n/cores/jinja2_core.py:56
- Consider adding tests for nested file paths to ensure that the new key generation works correctly in various directory structures.
relative_file_path = file_path.relative_to(self.path / locale)
I'll check it soon |
Keys are now generated based on the relative file path, not just the stem file.
This allows you to support a nested template structure, e.g:
They can be accessed like this: