Download the PHP package fei/translate-client without Composer
On this page you can find all versions of the php package fei/translate-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fei/translate-client
More information about fei/translate-client
Files in fei/translate-client
Package translate-client
Short Description Flash applicative Translate - client component
License GPL-3.0
Informations about the package translate-client
Service Translate - Client
Table of contents
- Purpose
- Requirements
- Runtime
- Step by step installation
- Initialization
- Configuration
- Settings
- Known issues
- Contribution
- Link to documentation
- Examples
Purpose
This client permit to use the Translate Api
. Thanks to it, you could request the API to :
- Fetch data
- Create data
- Update data
- Delete data
easily
Requirements
Runtime
- PHP 5.5
Step by step Installation
for all purposes (devlopment, contribution and production)
Initialization
-
Cloning repository
- Run Composer depedencies installation
Configuration
The Translate client needs some options to work properly. The available options that can be passed to the __construct()
or setOptions()
methods are :
Option | Description | Type | Possible Values | Default |
---|---|---|---|---|
OPTION_BASEURL | This is the server to which send the requests. | string | Any URL, including protocol but excluding path | -- |
OPTION_HEADER_AUTHORIZATION | Api Key for authentification | string | Any string value | '' |
Settings
Don't forget to set the right baseUrl
:
Beanstalkd configuration
Running Beanstalkd is very simple. However, you must pay attention to the z
option which set the maximum job (or message) size in bytes. So, if you want send multiple translations to Translate API, you should allow enough bytes according to the length of your translations.
Launch Unit test
Start the docker with docker-compose up -d
Then docker exec -ti translateclient_php_1 /var/html/vendor/bin/codecept run unit
Run api-client-worker.php
You could see below an example of running api-client-worker.php
:
php /path/to/translate-client/vendor/bin/api-client-worker.php --host 127.0.0.1 --port 11300 --delay 3
Options | Shortcut | Description | Default |
---|---|---|---|
host | -h |
The host of Beanstalkd instance | localhost |
port | -p |
The port which Beanstalkd instance listening | 11300 |
delay | -d |
The delay between two treatment of the worker | 3 seconds |
verbose | -v |
Print verbose information | - |
You can control the api-client-worker.php process by using Supervisor.
Configuration
In order to make the client working properly, you need to configure a couple of paramaters :.
The configuration takes place in the config/config.php
file. Here is a complete example of the configurations :
lock_file
: this configuration is used to locate thelock
used to determine if you have already subscribed to an API serverdata_path
: this configuration is used to set one directory that will be used to store temporary data when updating the translation cache of your clienttranslations_path
: this configuration is used to set one directory that will be used to store your translation cache filesservers
: this is an array defining all the servers you want to subscribe when calling theTranslate::subscribe
method without any$server
in the parameter of the method.url
: this is the url used to listen the requests coming from the Translate API server when sending new translation cache files. Do not forget this parameter otherwise you will not receive any translations
Known issues
No known issue at this time.
Contribution
As FEI Service, designed and made by OpCoding. The contribution workflow will involve both technical teams. Feel free to contribute, to improve features and apply patches, but keep in mind to carefully deal with pull request. Merging must be the product of complete discussions between Flash and OpCoding teams :)
Link to documentation
Examples
You can test this client easily thanks to the folder examples
Here, an example on how to use example : php /my/translate-client/folder/examples/translate.php
Basic usage
In order to consume Translate
methods, you have to define a new Translate
instance and set the right transport (Asynchronously or Synchronously).
Translate client instance will first attempt to transfer the messages with Beanstalkd, if the process fail then the client will try to send I18nString payload directly to the right API endpoint.
There are several methods in Translate class, all listed in the following table:
Method | Parameters | Return |
---|---|---|
fetchOne | int $id |
I18nString |
fetchAll | ||
find | string $key, string $lang = '', string $domain = '' |
ArrayCollection or I18nString |
search | Pattern $pattern |
array |
store | I18nString $string or array $string |
array |
update | I18nString $string or array $string |
array |
delete | int or I18nString or Pattern or string $parameter |
bool |
subscribe | string $server = null, array $namespaces, $encoding = 'UTF-8' |
bool |
unsubscribe | string $server = null, array $namespaces |
bool |
handleRequest | string $requestUri = null, string $requestMethod = null |
Translate |
setClient | Translate $client |
Translate |
setLang | string $lang |
Translate |
setDomain | string $domain |
Translate |
setLogger | Logger $logger |
Translate |
All versions of translate-client with dependencies
fei/api-client Version ^1.1
fei/logger-client Version ^1.2
doctrine/common Version ^2.6.1
fei/translate-common Version ^1.0.0
nikic/fast-route Version ^1.2
zendframework/zend-diactoros Version ^1.3