elasticms/xliff package provides a focused, reusable solution for XLIFF (XML Localization Interchange File Format) handling, aligning well with Laravel’s modular architecture. It can be integrated as a standalone service or embedded within a larger localization system (e.g., a Laravel-based CMS or translation management workflow).Post, Product) into XLIFF files for external translators. Supports both plain text and segmented HTML.DOMDocument or SimpleXML). No conflicts with Laravel’s core or popular packages (e.g., spatie/laravel-translatable).<group>, <note> elements). Validate that the package handles these or plan to extend it.memory_get_usage() and optimize via streaming (e.g., XMLWriter).spatie/array-to-xml for simple cases).elasticms ecosystem. Future updates may introduce breaking changes.elasticms repo for deprecations.model_translations) or merged into existing models (e.g., JSON column)?<script>, <style>) that require custom handling?{variable} placeholders) be managed?$this->app->singleton('xliff', function ($app) {
return new \Ems\Xliff\XliffGenerator();
});
Xliff::export(Model::class)) for Blade templates or controllers. Example:
use Facades\Xliff;
// Export a model to XLIFF
$xliff = Xliff::export(Post::find(1), 'en', 'fr');
Storage::put('public/translations/post_1.xlf', $xliff);
php artisan xliff:export posts --locale=fr
php artisan xliff:import translations/post_1_fr.xlf
Schema::create('translations', function (Blueprint $table) {
$table->id();
$table->string('model_type'); // e.g., 'App\Models\Post'
$table->unsignedBigInteger('model_id');
$table->string('locale');
$table->text('key'); // e.g., 'title', 'content'
$table->text('value');
$table->boolean('is_html')->default(false);
$table->timestamps();
});
Observers or Model Events to trigger XLIFF exports on content updates:
class PostObserver {
public function saved(Post $post) {
if ($post->isDirty('title') || $post->isDirty('content')) {
Xliff::export($post, config('app.default_locale'), 'fr');
}
}
}
@translate directives:
@translate('post.title', $post->id, 'fr')
Route::get('/api/translations/{locale}', [TranslationController::class, 'index']);
Phase 1: Proof of Concept (2 weeks)
Post).XliffService to wrap the package’s API.Phase 2: Core Workflow (3 weeks)
TranslationService to handle locale switching and fallback logic.Phase 3: Scaling (4 weeks)
xliff:export/xliff:import) for large datasets.SimpleXML or XMLReader for memory efficiency.How can I help you explore Laravel packages today?