adcog-cpi/translation-bundle
Symfony bundle providing translation-aware link helpers for controllers and Twig. Generates tags with translated name/title/description from route keys, optional route-to-class, underscore-to-dot mapping, prefixing, and active-route tracking via configurable defaults.
translator.component), which may conflict with Laravel’s built-in translation system unless adapted (e.g., via a bridge like symfony/translation).use_route_as_class and track_selected_links features are Symfony-specific (e.g., RouterInterface), requiring custom Laravel implementations (e.g., wrapping Laravel’s URL/Route services).ContainerInterface vs. Laravel’s Container/ServiceProvider.Router vs. Laravel’s Router/UrlGenerator.Translator, UrlGenerator, and Blade directives.symfony/translation) and adapt the bundle via a facade.Translation service with Laravel’s Translator.home_index → home.index mapping).{{ path('home') }} → {{ route('home') }}).spatie/laravel-translatable, backpack/translation-manager) that solve the core problem?track_selected_links) critical, or can a subset be implemented natively?config('app.locale') vs. Symfony’s translator caching)?Translator uses __() with fallbacks; does this bundle support similar behavior?RouterInterface vs. Laravel’s UrlGenerator.{{ path('route') }} vs. @route('route')).ContainerInterface vs. Laravel’s Illuminate\Container.| Step | Action | Technical Debt | Risk |
|---|---|---|---|
| 1 | Assess Feature Parity | Low | Low |
| Map bundle features to Laravel equivalents (e.g., route-based links → Blade directives). | |||
| 2 | Dependency Isolation | Medium | Medium |
Extract core logic (translation + link generation) into a Laravel-compatible package (e.g., using illuminate/translation). |
Requires rewriting service locators. | High if Symfony dependencies are deeply coupled. | |
| 3 | Bridge Symfony Components | High | High |
Use symfony/translation and symfony/routing as drop-in replacements for Laravel’s equivalents. |
Complex container binding. | High if version conflicts arise. | |
| 4 | Blade Integration | Medium | Medium |
Create Blade directives (e.g., @translatedLink) to wrap the bundle’s logic. Example: |
Requires manual template updates. | Low if directives are well-documented. | |
| ```php | |||
| // app/Providers/BladeServiceProvider.php | |||
| Blade::directive('translatedLink', function ($expr) { |
$translation = app('eb_translation'); // Hypothetical facade
return "<?php echo \$translation->link($expr); ?>";
});
| 5 | **Testing & Validation** | High | High |
| | Write tests for: | Time-consuming. | Critical for stability. |
| - Route parameter handling. | | |
| - Fallback translations. | | |
| - Blade directive rendering. | | |
### **Compatibility**
- **Laravel Versions**:
- Tested with Laravel 8/9/10 (due to PHP 8.x requirements).
- Symfony 5.x/6.x components may conflict with Laravel’s older dependencies.
- **PHP Versions**:
- Bundle likely targets PHP 7.2+ (Symfony 4+). Laravel 8+ is compatible.
- **Translation Formats**:
- Bundle uses YAML (`messages.fr.yml`). Laravel prefers JSON/arrays (`resources/lang/fr/messages.php`).
- **Solution**: Convert YAML to Laravel’s format during deployment or use a package like [`spatie/laravel-yaml-front-matter`](https://github.com/spatie/laravel-yaml-front-matter).
### **Sequencing**
1. **Phase 1: Proof of Concept (2–4 weeks)**
- Rewrite core logic as a standalone Laravel package (e.g., `laravel-translation-links`).
- Test with a single route/translation pair.
2. **Phase 2: Feature Implementation (3–6 weeks)**
- Implement Blade directives for `link()`.
- Adapt `track_selected_links` using Laravel’s `Request` and `URL` helpers.
- Add caching for translations (Laravel’s `FileCache` or `Redis`).
3. **Phase 3: Integration (2–3 weeks)**
- Replace manual link generation in templates/controllers.
- Deprecate old patterns via middleware/deprecation notices.
4. **Phase 4: Optimization (Ongoing)**
- Benchmark performance (e.g., route lookup time).
- Add support for dynamic locales (e.g., `app()->setLocale()`).
---
## Operational Impact
### **Maintenance**
- **Short-Term**:
- **High effort** to maintain a forked/rewritten version. Requires:
- Syncing with upstream (if any) for bug fixes.
- Updating for Laravel/Symfony version changes.
- **Documentation gap**: No README/examples for Laravel. Would need:
- Installation guide (Composer, service provider setup).
- Blade directive usage examples.
- **Long-Term**:
- **Lower effort** if bundled as a standalone Laravel package (e.g., published to Packagist).
- **Dependency risks**:
- Symfony packages may introduce bloat or conflicts.
- Abandoned upstream could lead to technical debt.
### **Support**
- **Community**:
- **None**: 0 stars/issues suggest low adoption. Support would rely on:
- Internal team expertise.
- Laravel/Symfony community cross-pollination (e.g., Stack Overflow).
- **Debugging**:
- **Complex stack traces**: Mixing Symfony/Laravel services may obscure errors.
- **Example issues**:
- `RouteNotFoundException` in Symfony’s router vs. Laravel’s `UrlGenerator`.
- Twig syntax errors in Blade templates.
- **Tools**:
- Use Laravel’s
How can I help you explore Laravel packages today?