Download the PHP package 2amigos/yii2-translateable-behavior without Composer

On this page you can find all versions of the php package 2amigos/yii2-translateable-behavior. 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-translateable-behavior

TranslateableBehavior for Yii2

This behavior has been inspired by the great work of Mikehaertl's Translatable Behavior for Yii 1.*.

It eases the translation of ActiveRecord's attributes as it maps theme from a translation table into the main record. It also automatically loads application language by default.

Sample of use:

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your application's composer.json file.

Usage

Preparation

First you need to move all the attributes that require to be translated into a separated table. For example, imagine we wish to keep translations of title and description from our tour entity. Our schema should result on the following:

After we have modified our schema, now we need to define a relation in our ActiveRecord object. The following example assumes that we have already created a TourLang model (see the schema above):

Finally, we need to attach our behavior.

Basic Usage

You may also set multiple translations directly:

Fallback language

In case no translation is available for a specific language the behavior allows to specify a fallback translation to load instead. By default the fallback will use the application source language. It can be configured by setting the fallbackLanguage property of the behavior.

Fallback language can be configured to be a single language or per language:

Additionally to the configurable fallback a fallback to non-localized language is applied automatically. E.g. if no translation exists for de-AT (German in Austria) the translation will fall back to de. The fallback goes further if de is not found using the fallbackLanguage configuration, so from the example above it will then try en.

When the fallback is defined in array format and no fallback can be found for a language, the first fallback is returned.

You may disable the fallback mechanism by setting fallbackLanguage to false.

If you want to configure fallback languages globally, you can do so by configuring the TranslateableBehavior class in Yii DI container:

Deleting translations

By default, when an active record is deleted, translation records are deleted in the afterSave event. However some database scenarios require different configuration, in case foreign keys restrict the deletion of records.

You may configure 'deleteEvent' to be either ActiveRecord::EVENT_BEFORE_DELETE or ActiveRecord::EVENT_AFTER_DELETE to control on which event the deletion of records should be performed. You may set 'deleteEvent' to false to disable deletion and rely on DB foreign key cascade or implement your own method.

When using the Translateablebehavior in an ActiveRecord you should enable [transactions()](https://www.yiiframework.com/doc/api/2.0/yii-db-activerecord#transactions()-detail) for the delete operation.

2amigOS!
Web development has never been so fun!
www.2amigos.us


All versions of yii2-translateable-behavior with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
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 2amigos/yii2-translateable-behavior contains the following files

Loading the files please wait ....