fei / translate-package
Translate client package integration for Objective PHP applications
Installs: 10 364
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 24
Forks: 0
Open Issues: 5
Requires
- php: >=7.0
- fei/connect-client: ^3.1
- fei/translate-client: ^1.4
- objective-php/application: ^1.0
- objective-php/cli: ^1.2
- dev-master
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- 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/phpseclib/phpseclib-2.0.31
- dev-dependabot/composer/symfony/http-foundation-3.4.47
- dev-dependabot/composer/robrichards/xmlseclibs-3.1.1
- dev-detached
- dev-detached2
- dev-feature/add-api-key
- dev-develop
- dev-feature/update_translate_client
This package is auto-updated.
Last update: 2024-12-20 09:29:01 UTC
README
This package provide Translate Client integration for Objective PHP applications.
Installation
Translate Package needs PHP 7.0 or up to run correctly.
You will have to integrate it to your Objective PHP project with composer require fei/translate-package
.
Integration
As shown below, the Translate Package must be plugged in the application initialization method.
The Translate Package create a Translate Client service that will be consumed by the application's middlewares.
<?php use ObjectivePHP\Application\AbstractApplication; use Fei\Service\Translate\Package\TranslatePackage; class Application extends AbstractApplication { public function init() { // Define some application steps $this->addSteps('bootstrap', 'init', 'auth', 'route', 'rendering'); // Initializations... // Plugging the Translate Package in the bootstrap step $this->getStep('bootstrap') ->plug(TranslatePackage::class); // Another initializations... } }
Application configuration
Create a file in your configuration directory and put your Translate configuration as below:
<?php use Fei\Service\Translate\Package\Config\TranslateParam; use Fei\ApiClient\Transport\BasicTransport; return [ new TranslateParam('base_url', 'http://translate.api/'), // Translate API URL and port new TranslateParam('transport', new BasicTransport()), // Transport type new TranslateParam('translate_directory', '/app/translate/'), // Directory to store the translations new TranslateParam('translate_config', [ 'lock_file' => '/app/translate/.translations.lock', 'data_path' => '/app/translate/data', 'translations_path' => '/app/translate/translations', 'localTranslationsFile' => dirname(__DIR__) . '/localTranslations.php', 'skipSubscription' => false, 'servers' => [ 'http://translate.api/' => [ 'namespaces' => ['/mynamespace'], 'host' => 'other-host' ] ], 'url' => 'http://translate.domain.dev/handleRequest.php' ]),// Translate client config (Cf. Translate Client documentation) new TranslateParam('translate_namespace', '/mynamespace'), // Namespace defined in translate_config where to search the translations new TranslateParam('translate_lang', 'en_GB') // Language defined in which we want the translations ];
In the previous example you need to set this configuration:
base_url
: represent the URL where the API can be contacted in order to send the translationstransport
: represent the translations transport typetranslate_directory
: represent the path to the directory to store the translationstranslate_config
: represent the translate client configuration (Cf.translate-client
documentation)translate_namespace
: represent the default namespace where to search the translationstranslate_lang
: represent the default language in which we want the translations
Note that if you want your application to use local translations and not subscribe to a Translate server you can configure your application like this:
<?php use Fei\Service\Translate\Package\Config\TranslateParam; return [ new TranslateParam('translate_config', [ 'localTranslationsFile' => dirname(__DIR__) . '/localTranslations.php', 'skipSubscription' => true, ]), ];
Please check out translate-client
documentation for more information about how to use this client.