weglot/translation-definitions
Laravel package providing translation definitions for Weglot integrations—helpers and configuration to manage translation keys, mapping, and defaults in a consistent way across your app. Useful for standardizing multilingual content handling with Weglot.
trans()). However, it may conflict with existing translation layers (e.g., resources/lang) if not carefully scoped. Ideal for apps using Weglot’s ecosystem or needing structured, dynamic translations (e.g., CMS-driven content).TranslationDefinitionResolver) to Laravel’s container. May need a custom provider if Weglot’s defaults don’t align.config/weglot.php; conflicts possible with existing app.php or translation.php keys. Use config.merge() for safe overrides.Weglot::getDefinition()). Avoid mixing with Laravel’s trans() unless explicitly designed for hybrid use.config/filesystems.php) or Eloquent models.weglot/translation-api or other packages. Audit for version conflicts (e.g., PHP 8.1+ features) and unnecessary bloat (e.g., unused API clients).TranslationDefinitionInterface) for abstraction.tideways/xhprof to profile definition resolution.Cache::remember()) or use Laravel’s config caching (php artisan config:cache).composer require weglot/translation-definitions:^1.0 with strict constraints.TranslationDefinition implementations.factory(Translation::class)).trans() helper and middleware (e.g., WeglotMiddleware).@lang, @choice).resources/lang or database-backed translations?laravel-debugbar.)trans() + JSON files suffice? (Lighter weight.)spatie/laravel-translatable) for simpler needs?AppServiceProvider:
$this->app->bind(
TranslationDefinitionResolver::class,
WeglotTranslationResolver::class
);
php artisan vendor:publish --tag=weglot-config
Merge with existing config:
config(['weglot.default_locale' => 'en_US']);
translated) if Weglot emits them:
Event::listen(TranslationResolved::class, function ($event) {
// Log or cache resolved translations
});
composer require php:^8.1
"require": {
"weglot/translation-definitions": "^1.0"
}
resources/lang, database, hardcoded strings).# Current: resources/lang/en/messages.php
"welcome" => "Hello, {name}!"
# Weglot: definitions/en/welcome.yml
key: "messages.welcome"
default: "Hello, {name}!"
placeholders:
name: "string"
// Before: trans('messages.welcome', ['name' => 'John'])
// After: Weglot::trans('messages.welcome', ['name' => 'John'])
resources/lang) with Weglot’s package.trans() helpers).composer require laravel/framework:^9.0
app/Http/Kernel.php:
protected $middlewareGroups = [
'web' => [
\Weglot\TranslationMiddleware::class,
// ...
],
];
{{ trans('key') }} and @lang('key').@weglot).test('resolves Weglot translations', function () {
$translation = Weglot::trans('messages.welcome', ['name' => 'Jane']);
expect($translation)->toBe('Hello, Jane!');
});
composer require weglot/translation-definitions
php artisan vendor:publish --tag=weglot-config
config/weglot.php (e.g., default locale, fallback chain).// Before
echo __('messages.welcome', ['name' => $user->name]);
// After
echo Weglot::trans('messages.welcome', ['name'
How can I help you explore Laravel packages today?