Download the PHP package tableau-mkt/eggs-n-cereal without Composer
On this page you can find all versions of the php package tableau-mkt/eggs-n-cereal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tableau-mkt/eggs-n-cereal
More information about tableau-mkt/eggs-n-cereal
Files in tableau-mkt/eggs-n-cereal
Package eggs-n-cereal
Short Description A basic PHP XLIFF serialization library.
License GPL-2.0+
Informations about the package eggs-n-cereal
Eggs'n'Cereal
A basic, generic PHP XLIFF serialization library.
Installation
The recommended way to install Eggs'n'Cereal is of course to use Composer:
Note: There is no stable release, necessarily. So...
Usage
The basic idea of this library is that you provide a series of "translatable"
classes for your entities. These "translatable" classes implement the
EggsCereal\Interfaces\TranslatableInterface
interface.
A TranslatableInterface
instance is meant to wrap your entity with a unified
method to get and set data. You must do so by implementing:
TranslatableInterface::getData()
TranslatableInterface::setData()
In addition to getting and setting data, you must also provide a way to get a unique identifier for your translatable entity, as well as a label by implementing:
TranslatableInterface::getIdentifier()
TranslatableInterface::getLabel()
The identifier and label are used to validate an XLIFF file during the import / unserialization process.
Once you've implemented the interface, you can serialize and unserialize your translatable like so:
Sample implementation
Suppose you want to translate data stored in a flat, single-level PHP array. You
might write an ArrayTranslatable
class like so:
With this ArrayTranslatable
implementation, usage is straightforward.
Forewarning
This library is a work in progress and draws heavily from work by Cloudwords on their Cloudwords for Multilingual Drupal module.
Use at your own risk, for now.