Download the PHP package codewiser/multilingual without Composer

On this page you can find all versions of the php package codewiser/multilingual. 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 multilingual

Multilingual Cast

Multilingual attribute keeps a set of values in different locales. Such an attribute is stored in a database as a JSON object.

id name
1 {"en":"Michael","es":"Miguel"}

Multilingual lets you deal with such an attribute just like a plain one:

Usage

Apply the cast and include HasMultilingual, which gives access to the lowdown of a multilingual attribute.

Storing

A new value will be implicitly stored in the current locale.

However, you may explicitly define a locale.

Reading

A plain value will be implicitly retrieved in the current locale. It is enough to properly apply the Accept-Language header from a User-Agent — and the user will get content in a preferred language.

If there is no value for the requested locale, the fallback locale is tried next, and then the first value in the map — even when that value is empty.

You may explicitly define a locale.

Hydrating

Reading gives a plain value, so ask for the Multilingual object when you need another locale, or every locale at once.

A hydrated attribute gives back the whole object.

Hydrating a non-multilingual attribute throws an InvalidArgumentException.

Serializing

Serialization is never hydrated implicitly — $model->toArray() holds plain values.

Ask for it explicitly wherever every locale belongs in the output.

Language tags

You may access a hydrated Multilingual using language tags as well. The package uses locale_filter_matches to find the best variant:

Strict mode

If you try to get a value that is missing, the Multilingual will try to return any convenient value — using the fallback locale or just the first one:

You may enable strict mode, and then Multilingual will return the exact value:

Multilingual arrays

As we may keep multilingual scalars, we may keep multilingual arrays as well:

Multilingual objects

Multilingual array could be mapped into an object:

Changing a mapped object

The very same object is handed out on every read, so changing it changes the attribute. The change is written back right before the attributes are read, dirtied, serialized or saved, so it behaves like any other change of the model.

Assigning the attribute replaces the object, so a change made to the old one is gone:

The write back hangs on getAttributes(), which is what getDirty(), toArray(), save() and friends funnel through. A model defining its own getAttributes() overrides the one from the trait, and then it has to call flushMultilingualAttributes() itself.

Multilingual collection

You may cast an attribute to a collection of Multilingual values. It is possible to map every row into an object. Strict mode is supported as well:

Multilingual collection (Laravel's cast)

It is possible to cast Multilingual to a collection using Laravel's AsCollection:

AsCollection::of() maps into the class directly, so it never routes through the cast. Elements are always Multilingual objects here.

The attribute is not recognised as multilingual though, so multilingual() throws an InvalidArgumentException for it, and Multilingual::of() leaves it untouched. Use AsMultilingual::collect() above when the whole collection has to be hydrated.


All versions of multilingual with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-intl Version *
laravel/framework Version >=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 codewiser/multilingual contains the following files

Loading the files please wait ...