Skip to content
Snippets Groups Projects
Commit 3827f492 authored by Jared Hancock's avatar Jared Hancock
Browse files

i18n: Make roles translatable

parent 846d8231
No related branches found
No related tags found
No related merge requests found
...@@ -89,6 +89,15 @@ class Role extends RoleModel { ...@@ -89,6 +89,15 @@ class Role extends RoleModel {
return $this->getPermission()->getInfo(); return $this->getPermission()->getInfo();
} }
function getTranslateTag($subtag) {
return _H(sprintf('role.%s.%s', $subtag, $this->getId()));
}
function getLocal($subtag) {
$tag = $this->getTranslateTag($subtag);
$T = CustomDataTranslation::translate($tag);
return $T != $tag ? $T : $this->ht[$subtag];
}
function to_json() { function to_json() {
$info = array( $info = array(
...@@ -191,20 +200,19 @@ class Role extends RoleModel { ...@@ -191,20 +200,19 @@ class Role extends RoleModel {
return $role; return $role;
} }
static function getRoles($criteria=null) { static function getRoles($criteria=null, $localize=true) {
static $roles = null; static $roles = null;
if (!isset($roles) || $criteria) { if (!isset($roles) || $criteria) {
$filters = array(); $filters = array();
if (isset($criteria['enabled'])) { if (isset($criteria['enabled'])) {
if ($criteria['enabled']) $q = new Q(array('flags__hasbit' => self::FLAG_ENABLED));
$filters += array( if (!$criteria['enabled'])
'flags__hasbit' => self::FLAG_ENABLED); $q->negate();
else $filters[] = $q;
$filters [] = Q::not(array(
'flags__hasbit' => self::FLAG_ENABLED));
} }
$query = self::objects() $query = self::objects()
->order_by('name') ->order_by('name')
->values_flat('id', 'name'); ->values_flat('id', 'name');
...@@ -212,13 +220,20 @@ class Role extends RoleModel { ...@@ -212,13 +220,20 @@ class Role extends RoleModel {
if ($filters) if ($filters)
$query->filter($filters); $query->filter($filters);
$localize_this = function($id, $default) use ($localize) {
if (!$localize)
return $default;
$tag = _H("role.name.{$id}");
$T = CustomDataTranslation::translate($tag);
return $T != $tag ? $T : $default;
};
$names = array(); $names = array();
foreach ($query as $row) foreach ($query as $row)
$names[$row[0]] = $row[1]; $names[$row[0]] = $localize_this($row[0], $row[1]);
// TODO: Localize
if ($criteria) return $names; if ($criteria || !$localize)
return $names;
$roles = $names; $roles = $names;
} }
......
...@@ -296,15 +296,6 @@ class Topic extends VerySimpleModel { ...@@ -296,15 +296,6 @@ class Topic extends VerySimpleModel {
return $T != $tag ? $T : $default; return $T != $tag ? $T : $default;
}; };
$localize_this = function($id, $default) use ($localize) {
if (!$localize)
return $default;
$tag = _H("topic.name.{$id}");
$T = CustomDataTranslation::translate($tag);
return $T != $tag ? $T : $default;
};
// Resolve parent names // Resolve parent names
foreach ($topics as $id=>$info) { foreach ($topics as $id=>$info) {
$name = $localize_this($id, $info['topic']); $name = $localize_this($id, $info['topic']);
......
...@@ -6,6 +6,7 @@ if ($role) { ...@@ -6,6 +6,7 @@ if ($role) {
$action = 'update'; $action = 'update';
$submit_text = __('Save Changes'); $submit_text = __('Save Changes');
$info = $role->getInfo(); $info = $role->getInfo();
$trans['name'] = $role->getTranslateTag('name');
$newcount=2; $newcount=2;
} else { } else {
$title = __('Add New Role'); $title = __('Add New Role');
...@@ -48,7 +49,7 @@ $info = Format::htmlchars(($errors && $_POST) ? array_merge($info, $_POST) : $in ...@@ -48,7 +49,7 @@ $info = Format::htmlchars(($errors && $_POST) ? array_merge($info, $_POST) : $in
<td width="180" class="required"><?php echo __('Name'); ?>:</td> <td width="180" class="required"><?php echo __('Name'); ?>:</td>
<td> <td>
<input size="50" type="text" name="name" value="<?php echo <input size="50" type="text" name="name" value="<?php echo
$info['name']; ?>"/> $info['name']; ?>" data-translate-tag="<?php echo $trans['name']; ?>"/>
<span class="error">*&nbsp;<?php echo $errors['name']; ?></span> <span class="error">*&nbsp;<?php echo $errors['name']; ?></span>
</td> </td>
</tr> </tr>
......
...@@ -51,7 +51,7 @@ $showing=$pageNav->showing().' '._N('role', 'roles', $count); ...@@ -51,7 +51,7 @@ $showing=$pageNav->showing().' '._N('role', 'roles', $count);
?> ?>
</td> </td>
<td><a href="?id=<?php echo $id; ?>"><?php echo <td><a href="?id=<?php echo $id; ?>"><?php echo
$role->getName(); ?></a></td> $role->getLocal('name'); ?></a></td>
<td>&nbsp;<?php echo $role->isEnabled() ? __('Active') : <td>&nbsp;<?php echo $role->isEnabled() ? __('Active') :
'<b>'.__('Disabled').'</b>'; ?></td> '<b>'.__('Disabled').'</b>'; ?></td>
<td><?php echo Format::date($role->getCreateDate()); ?></td> <td><?php echo Format::date($role->getCreateDate()); ?></td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment