-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make sure we are transferable * Use async * style fix * Bugfix * Style fix
- Loading branch information
Showing
2 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,19 @@ | |
use FAPI\Localise\Exception\Domain\AssetConflictException; | ||
use FAPI\Localise\Exception\Domain\NotFoundException; | ||
use FAPI\Localise\LocoClient; | ||
use Symfony\Component\Translation\Loader\ArrayLoader; | ||
use Symfony\Component\Translation\MessageCatalogueInterface; | ||
use Translation\Common\Exception\StorageException; | ||
use Translation\Common\Model\Message; | ||
use Translation\Common\Storage; | ||
use Translation\Common\TransferableStorage; | ||
|
||
/** | ||
* Localize.biz. | ||
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class Loco implements Storage | ||
class Loco implements Storage, TransferableStorage | ||
{ | ||
/** | ||
* @var LocoClient | ||
|
@@ -122,12 +125,48 @@ public function delete($locale, $domain, $key) | |
$this->client->translations()->delete($projectKey, $key, $locale); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function export(MessageCatalogueInterface $catalogue) | ||
{ | ||
$locale = $catalogue->getLocale(); | ||
$loader = new ArrayLoader(); | ||
foreach ($this->domainToProjectId as $domain => $projectKey) { | ||
try { | ||
$data = $this->client->export()->locale( | ||
$projectKey, | ||
$locale, | ||
'json', | ||
['format' => 'symfony'] | ||
); | ||
$array = json_decode($data, true); | ||
$catalogue->addCatalogue( | ||
$loader->load($array, $locale, $domain) | ||
); | ||
} catch (NotFoundException $e) { | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function import(MessageCatalogueInterface $catalogue) | ||
{ | ||
$locale = $catalogue->getLocale(); | ||
foreach ($this->domainToProjectId as $domain => $projectKey) { | ||
$data = json_encode($catalogue->all($domain)); | ||
$this->client->import()->import($projectKey, 'json', $data, ['locale' => $locale, 'async' => 1]); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $domain | ||
* | ||
* @return string | ||
*/ | ||
protected function getApiKey($domain) | ||
private function getApiKey($domain) | ||
{ | ||
if (isset($this->domainToProjectId[$domain])) { | ||
return $this->domainToProjectId[$domain]; | ||
|