-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to list locales used in a project
This way we can more easily download all locales in a cli script (fetch them using this command and then download in a loop)
- Loading branch information
1 parent
241286b
commit b0a7988
Showing
2 changed files
with
48 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Teamleader\OneSky; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ListLocaleCommand extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this | ||
->setName('list-locale') | ||
->setDescription('List the locale enabled in the project'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->initializeClient($input->getOption('key'), $input->getOption('secret')); | ||
|
||
$project_id = $input->getOption('project_id'); | ||
if (is_null($project_id)) { | ||
$project_id = $this->config['project_id']; | ||
} | ||
|
||
$response = $this->client->projects('languages', [ | ||
'project_id' => $project_id, | ||
]); | ||
|
||
if (!$response) { | ||
$output->writeln('<error>Empty OneSky response!</error>'); | ||
exit(1); | ||
} | ||
|
||
$data = json_decode($response, true); | ||
if (isset($data['meta']) && $data['meta']['status'] != 200) { | ||
$output->writeln('<error>' . $data['meta']['message'] . '</error>'); | ||
exit(1); | ||
} | ||
|
||
foreach ($data['data'] as $language) { | ||
$output->writeln($language['code']); | ||
} | ||
} | ||
} |