Download the PHP package lundo/laravel-translations without Composer

On this page you can find all versions of the php package lundo/laravel-translations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-translations

laravel-translations

Transparent polymorphic translations for Eloquent models. The default locale is stored directly in model columns; all other locales are stored in a shared translations table — no JSON columns, no extra casts.

Requirements

Installation

Run the migration:

The migration is loaded automatically by the package — no publish step needed. If you prefer to customise it, you can publish it first:

Optionally publish the config:

Setup

Add the HasTranslations trait to your model and define a $translatable array:

That's it. The default locale (nl by default) is read from and written to the model columns as normal. Non-default locales are transparently read from and written to the translations table.

Reading translations

Accessing a translatable attribute always returns the value for the active locale, falling back to the model column if no translation exists:

Get a specific locale explicitly:

Check existence:

Get all locales the model has a value for:

Writing translations

Setting an attribute while a non-default locale is active buffers the value and persists it when the model is saved:

Set a specific locale directly (bypasses the active locale):

Set multiple locales at once:

Removing translations

Validation rules

Two rules are provided for validating locale-map payloads (e.g. { "nl": "Hallo", "en": "Hello" }).

Register the macros once (e.g. in a service provider):

Rule::localized() — accepts a plain string (treated as the default locale) or an array whose keys are all valid locales and whose values are strings or null. Use on update endpoints where partial input is acceptable.

Rule::localeRequired() — like localized but additionally requires every configured locale to be present with a non-empty value. Use on create endpoints.

Localized media (optional — requires spatie/laravel-medialibrary)

HasLocalizedMedia adds a getLocalizedMedia() method that returns media for the active locale, falling back to the fallback locale, then to untagged (legacy) media. Requires a locale custom property on each media item.

Middleware

SetLocaleFromUser reads the authenticated user's preferred locale and sets it for the request. Register it in your route middleware:

The attribute it reads from is configurable:

Performance scope

WithActiveLocaleScope is an opt-in global scope that eager-loads only the active locale's translations instead of all locales. Add it to a model when you have many locales and want to avoid loading all rows:

Configuration

Key Default Description
default_locale env('APP_LOCALE', 'nl') Locale stored in model columns
fallback_locale env('APP_FALLBACK_LOCALE', 'nl') Fallback when translation is missing
model Translation::class Eloquent model for the translations table
user_locale_attribute preferred_locale User attribute read by the middleware

License

MIT


All versions of laravel-translations with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
laravel/framework Version ^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lundo/laravel-translations contains the following files

Loading the files please wait ...