PHPackages                             carlosv2/translatte - 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. carlosv2/translatte

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

carlosv2/translatte
===================

Data translation library based on pattern matching

1.0.0(9y ago)016MITPHPPHP &gt;=5.3,&lt;7.2

Since Feb 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/carlosV2/Translatte)[ Packagist](https://packagist.org/packages/carlosv2/translatte)[ RSS](/packages/carlosv2-translatte/feed)WikiDiscussions master Synced today

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

Translatte
==========

[](#translatte)

This package aims to provide an interpretation layer to data.

[![License](https://camo.githubusercontent.com/0d8fec92c1547eca70e6394c7592d74ebb88632a7a2bf541f7f5776c7af948fd/68747470733a2f2f706f7365722e707567782e6f72672f6361726c6f7376322f7472616e736c617474652f6c6963656e7365)](https://packagist.org/packages/carlosv2/translatte)[![Build Status](https://camo.githubusercontent.com/56de05b7130b97b9e28d7543d89ebfac490c70dc773ab7c18cddd9667d9b3cc1/68747470733a2f2f7472617669732d63692e6f72672f6361726c6f7356322f5472616e736c617474652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/carlosV2/Translatte)[![SensioLabsInsight](https://camo.githubusercontent.com/9a37bb65073b3c3e45d1eb71c7ed2d69cd20f68c045a360d6f9781c88a2dc364/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f37626135613737632d333565332d343564622d613038312d3032393931386533393434632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/7ba5a77c-35e3-45db-a081-029918e3944c)

Usage
-----

[](#usage)

There is no limit as per when or for what to use it. The only requisite is that your classes implements the `carlosV2\Translatte\TranslationInterface`.

For example, you can perform language translations:

```
class HelloWorldTranslation implements TranslationInterface
{
    public function matches($message)
    {
        return $message === 'Hello World';
    }

    public function translate($message)
    {
        return 'Hola Mundo';
    }
}
```

Or to translate file paths into their contents:

```
class FileTranslation implements TranslationInterface
{
    public function matches($message)
    {
        return file_exists($message);
    }

    public function translate($message)
    {
        return file_get_contents($message);
    }
}
```

If you want to perform those translations, you will need to instantiate a translator and feed him with the translations:

```
$translator = new Translator();

$translator->addTranslation(new HelloWorldTranslation());
$translator->addTranslation(new FileTranslation());

echo $translator->translate('Hello World'); // Hola Mundo
echo $translator->translate('/etc/passwd'); // The contents of your file
```

### SQL to RAW

[](#sql-to-raw)

Bundled within the library there is a piece of code to help translating SQLs. Be aware it is very simple and it does not understand SQL but rather it works by pattern matching them.

In order to implement those translations, you need to extend `carlosV2\Translatte\SqlToRaw\SqlToRawTranslation`. Despite this class only enforces the implementation of `getSqlPattern` method, you are also required to implement the `process` method.

For example, imagine we have some data indexed by a certain value and, for whatever reason, we have an SQL looking for this data. Using this package, we can grab the value requested in the SQL and use it to select the correct data. Take a look:

```
class LoadRowSql extends SqlToRawTranslation
{
    private $data;

    public function __construct(array $data)
    {
        $this->data = $data;
    }

    protected function getSqlPattern()
    {
        return 'SELECT {*} FROM my_table WHERE field = {field}';
    }

    protected function process($field)
    {
        return $this->data[$field];
    }
}
```

The match will be performed according to the following rules:

- Any character will match itself
- Placeholders will match an unlimited number or characters

The placeholders are composed by `{` + some name + `}` and there are two different placeholders:

- Discard placeholders: It contains an asterisk and it tells the library that we don't care whatever is in there.
- Named placeholders: It contain a valid argument name and it tells the library to extract whatever is in there and provide it as value for the same argument name in the `process` method.

Install
-------

[](#install)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this project:

```
$ composer require carlosv2/translatte
```

This command requires you to have Composer installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

3421d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2642839?v=4)[Carlos Ortega](/maintainers/carlosV2)[@carlosV2](https://github.com/carlosV2)

---

Top Contributors

[![carlosV2](https://avatars.githubusercontent.com/u/2642839?v=4)](https://github.com/carlosV2 "carlosV2 (1 commits)")

---

Tags

datatranslationpatternPattern Matching

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/carlosv2-translatte/health.svg)

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

###  Alternatives

[gettext/gettext

PHP gettext manager

70231.8M115](/packages/gettext-gettext)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)[wcm/wcm-lang-switch

Adds a button to the admin toolbar. This buttons allows users to seamlessly switch between available languages..

202.0k](/packages/wcm-wcm-lang-switch)

PHPackages © 2026

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