fei / translate-client
Flash applicative Translate - client component
Installs: 8 463
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 23
Forks: 0
Open Issues: 3
Type:project
Requires
- php: >=5.5
- doctrine/common: ^2.6.1
- fei/api-client: ^1.1
- fei/logger-client: ^1.2
- fei/translate-common: ^1.0.0
- nikic/fast-route: ^1.2
- zendframework/zend-diactoros: ^1.3
Requires (Dev)
- codeception/codeception: ^2.2
- jakub-onderka/php-parallel-lint: ^0.9.2
- sebastian/phpcpd: ^2.0
- squizlabs/php_codesniffer: ^2.7
- dev-master
- v1.8.0
- v1.7.0
- v1.3.0
- v1.2.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/guzzlehttp/guzzle-6.5.8
- dev-dependabot/composer/guzzlehttp/psr7-1.8.5
- dev-dependabot/composer/codeception/codeception-3.1.3
- dev-detached2
- dev-detached
- dev-develop
- dev-feature/create_dir_trans
- dev-feature/update_composer_api_client
This package is auto-updated.
Last update: 2024-12-20 09:23:55 UTC
README
Table of contents
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
git clone https://github.com/flash-global/translate-client.git
- Run Composer depedencies installation
composer install
Configuration
The Translate client needs some options to work properly. The available options that can be passed to the __construct()
or setOptions()
methods are :
Settings
Don't forget to set the right baseUrl
:
<?php $translate = new Translate([Translate::OPTION_BASEURL => 'http://translate.dev']); $translate->setTransport(new BasicTransport());
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
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 :
<?php return [ 'lock_file' => dirname(__DIR__) . '/.translations.lock', 'data_path' => dirname(__DIR__) . '/data', 'translations_path' => dirname(__DIR__) . '/translations', 'servers' => [ 'http://10.5.0.1:8010' => [ 'namespaces' => ['/a/b/c/d'] ] ], 'url' => 'http://10.6.0.1:8040/examples/handleRequest.php/update' ];
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).
<?php use Fei\Service\Translate\Client\ Translate; use Fei\ApiClient\Transport\BasicTransport; use Fei\ApiClient\Transport\BeanstalkProxyTransport; use Pheanstalk\Pheanstalk; $translate = new Translate([Translate::OPTION_BASEURL => 'https://translate.api']); // Put your translate API base URL here $translate->setTransport(new BasicTransport()); $proxy = new BeanstalkProxyTransport(); $proxy->setPheanstalk(new Pheanstalk('127.0.0.1')); $translate->setAsyncTransport($proxy); // Use the translate client methods...
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: