PHPackages                             zaszczyk/translatable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. zaszczyk/translatable

ActiveLibrary[Localization &amp; i18n](/categories/localization)

zaszczyk/translatable
=====================

Manage translatable fields with Phalcon models. Forked from https://github.com/ovide/translatable

1.0.1(8y ago)05.3kPHP

Since Oct 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Zaszczyk/translatable)[ Packagist](https://packagist.org/packages/zaszczyk/translatable)[ RSS](/packages/zaszczyk-translatable/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

translatable
============

[](#translatable)

Manage translatable fields with Phalcon models

Example
-------

[](#example)

You have a database table `MyModel` with columns `id`, `value`, `timestamp` and `description`; but `description` must be a translatable field.

You can add a`Translation` table as

```
CREATE TABLE `translation` (
  `table` varchar(255) NOT NULL,
  `field` varchar(255) NOT NULL,
  `row` varchar(255) NOT NULL,
  `lang` char(2) NOT NULL,
  `text` text NOT NULL,
  PRIMARY KEY (`table`,`field`,`row`,`lang`)
)
```

```
use \Ovide\Lib\Translate as Translate;

/**
 * Your translatable model
 * @property string $description
 */
class MyModel extends Translate\Model
{
    public $id;
    public $value;
    public $timestamp;
    protected $_translatable = ['description'];
}

/**
 * This is a default basic abstract model, but you can add yours
 */
class Translation extends Translate\Adapter\Model\AbstractModel{}

$di = new \Phalcon\DI\FactoryDefault();
$di->setShared('db', function () {
    return new \Phalcon\Db\Adapter\Pdo\Mysql([/* my config */]);
});

/**
 *             HERE WE SET THE TRANSLATOR
 */
$di->setShared('translator', function() {
    $service = new Translate\Service();
    //All translatable models from 'db'
    //will use 'Translation' to manage the translations
    $service->attachAdapter(
        'db',
        Translate\Adapter\Model\Manager::class,
        ['backendModel' => 'Translation']
    );
    //You can use a default language resolver
    Translate\Model::setLanguageResolver(function() use($di){
        //You can put anything here
        if (isset($_COOKIE['lang'])) return $_COOKIE['lang'];
        return 'en';
    });
});
```

Now you can use translatable fiels as normal properties

```
$model = new MyModel();
$model->value = 'foo';
//Will set the text using the default language
$model->description = 'my description';
//You can change the current language
$model->setCurrentLang('es');
$model->description = 'mi descripción';
//Or use setter/getter
$model->setTranslation('description', 'la meva descipció', 'ca');
$model->save();
```

Adapters
--------

[](#adapters)

You can use any addapter to store translations. By now there's a Model (SQL) and Collection (Mongo) adapter. Just implement `TranslationInterface` to create your own.

```
interface TranslationInterface
{
    public static function retrieve(Model $model, $pk, array $options = null);
    public function get($field, $language);
    public function set($field, $language, $value);
    public function persist(array $records = null);
    public function remove();
}
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 76.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~550 days

Total

2

Last Release

2984d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/80387322?v=4)[MateuszBlaszczyk](/maintainers/MateuszBlaszczyk)[@MateuszBlaszczyk](https://github.com/MateuszBlaszczyk)

---

Top Contributors

[![Zaszczyk](https://avatars.githubusercontent.com/u/7737337?v=4)](https://github.com/Zaszczyk "Zaszczyk (10 commits)")[![ovide](https://avatars.githubusercontent.com/u/3451025?v=4)](https://github.com/ovide "ovide (3 commits)")

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/zaszczyk-translatable/health.svg)

```
[![Health](https://phpackages.com/badges/zaszczyk-translatable/health.svg)](https://phpackages.com/packages/zaszczyk-translatable)
```

###  Alternatives

[php-translation/translator

Translator services

25224.8k5](/packages/php-translation-translator)[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1926.6k1](/packages/smmoosavi-php-gettext)[laradevs/spanish

labels translated to spanish

166.7k](/packages/laradevs-spanish)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
