cursedcoder/dark-translation-bundle
Installation:
composer require cursedcoder/dark-translation-bundle
Register the bundle in AppKernel.php and include its routes in routing.yml.
Configuration:
Add your GitHub fork URL for the target language and local paths for source/docs in config.yml:
dark_translation:
repositories:
ru: 'https://github.com/your-fork/symfony-docs-ru'
source:
base_dir: '%kernel.root_dir%/../docs'
from: '%kernel.root_dir%/../docs/symfony-docs'
to: '%kernel.root_dir%/../docs/translated'
First Use Case: Fetch the latest Symfony docs for translation:
php app/console dark:translation:fetch
Access the translation interface at /dark/translation to start editing.
Fetching Docs:
Use the dark:translation:fetch command to pull the latest Symfony docs into your local from directory.
php app/console dark:translation:fetch --lang=ru
Editing Interface:
Navigate to /dark/translation to use the double-editor with synchronized scrolling. The left panel shows the source (English), and the right panel shows the target language (e.g., Russian).
Saving Translations:
After editing, save changes to the to directory. The bundle tracks changes and allows you to push translations to your fork later.
Pushing Translations: Commit and push translations to your GitHub fork:
php app/console dark:translation:push --lang=ru
DarkTranslationBundle::Resources/views.dark:translation:generate command to create missing translation files in the to directory.# .github/workflows/translate.yml
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: composer install
- run: php bin/console dark:translation:fetch --lang=ru
- run: php bin/console dark:translation:push --lang=ru
File Tracking:
The bundle tracks changes via filenames. Ensure your from and to directories mirror each other exactly (same subfolder structure). Mismatches may cause files to be ignored during pushes.
dark:translation:sync to align directory structures.GitHub Fork Permissions:
The dark:translation:push command requires write access to your fork. Test with a personal access token if using SSH:
git config --global url."git@github.com:".insteadOf "https://github.com/"
Twig Template Overrides:
Overriding templates requires careful naming. Use the bundle’s namespace in your app/Resources/DarkTranslationBundle/views/ directory to avoid conflicts.
dark_translation config for typos in repositories or source paths. Use --verbose flag for commands:
php app/console dark:translation:fetch --lang=ru --verbose
from directory contains the original docs. Re-fetch with:
php app/console dark:translation:fetch --force
Custom Commands:
Extend the bundle by creating your own commands (e.g., dark:translation:validate to check translation completeness). Use the existing command classes as a reference:
// src/Dark/TranslationBundle/Command/ValidateCommand.php
class ValidateCommand extends ContainerAwareCommand {
protected function execute(InputInterface $input, OutputInterface $output) {
// Custom logic here
}
}
Hooks for Pre/Post-Translation:
Override the DarkTranslationEvents to add logic before/after fetching/pushing. Example:
// src/Acme/TranslationListener.php
class TranslationListener {
public function onTranslationFetch(DarkTranslationEvents $event) {
// Pre-fetch logic
}
}
Register the listener in services.yml:
services:
acme.translation_listener:
class: Acme\TranslationListener
tags:
- { name: kernel.event_listener, event: dark.translation.fetch, method: onTranslationFetch }
Localization Rules:
Add custom rules for specific file types (e.g., .md vs .rst). Extend the TranslationManager service:
// config/services.yml
dark_translation.manager.class: Acme\CustomTranslationManager
dark_translation.manager.arguments:
- '@service_container'
- ['.md' => 'markdown_rules', '.rst' => 'rest_rules']
How can I help you explore Laravel packages today?