Download the PHP package carlosv2/translatte without Composer
On this page you can find all versions of the php package carlosv2/translatte. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download carlosv2/translatte
More information about carlosv2/translatte
Files in carlosv2/translatte
Package translatte
Short Description Data translation library based on pattern matching
License MIT
Informations about the package translatte
Translatte
This package aims to provide an interpretation layer to data.
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:
Or to translate file paths into their contents:
If you want to perform those translations, you will need to instantiate a translator and feed him with the translations:
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:
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
Open a command console, enter your project directory and execute the following command to download the latest stable version of this project:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.