Download the PHP package neam/yii-i18n-attribute-messages without Composer

On this page you can find all versions of the php package neam/yii-i18n-attribute-messages. 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 yii-i18n-attribute-messages

Yii Extension: I18nAttributeMessages

Transparent attribute translation for ActiveRecords, leveraging Yii's built-in translation features to retrieve translated attribute contents.

All you'll need to do is to rename the fields from $book->title to $book->_title in your database. The included console command scans your database and configuration and creates a migration for all necessary renames.

The behavior then transparently turns $book->title into Yii:t('attributes.Book.title', $book->_title) and $book->title_de into Yii:t('attributes.Book.title', $book->_title, array(), null, 'de'), while providing transparent saving of translations simply by assigning and saving these attributes in the model (Note: CDbMessageSource only).

Features

Limitations

Not ideal for translated attributes that are supposed to be native in the active records' database tables, such as translated foreign keys, or multilingual look-up/search columns. Use https://github.com/neam/yii-i18n-columns for those attributes instead.

Requirements

Setup

Download and install

Ensure that you have the following in your composer.json:

"repositories":[
    {
        "type": "vcs",
        "url": "https://github.com/neam/yii-i18n-attribute-messages"
    },
    ...
],
"require":{
    "neam/yii-i18n-attribute-messages":"dev-master",
    ...
},

Then install through composer:

php composer.phar update neam/yii-i18n-attribute-messages

If you don't use composer, clone or download this project into /path/to/your/app/vendor/neam/yii-i18n-attribute-messages

Add Alias to both main.php and console.php

'aliases' => array(
    ...
    'vendor'  => dirname(__FILE__) . '/../../vendor',
    'i18n-attribute-messages' => 'vendor.neam.yii-i18n-attribute-messages',
    ...
),

Import the behavior in main.php

'import' => array(
    ...
    'i18n-attribute-messages.behaviors.I18nAttributeMessagesBehavior',
    ...
),

Reference the console command in console.php

'commandMap' => array(
    ...
    'i18n-attribute-messages'    => array(
        'class' => 'i18n-attribute-messages.commands.I18nAttributeMessagesCommand',
    ),
    ...
),

Configure models to be multilingual

1. Add the behavior to the models that you want multilingual

public function behaviors()
{
    return array(
        'i18n-attribute-messages' => array(
             'class' => 'I18nAttributeMessagesBehavior',

             /* The multilingual attributes */
             'translationAttributes' => array(
                  'title',
                  'slug',
                  'book_id',
                  //'etc',
             ),

            /* An array of allowed language/locale ids that are to be used as suffixes, such as title_en, title_de etc */
            //'languageSuffixes' => array_keys(Yii::app()->params["languages"]),

            /* Configure if you want to use another translation component for this behavior. Default is 'messages' */
            //'messageSourceComponent' => 'attributeMessages',

        ),
    );
}

2. Create migration from command line:

./yiic i18n-attribute-messages process

Run with --verbose to see more detailed output.

3. Apply the generated migration:

./yiic migrate

This will rename the fields that are defined in translationAttributes to _fieldname, which will be the placed that the source content is stored (the content that is to be translated).

Sample migration file:

</div>

Note: This field is generated automatically by Gii.

Creating an input to set/update the swedish translation of the field "title"

<div class="row">

</div>

Hint: You might want to display the source language content next to the translation field, like so:

<div class="row">
    : 
</div>
<div class="row">

</div>

Also, don't forget to adjust the validation rules (safe, required, etc) for the virtual translation fields.

Creating an input to set/update the current app language's translation of the field "title"

<div class="row">

</div>

More examples

Simply look at any other examples of form building in Yii. Since the translated attributes are ordinary model attributes, you may use core or third-party extensions that save to and read from model attributes for constructing your translation UI.

Changelog

0.1.0

0.0.0

Testing the extension

One-time preparations

Switch to the extension's root directory

cd vendor/neam/yii-i18n-attribute-messages

Create a database called yiam_test in your local mysql server installation. Create a user called yiam_test with yiam_test as the password and make sure that this user has access to the local database.

After this, you can run the following routine to test the extension:

Test the command

1. Set-up the test database

Load tests/db/unmodified.sql into the database.

2. Run the console command

tests/app/protected/yiic i18n-attribute-messages process

3. Apply the migration

tests/app/protected/yiic migrate

Test the behavior

Run the unit tests

php codecept.phar run unit

You should get output similar to:

Codeception PHP Testing Framework v1.6.2
Powered by PHPUnit 3.7.19 by Sebastian Bergmann.

Suite unit started
Trying to ensure empty db (BasicTest::ensureEmptyDb) - Ok
Trying to ensure known source language (BasicTest::ensureKnownSourceLanguage) - Ok
Trying to see behavior (BasicTest::seeBehavior) - Ok
Trying to interpret language suffix (BasicTest::interpretLanguageSuffix) - Ok
Trying to get (BasicTest::get) - Ok
Trying to set without suffix (BasicTest::setWithoutSuffix) - Ok
Trying to set with suffix (BasicTest::setWithSuffix) - Ok
Trying to save single with source message (BasicTest::saveSingleWithSourceMessage) - Ok
Trying to save single without source message (BasicTest::saveSingleWithoutSourceMessage) - Ok
Trying to fetch single without suffix (BasicTest::fetchSingleWithoutSuffix) - Ok
Trying to reuse previous translation (BasicTest::reusePreviousTranslation) - Ok
Trying to update existing (BasicTest::updateExisting) - Ok
Trying to further fallback behavior tests (BasicTest::furtherFallbackBehaviorTests) - Ok
Trying to test test suite (EmptyTest::testTestSuite) - Ok

Time: 0 seconds, Memory: 14.25Mb

OK (14 tests, 124 assertions)

All versions of yii-i18n-attribute-messages with dependencies

PHP Build Version
Package Version
Requires php Version >=5.0.0
yiisoft/yii Version >=1.1.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 neam/yii-i18n-attribute-messages contains the following files

Loading the files please wait ....