Skip to content

feat: enhance recursive translations with shortcuts and dot notation #110

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

nicebots-xyz-bot
Copy link
Collaborator

Implements issue #67 with enhanced folder structure support:

  • Shortcuts: c. → commands., t. → translations., s. → strings.
  • Dot notation: Folder names with dots create nested key structures
  • Documentation: Updated readme.md with comprehensive examples
  • Cleanup: Removed separate RECURSIVE_TRANSLATIONS.md file

Maintains full backward compatibility with existing translation files.

Fixes #67

- Add load_translation_folder() function to support translations/ folder structure
- Modify extension loading to check for both translations.yml and translations/ folder
- Maintain backward compatibility with existing translations.yml files
- Support recursive folder structure with dot-notation keys for strings
- Add comprehensive documentation for the new feature

Features:
- Recursive processing of .yml/.yaml files in translations/ folder
- Automatic separation of commands and strings based on folder structure
- Dot-notation keys for nested string organization (e.g., strings.general.welcome)
- Priority given to translations.yml for backward compatibility
- Support for both .yml and .yaml file extensions

This allows extensions to organize translations in a more structured way:
translations/
├── commands/
│   ├── command1.yaml
│   └── command2.yaml
└── strings/
    └── messages.yaml
- Add folder name shortcuts: c. → commands., t. → translations., s. → strings.
- Support dots in folder names for nested key structures
- Update readme.md with comprehensive folder structure documentation
- Remove separate RECURSIVE_TRANSLATIONS.md file as requested
- Fix command structure loading for folder-based translations
- Maintain backward compatibility with existing translation files

Resolves #67
@Paillat-dev Paillat-dev requested a review from Copilot May 25, 2025 15:08
Copy link

@Copilot 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 implements enhanced translation loading by introducing support for both a single file and a folder structure with shortcut expansion and dot notation for nested translation keys. Key changes include:

  • Updating src/start.py to check and load translations from either a file or folder
  • Adding helper functions (_expand_folder_name, _load_recursive_translations, load_translation_folder) in src/i18n/utils.py to process folder-based translations
  • Updating module exports in src/i18n/init.py and enhancing documentation in readme.md

Reviewed Changes

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

File Description
src/start.py Added logic to check for both translations files and folders with detailed logging
src/i18n/utils.py Introduced helper functions to expand folder names and recursively load translations
src/i18n/init.py Updated exports to include the new load_translation_folder function
readme.md Updated documentation with usage examples for the new folder structure format

break

# Convert dots to path separators for nested structure
return folder_name.replace('.', '.')
Copy link
Preview

Copilot AI May 25, 2025

Choose a reason for hiding this comment

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

The _expand_folder_name function's replacement operation currently has no effect, as it replaces '.' with '.'. If the intent is to convert dots to a different separator for nested keys, please update the replacement accordingly (e.g., using a different character or string).

Suggested change
return folder_name.replace('.', '.')
return folder_name.replace('.', '/')

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.

Allow recursive translations folder
2 participants