- How do I add translatable fields to an Eloquent model in Laravel?
- Use the `translatable()` migration macro in your schema definition to add `locale` and `locale_parent_id` fields, then apply the `Translatable` trait to your model. The package handles the rest, including translation relations and query scopes.
- Does `novius/laravel-translatable` support Laravel 13?
- Yes, the package officially supports Laravel 10 through 13. Check the [GitHub repository](https://github.com/novius/laravel-translatable) for the latest version compatibility before installing.
- Can I customize which attributes are translatable in my model?
- Yes, override the `translatableConfig()` method in your model to specify custom attributes for translation. By default, all non-reserved fields are translatable unless excluded.
- How do I handle missing translations (fallbacks) in my app?
- The package doesn’t enforce fallbacks, so you’ll need to implement logic manually—e.g., fetch translations from a default locale or return `null`. Use `getTranslation()` with a fallback check in your application code.
- Will soft-deleted parent models automatically delete their translations?
- No, soft deletes on parent models won’t cascade to translations by default. Use the `translationsWithDeleted` relation to include soft-deleted translations, or configure cascading deletes in your migration.
- Is this package suitable for high-traffic applications with many languages?
- The package uses a single-table design, which may struggle with >50 languages or millions of records. Monitor performance and consider indexing `locale` and `locale_parent_id` fields. For scalability, alternatives like `spatie/laravel-translatable` might be better.
- How do I query translations for a specific locale in Laravel?
- Use the `withLocale($locale)` scope on your model’s query builder. For example, `Post::withLocale('en')->get()` retrieves only English translations. Combine with `getTranslation()` for single-record lookups.
- Does this package support many-to-many translation relationships (e.g., multilingual tags)?
- No, this package is designed for one-to-many relationships (parent → translations). For many-to-many scenarios (e.g., tags), consider a custom solution or packages like `spatie/laravel-translatable` with pivot tables.
- How do I test translations in my Laravel application?
- Mock translations in unit tests by creating model instances with `translate()` or manually setting `locale` and `locale_parent_id`. Use `getTranslation()` to verify locale-specific data. For integration tests, seed translations in your database.
- What are the license implications of using `novius/laravel-translatable` in a proprietary project?
- The package is licensed under AGPL-3.0, which may require open-sourcing your project or forking the package. Review the license carefully or consider alternatives like `spatie/laravel-translatable` (MIT) for proprietary use.