- How do I install `laravel-lang/common` in a Laravel 10+ project?
- Run `composer require laravel-lang/common` via Composer. The package integrates automatically with Laravel’s service container and requires no manual configuration for basic usage. Follow the [official documentation](https://laravel-lang.com/packages-common.html) for advanced setups like dynamic language pack sources.
- Can this package replace Laravel’s built-in `resources/lang` files entirely?
- No, but it supports a hybrid approach. Start by keeping static files as fallbacks while dynamically loading packs from APIs, CDNs, or databases. Use the `config('lang.dynamic_packs.enabled')` flag to enable dynamic packs for specific locales gradually.
- Does `laravel-lang/common` support loading translations from a database?
- Yes, the package supports database-driven language packs. You’ll need to model translations (e.g., a `translations` table with `locale`, `key`, and `value` columns) and configure the source in your `config/lang.php`. JSON fields or dedicated tables work well.
- What happens if a language pack fails to load from an external API/CDN?
- The package includes fallback chains—it will attempt to load from the next source (e.g., local cache, default language) if the primary source fails. Configure retry logic and timeouts in your `config/lang.php` under `fallback_strategy` to handle transient failures gracefully.
- Is there performance overhead for dynamic language packs, and how can I mitigate it?
- Dynamic loading can introduce latency, but the package recommends aggressive caching (e.g., Redis or edge caching like Cloudflare). Set appropriate TTLs in your cache config and monitor translation load times. For critical apps, preload packs during low-traffic periods.
- Will this package work with Laravel 9 or older versions?
- The package is officially tested on Laravel 10+. For older versions, check for deprecated method calls or missing features (e.g., service container changes). You may need to polyfill or adjust middleware if compatibility issues arise.
- Can I customize language pack structures (e.g., nested keys, pluralization rules)?
- Yes, the package supports custom structures. Extend the `LanguagePack` contract or override default parsers in your service provider. For pluralization, integrate with libraries like `voku/translation` or leverage Laravel’s built-in `@choice` directive.
- How do I migrate existing `resources/lang` files to dynamic packs?
- Start with a hybrid setup: keep static files as fallbacks while dynamically loading packs for user-selected languages. Use database migrations to backfill existing translations into your dynamic source (API/CDN/DB). Deprecate static files gradually via middleware or config flags.
- Does this package support right-to-left (RTL) languages or custom interpolation?
- The package is language-agnostic and supports RTL languages out of the box. For custom interpolation (e.g., context-aware fallbacks like `trans('key', ['context' => 'admin'])`), extend the `Translator` facade or create custom macros in your service provider.
- Are there alternatives to `laravel-lang/common` for dynamic translations?
- Alternatives include `spatie/laravel-translatable` (for Eloquent models) or `laravel-localization` (for route/localization helpers). However, `laravel-lang/common` uniquely focuses on reusable tooling for dynamic packs (API/CDN/DB) while maintaining compatibility with Laravel’s core localization system.