Download the PHP package tuzelko/yii2-localizable without Composer

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

Yii2 Localization extension

Project Status: Active Tests Latest Version PHP Version Total Downloads License

Localization extension for the Yii2 framework.

Stores localized attributes in a per-language related table (one row per language) instead of a JSON column, so the values stay plain, indexable columns you can search and sort on. A single behavior virtualizes those columns on the owner model, and a matching validator drops localization payloads straight into a form's rules().

Features

Requirements

Installation

How it works

The owner model holds no localized columns itself. Instead it owns a hasMany relation to a localization table that carries one row per language:

Owner (post) Localization (post_localization)
id id, post_id, lang, is_default, title, description, …

Exactly one row per owner is flagged is_default — that language is the fallback when the current one is missing. The behavior reads and writes that whole set through a single virtual property.

Quick start

1. Create the tables in your migration

2. The localization row model

Its rules() are the single source of field validation — the behavior runs the payload against them.

3. Attach the behavior to the owner

The behavior reads the row class and FK link off the relation, so the relation must be a plain FK hasMany.

That's it. $post->title is now a virtual, language-aware attribute, and $post->localization reads/writes the whole structure.

Reading localized attributes

The structured form is available through the singular localization virtual:

The singular localization is the structured object; the plural localizations relation is the raw row collection (use it for eager loading).

Writing localizations

Assign the {default, values} structure and save — the behavior rebuilds the rows in a transaction and sets is_default on the default language:

Saving again with a different structure replaces the whole set. A new owner with no localizations assigned fails validation — at least one localization is required.

Validation in forms

Drop LocalizationValidator into a form's rules(), pointing it at a localizable model. It pulls the row class and field rules off that model's behavior, so the form restates neither:

Being a plain rule, it keeps the usual knobs (on / when / skipOnEmpty / message). Field-level violations (a too-long or missing title) surface as validation errors (→ 400) instead of a save-time exception (→ 500).

Translated messages

The bundled validation messages ship translated into many languages — the full Yii2 locale set. The extension's composer bootstrap registers the localization message category automatically, so they work without any config in the consuming app — Yii::$app->language is all that matters.

Need to override a message or add a language? Define your own localization translation in the app config; the bootstrap never overwrites an existing one:

Deletion behaviour

The behavior owns the localization rows end to end. Hard-deleting an owner removes its rows automatically (hook it once, never forget cleanup). Soft-delete does not fire the delete event, so a soft-deleted owner keeps its localizations and they come back on restore.

Running tests

Tests run inside Docker (PHP 8.0 + SQLite) with no local setup required.

License

MIT — see LICENSE.


All versions of yii2-localizable with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
yiisoft/yii2 Version ~2.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 tuzelko/yii2-localizable contains the following files

Loading the files please wait ...