dasred / php-phraseapp-client
此包已被弃用,不再维护。未建议替代包。
关于此包最新版本(v2.1.1)没有可用的许可信息。
v2.1.1
2015-10-22 09:59 UTC
Requires
- php: >=5.5
- ext-curl: *
- dasred/translation: @stable
- dasred/zend-console: @stable
- dasred/zend-log: @stable
- zendframework/zend-http: @stable
- zendframework/zend-progressbar: ~2.5
README
PHP PhraseApp 客户端用于 PhraseApp 和 API 版本 2。
CLI 使用
tr-sync
使用
bin/tr-sync [options] sourcePath
参数
sourcePath 要搜索的路径。
选项
--projectId (-p) <string> project id
--accessToken (-a) <string> user access token
--localeDefault (-l) <string> default locale. Default de-DE
--applicationName (-n) [ <string> ] name of your application. Default PHP PhraseApp Client
--preferDirection (-d) [ <string> ] prefer direction for sync (remote, local). Default: remote
--exclude (-x) [ <string> ] regex to exclude files. can be given multiple times: Default: []
--tagForContentChangeFromLocalToRemote (-t) [ <string> ] tag for content change from local to remote. Default: newContent
--help (-h) Display this help message
--quiet (-q) Do not output any message
--version (-V) Display this application version
phraseapp
使用
bin/phraseapp [options] operation
区域操作
locale create <locale> [localeSource] creates the given locale.
locale list list all locales
键操作
key addTag <key> <tag> add the tag to the key.
key create <name> [description] [tag ...] create a new key.
key delete <key> deletes the key.
key list list the key.
key update <key> <name> [description] [tag ...] updates the key.
翻译操作
translation store <locale> <key> <content> set content of a key for a locale.
选项
--projectId (-p) <string> project id
--accessToken (-a) <string> user access token
--localeDefault (-l) <string> default locale. Default de-DE
--applicationName (-n) [ <string> ] name of your application. Default PHP PhraseApp Client
--help (-h) Display this help message
--version (-V) Display this application version
同步的 PHP 使用
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 (nuff@example.com)'); // 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(); }
PhraseApp 内联翻译的 PHP 使用
不要使用来自 \DasRed\Translation\Translator 的原始翻译器,而是在此客户端中使用 Translator (\DasRed\PhraseApp\Translator\PhraseApp)
// instead of $translator = new \DasRed\Translation\Translator('de-DE', __DIR__); // use $translator = new \DasRed\PhraseApp\Translator\PhraseApp('de-DE', __DIR__);
然后执行来自 PhraseApp 的其余解释。内联键前缀将是 "{{__phrase_" 和后缀将是 "__}}"。