cyberspectrum/i18n-xliff
PHP library for working with XLIFF translation files in i18n workflows. Provides parsing and handling utilities to read, write, and manipulate XLIFF data for localization pipelines, helping integrate translators’ files into apps and build processes.
Monolithic vs. Microservices Fit:
Translation Workflow Integration:
trans() helper but adds structured export/import for external tools (e.g., Crowdin, Lokalise, POEditor).lang/ directory structure), requiring manual conversion.Database vs. File-Based Storage:
translation table).resources/lang/ or a database-backed system.Laravel Ecosystem Compatibility:
app/Http/Middleware/Localize).FileLoader or DatabaseLoader extensions).translated event listeners).spatie/laravel-translatable, laravel-localization).XLIFF Parsing Overhead:
trans() for high-traffic apps.memory_limit if needed).Localization Features:
| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| XLIFF Format Rigidity | High | Abstract behind a wrapper to support JSON/YAML fallback. |
| Database Sync | Medium | Build a custom loader to bridge XLIFF ↔ DB. |
| Package Maturity | High | Low stars/activity → expect bugs; fork or wrap in a Laravel-specific layer. |
| Performance | Medium | Cache parsed XLIFF files; avoid parsing on every request. |
| Dependency Conflicts | Low | Use composer require with --ignore-platform-reqs if needed. |
lang/ directory)?Primary Use Case:
resources/lang/ (JSON/YAML) to XLIFF for translators.lang/ files from XLIFF).Recommended Stack Additions:
spatie/array-to-xml (for JSON→XLIFF conversion).laravel-localization (for route/localization management).git push to main.Alternatives Considered:
laravel-translation-manager: More Laravel-native but lacks XLIFF support.Phase 1: Proof of Concept (PoC)
en) from lang/ to XLIFF.composer require cyberspectrum/i18n-xliff.Phase 2: Integration with Workflow
php artisan export:xliff) to generate XLIFF for all languages.lang/.trans() via a custom loader (see below).Phase 3: Full Adoption
lang/ edits in favor of XLIFF → CI/CD pipeline.Laravel Version:
xml and dom extensions (enabled by default).Custom Loader Implementation:
// app/Providers/AppServiceProvider.php
use Cyberspectrum\I18nXliff\Loader;
use Illuminate\Support\Facades\Blade;
public function boot()
{
// Override Laravel's default loader with XLIFF fallback
$loader = new Loader();
$loader->addPath(base_path('resources/lang'));
$loader->addPath(base_path('xliff')); // Custom XLIFF directory
app()->set('path.lang', $loader);
}
XLIFF Structure Example:
<!-- resources/xliff/en.xlf -->
<xliff version="1.2">
<file source-language="en" target-language="es">
<body>
<trans-unit id="welcome">
<source>Welcome</source>
<target>Bienvenido</target>
</trans-unit>
</body>
</file>
</xliff>
| Step | Task | Owner | Dependencies |
|---|---|---|---|
| 1 | Install package + basic tests | Backend | Laravel 8+ |
| 2 | Build JSON→XLIFF converter | Dev | spatie/array-to-xml |
| 3 | Create export:xliff Artisan command |
Dev | Step 2 |
| 4 | Implement XLIFF→Laravel loader | Dev | Step 3 |
| 5 | Set up CI/CD pipeline | DevOps | GitHub Actions/GitLab CI |
| 6 | Train team on workflow | PM | Documentation |
| 7 | Deprecate manual lang/ edits |
PM/Dev | Step 6 |
composer update).How can I help you explore Laravel packages today?