refactor translation key generation in Jinja2Core#42
Open
loRes228 wants to merge 5 commits intoaiogram:devfrom
Open
refactor translation key generation in Jinja2Core#42loRes228 wants to merge 5 commits intoaiogram:devfrom
loRes228 wants to merge 5 commits intoaiogram:devfrom
Conversation
Contributor
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
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)
Author
Contributor
|
I'll check it soon |
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.
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: