Merge pull request #583 from nextcloud/issue-577-add-l10n

Add L10N support
This commit is contained in:
Morris Jobke 2016-07-28 16:12:45 +02:00 committed by GitHub
commit 1e4266b076
3 changed files with 26 additions and 14 deletions

View File

@ -24,6 +24,7 @@ namespace OCA\WorkflowEngine\Check;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\WorkflowEngine\ICheck; use OCP\WorkflowEngine\ICheck;
@ -42,13 +43,18 @@ class UserGroupMembership implements ICheck {
/** @var IGroupManager */ /** @var IGroupManager */
protected $groupManager; protected $groupManager;
/** @var IL10N */
protected $l;
/** /**
* @param IUserSession $userSession * @param IUserSession $userSession
* @param IGroupManager $groupManager * @param IGroupManager $groupManager
* @param IL10N $l
*/ */
public function __construct(IUserSession $userSession, IGroupManager $groupManager) { public function __construct(IUserSession $userSession, IGroupManager $groupManager, IL10N $l) {
$this->userSession = $userSession; $this->userSession = $userSession;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->l = $l;
} }
/** /**
@ -83,11 +89,11 @@ class UserGroupMembership implements ICheck {
*/ */
public function validateCheck($operator, $value) { public function validateCheck($operator, $value) {
if (!in_array($operator, ['is', '!is'])) { if (!in_array($operator, ['is', '!is'])) {
throw new \UnexpectedValueException('Invalid operator', 1); throw new \UnexpectedValueException($this->l->t('Operator %s is invalid', $operator), 1);
} }
if (!$this->groupManager->groupExists($value)) { if (!$this->groupManager->groupExists($value)) {
throw new \UnexpectedValueException('Group does not exist', 2); throw new \UnexpectedValueException($this->l->t('Group %s does not exist', $value), 2);
} }
} }

View File

@ -26,6 +26,7 @@ use OCP\AppFramework\QueryException;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\WorkflowEngine\ICheck; use OCP\WorkflowEngine\ICheck;
use OCP\WorkflowEngine\IManager; use OCP\WorkflowEngine\IManager;
@ -50,13 +51,18 @@ class Manager implements IManager {
/** @var IServerContainer|\OC\Server */ /** @var IServerContainer|\OC\Server */
protected $container; protected $container;
/** @var IL10N */
protected $l;
/** /**
* @param IDBConnection $connection * @param IDBConnection $connection
* @param IServerContainer $container * @param IServerContainer $container
* @param IL10N $l
*/ */
public function __construct(IDBConnection $connection, IServerContainer $container) { public function __construct(IDBConnection $connection, IServerContainer $container, IL10N $l) {
$this->connection = $connection; $this->connection = $connection;
$this->container = $container; $this->container = $container;
$this->l = $l;
} }
/** /**
@ -111,7 +117,7 @@ class Manager implements IManager {
return $checkInstance->executeCheck($check['operator'], $check['value']); return $checkInstance->executeCheck($check['operator'], $check['value']);
} else { } else {
// Check is invalid // Check is invalid
throw new \RuntimeException('Check ' . htmlspecialchars($check['class']) . ' is invalid or does not exist'); throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class']));
} }
} }
@ -158,7 +164,7 @@ class Manager implements IManager {
return $row; return $row;
} }
throw new \UnexpectedValueException('Operation does not exist'); throw new \UnexpectedValueException($this->l->t('Operation #%s does not exist', $id));
} }
/** /**
@ -262,7 +268,7 @@ class Manager implements IManager {
if (!empty($checkIds)) { if (!empty($checkIds)) {
$missingCheck = array_pop($checkIds); $missingCheck = array_pop($checkIds);
throw new \RuntimeException('Check #' . htmlspecialchars($missingCheck) . ' is invalid or does not exist'); throw new \UnexpectedValueException($this->l->t('Check #%s does not exist', $missingCheck));
} }
return $checks; return $checks;

View File

@ -20,13 +20,13 @@
*/ */
/** @var array $_ */ /** @var array $_ */
/** @var OC_L10N $l */ /** @var \OCP\IL10N $l */
?> ?>
<div id="<?php p($_['appid']); ?>" class="section workflowengine"> <div id="<?php p($_['appid']); ?>" class="section workflowengine">
<h2 class="inlineblock"><?php p($_['heading']); ?></h2> <h2 class="inlineblock"><?php p($_['heading']); ?></h2>
<script type="text/template" id="operations-template"> <script type="text/template" id="operations-template">
<div class="operations"></div> <div class="operations"></div>
<button class="button-add-operation">Add operation</button> <button class="button-add-operation"><?php p($l->t('Add operation')); ?></button>
</script> </script>
<script type="text/template" id="operation-template"> <script type="text/template" id="operation-template">
@ -56,17 +56,17 @@
</div> </div>
{{/each}} {{/each}}
</div> </div>
<button class="button-add">Add check</button> <button class="button-add"><?php p($l->t('Add check')); ?></button>
{{#if hasChanged}} {{#if hasChanged}}
{{! reset only makes sense if the operation is already saved }} {{! reset only makes sense if the operation is already saved }}
{{#if operation.id}} {{#if operation.id}}
<button class="button-reset pull-right">Reset</button> <button class="button-reset pull-right"><?php p($l->t('Reset')); ?></button>
{{/if}} {{/if}}
<button class="button-save pull-right">Save</button> <button class="button-save pull-right"><?php p($l->t('Save')); ?></button>
{{/if}} {{/if}}
{{#if saving}} {{#if saving}}
<span class="icon-loading-small pull-right"></span> <span class="icon-loading-small pull-right"></span>
<span class="pull-right">Saving ...</span> <span class="pull-right"><?php p($l->t('Saving…')); ?></span>
{{else}}{{#if message}} {{else}}{{#if message}}
<span class="msg pull-right {{#if errorMessage}}error{{else}}success{{/if}}"> <span class="msg pull-right {{#if errorMessage}}error{{else}}success{{/if}}">
{{message}}{{#if errorMessage}} {{errorMessage}}{{/if}} {{message}}{{#if errorMessage}} {{errorMessage}}{{/if}}
@ -75,5 +75,5 @@
</div> </div>
</script> </script>
<div class="rules"><span class="icon-loading-small"></span> Loading ...</div> <div class="rules"><span class="icon-loading-small"></span> <?php p($l->t('Loading…')); ?></div>
</div> </div>