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 {
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() {
$info = array(
......@@ -191,20 +200,19 @@ class Role extends RoleModel {
return $role;
}
static function getRoles($criteria=null) {
static function getRoles($criteria=null, $localize=true) {
static $roles = null;
if (!isset($roles) || $criteria) {
$filters = array();
if (isset($criteria['enabled'])) {
if ($criteria['enabled'])
$filters += array(
'flags__hasbit' => self::FLAG_ENABLED);
else
$filters [] = Q::not(array(
'flags__hasbit' => self::FLAG_ENABLED));
$q = new Q(array('flags__hasbit' => self::FLAG_ENABLED));
if (!$criteria['enabled'])
$q->negate();
$filters[] = $q;
}
$query = self::objects()
->order_by('name')
->values_flat('id', 'name');
......@@ -212,13 +220,20 @@ class Role extends RoleModel {
if ($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();
foreach ($query as $row)
$names[$row[0]] = $row[1];
// TODO: Localize
$names[$row[0]] = $localize_this($row[0], $row[1]);
if ($criteria) return $names;
if ($criteria || !$localize)
return $names;
$roles = $names;
}
......
......@@ -296,15 +296,6 @@ class Topic extends VerySimpleModel {
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
foreach ($topics as $id=>$info) {
$name = $localize_this($id, $info['topic']);
......
......@@ -6,6 +6,7 @@ if ($role) {
$action = 'update';
$submit_text = __('Save Changes');
$info = $role->getInfo();
$trans['name'] = $role->getTranslateTag('name');
$newcount=2;
} else {
$title = __('Add New Role');
......@@ -48,7 +49,7 @@ $info = Format::htmlchars(($errors && $_POST) ? array_merge($info, $_POST) : $in
<td width="180" class="required"><?php echo __('Name'); ?>:</td>
<td>
<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>
</td>
</tr>
......
......@@ -51,7 +51,7 @@ $showing=$pageNav->showing().' '._N('role', 'roles', $count);
?>
</td>
<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') :
'<b>'.__('Disabled').'</b>'; ?></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