PHP code example of dasred / php-phraseapp-client

1. Go to this page and download the library: Download dasred/php-phraseapp-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dasred / php-phraseapp-client example snippets


use DasRed\Zend\Log\Writer\Console as Writer;
use DasRed\Zend\Log\Logger\Console as Logger;
use Zend\Console\Console;
use DasRed\PhraseApp\Synchronize\Files\Type\Php;
use DasRed\PhraseApp\Synchronize\Files;
use DasRed\PhraseApp\Config;

// create logger
$writer = new Writer(Console::getInstance(), Writer::DEBUG);
$logger = new Logger();
$logger->addWriter($writer);

// create the config for synchronizer and co
$projectId = 'This is the project id.';
$accessToken = 'This is the authentication token for your user.';
$localeDefault = 'This is your default or main locale.';
$config = new Config($projectId, $accessToken, $localeDefault);

// This is the user agent which will reported to PhraseApp http://docs.phraseapp.com/api/v2/#identification-via-user-agent
$config->setApplicationName('Fancy Application Name ([email protected])');

// set the direction, which is prefered. If all from PhraseApp is always correct, then REMOTE ist prefered. Otherwise LOCAL
$config->setPreferDirection(Config::PREFER_REMOTE);

// set a default translation key tag which will be setted on translations keys, which will be written to phraseapp
$config->setTagForContentChangeFromLocalToRemote('newContent');

// create the synchronizer for many files
$synchronizer = new Files($logger, $config);

// create and append the handler for file loading and writing
$path = 'This is the path to translation in which the sub pathes defines the locales.';
$excludeNames = ['This is an array of regex to exclude if it match with by file name and file path'];
$handler = new Php($path, $excludeNames);
$synchronizer->appendHandler($handler);


// synchronize everything
if ($synchronizer->synchronize() === false)
{
	throw new \Exception();
}

// instead of
$translator = new \DasRed\Translation\Translator('de-DE', __DIR__);

// use
$translator = new \DasRed\PhraseApp\Translator\PhraseApp('de-DE', __DIR__);