added string and field translation table for translators

This commit is contained in:
Bachir Soussi Chiadmi
2016-12-20 00:17:50 +01:00
parent abbcb19838
commit ddc28956c4
7 changed files with 235 additions and 154 deletions

View File

@@ -41,6 +41,6 @@ function materio_translator_install() {
/**
* Implements hook_uninstall().
*/
function materio_translator_uninstall() {
variable_del('i18n_access_languages');
}
// function materio_translator_uninstall() {
// variable_del('materio_translator_languages');
// }

View File

@@ -106,6 +106,42 @@ function materio_translator_permission() {
'description' => t('administer user translation language access'),
'restrict access' => TRUE,
),
'access_translations_overview' => array(
'title' => t('Access translations overview')
),
'access_translation_table_fields' => array(
'title' => t('Access translation Fields table')
),
'access_translation_table_content_type' => array(
'title' => t('Access translation Content types table')
),
'access_translation_table_menu' => array(
'title' => t('Access translation menu table')
),
'access_translation_table_taxonomy' => array(
'title' => t('Access translation taxonomy table')
),
'translate_strings' => array(
'title' => t('Translate strings')
),
'delete_strings' => array(
'title' => t('Delete strings')
),
'refresh_strings' => array(
'title' => t('Refresh strings')
),
'import_translations' => array(
'title' => t('Import translations')
),
'export_translations' => array(
'title' => t('Import translations')
),
'update_modules_translations' => array(
'title' => t('Update modules translations')
),
);
}
@@ -113,25 +149,63 @@ function materio_translator_permission() {
* Implements hook_form_alter().
*/
function materio_translator_form_alter(&$form, &$form_state, $form_id) {
// Add materio_translator things to user/edit /user/add
if ($form_id == 'user_register_form' || $form_id == 'user_profile_form' ) {
// dsm($form_id, 'form_id');
// dsm($form, 'form');
// dsm($form_state, 'form_state');
// dsm($form_id);
$form['materio_translator'] = array(
'#type' => 'fieldset',
'#title' => t('Translation access'),
'#tree' => 0,
'#access' => user_access('administer user translation language access'),
);
$form['materio_translator']['materio_translator'] = array(
'#type' => 'checkboxes',
'#options' => array(LANGUAGE_NONE => t('Language neutral')) + locale_language_list('name'),
'#default_value' => materio_translator_load_permissions($form['#user']->uid),
'#description' => t('The user get edit, delete access to all content which are in this enabled languages. Create, view access needs a different access level.'),
);
// Add materio_translator things to user/edit /user/add
if ($form_id == 'user_register_form' || $form_id == 'user_profile_form' ) {
// dsm($form_id, 'form_id');
// dsm($form, 'form');
// dsm($form_state, 'form_state');
$form['materio_translator'] = array(
'#type' => 'fieldset',
'#title' => t('Translation access'),
'#tree' => 0,
'#access' => user_access('administer user translation language access'),
);
$form['materio_translator']['materio_translator'] = array(
'#type' => 'checkboxes',
'#options' => array(LANGUAGE_NONE => t('Language neutral')) + locale_language_list('name'),
'#default_value' => materio_translator_load_permissions($form['#user']->uid),
'#description' => t('The user get edit, delete access to all content which are in this enabled languages. Create, view access needs a different access level.'),
);
}
// limit fields in string translation
if($form_id == 'i18n_string_locale_translate_edit_form'){
// dsm($form, 'form');
// dsm($form_state, 'form_state');
global $user;
$perms = materio_translator_load_permissions($user->uid);
// dsm($perms);
foreach ($form['translations'] as $langcode => $item) {
// disable field if langcode not in perms
if(!in_array($langcode, $perms) && isset($form['translations'][$langcode])){
$form['translations'][$langcode]['#disabled'] = true;
}
}
}
// limit fields in string translation
if($form_id == 'field_translation_table_form'
|| $form_id == "node_translation_table_nodetype_form"
|| $form_id == "menu_translation_table_menu_form"
|| $form_id == "taxonomy_translation_table_taxonomy_form"){
// dsm($form, 'form');
// dsm($form_state, 'form_state');
global $user;
$perms = materio_translator_load_permissions($user->uid);
// dsm($perms);
foreach ($form['filtered_form']['strings'] as $id => $row) {
foreach ($row as $langcode => $field) {
// disable field if langcode not in perms
if(!in_array($langcode, $perms)){
$form['filtered_form']['strings'][$id][$langcode]['#disabled'] = true;
}
}
}
}
}
/**
@@ -224,10 +298,45 @@ function materio_translator_menu_alter(&$items) {
}
// translation add link
if(preg_match('/^node\/%node\/edit\/add\/%entity_translation_language/', $path)){
// if(preg_match('/^node\/%node\/edit\/add\/%entity_translation_language/', $path)){
// dsm($item, $path);
// }
// translation add link
if(preg_match('/admin\/config\/regional\/translate/', $path)){
$items[$path]['access arguments'] = array('access_translations_overview');
}
if(preg_match('/admin\/config\/regional\/translate\/table/', $path)){
$items[$path]['access arguments'] = array('access_translation_table_fields');
}
if(preg_match('/admin\/config\/regional\/translate\/table\/nodetype/', $path)){
$items[$path]['access arguments'] = array('access_translation_table_content_type');
}
if(preg_match('/admin\/config\/regional\/translate\/table\/menu/', $path)){
$items[$path]['access arguments'] = array('access_translation_table_menu');
}
if(preg_match('/admin\/config\/regional\/translate\/table\/taxonomy/', $path)){
$items[$path]['access arguments'] = array('access_translation_table_taxonomy');
}
if(preg_match('/admin\/config\/regional\/translate\/translate/', $path)){
$items[$path]['access arguments'] = array('translate_strings');
}
if(preg_match('/admin\/config\/regional\/translate\/import/', $path)){
$items[$path]['access arguments'] = array('import_translations');
}
if(preg_match('/admin\/config\/regional\/translate\/i18n_string/', $path)){
$items[$path]['access arguments'] = array('refresh_strings');
}
if(preg_match('/admin\/config\/regional\/translate\/update/', $path)){
$items[$path]['access arguments'] = array('update_modules_translations');
}
if(preg_match('/admin\/config\/regional\/translate\/export/', $path)){
$items[$path]['access arguments'] = array('export_translations');
}
if(preg_match('/admin\/config\/regional\/translate\/delete/', $path)){
$items[$path]['access arguments'] += array("delete_strings");
}
}
}
@@ -430,7 +539,7 @@ function _materio_translator_form_node_form_alter($form, &$form_state) {
function materio_translator_node_tab_access(){
$args = func_get_args();
dsm($args, '1 -- materio_translator_node_tab_access args');
// dsm($args, '1 -- materio_translator_node_tab_access args');
// dsm($entity_type, "entity_type");
// dsm($entity, "entity");

View File

@@ -1,29 +0,0 @@
name = Translate Perms
description = "The description of this module"
; Core version (required)
core = 7.x
; Package name (see http://drupal.org/node/542202 for a list of names)
; package =
; PHP version requirement (optional)
; php = 5.2
; Loadable code files
; files[] = translate_perms.module
; files[] = translate_perms.admin.inc
; files[] = translate_perms.class.inc
; Module dependencies
; dependencies[] = mymodule
; dependencies[] = theirmodule (1.2)
; dependencies[] = anothermodule (>=2.4)
; dependencies[] = views (3.x)
; Configuration page
; configure = admin/config/translate_perms
; For further information about configuration options, see
; - http://drupal.org/node/542202

View File

@@ -1,92 +0,0 @@
<?php
/**
* @file
* This is the file description for Translate Perms module.
*
* In this more verbose, multi-line description, you can specify what this
* file does exactly. Make sure to wrap your documentation in column 78 so
* that the file can be displayed nicely in default-sized consoles.
*/
/**
* Implements hook_permission().
*/
function translate_perms_permission() {
return array(
'access_translations_overview' => array(
'title' => t('Access translations overview')
),
'access_translation_table_fields' => array(
'title' => t('Access translation Fields table')
),
'access_translation_table_content_type' => array(
'title' => t('Access translation Content types table')
),
'access_translation_table_menu' => array(
'title' => t('Access translation menu table')
),
'access_translation_table_taxonomy' => array(
'title' => t('Access translation taxonomy table')
),
'translate_strings' => array(
'title' => t('Translate strings')
),
'import_translations' => array(
'title' => t('Import translations')
),
'refresh_strings' => array(
'title' => t('Refresh strings')
),
'update_modules_translations' => array(
'title' => t('Update modules translations')
),
'export_translations' => array(
'title' => t('Import translations')
),
);
}
/**
* Implements hook_menu_alter().
*/
function translate_perms_menu_alter(&$items) {
if(isset($items['admin/config/regional/translate']))
$items['admin/config/regional/translate']['access arguments'] = array('access_translations_overview');
if(isset($items['admin/config/regional/translate/table']))
$items['admin/config/regional/translate/table']['access arguments'] = array('access_translation_table_fields');
if(isset($items['admin/config/regional/translate/table/nodetype']))
$items['admin/config/regional/translate/table/nodetype']['access arguments'] = array('access_translation_table_content_type');
if(isset($items['admin/config/regional/translate/table/menu']))
$items['admin/config/regional/translate/table/menu']['access arguments'] = array('access_translation_table_menu');
if(isset($items['admin/config/regional/translate/table/taxonomy']))
$items['admin/config/regional/translate/table/taxonomy']['access arguments'] = array('access_translation_table_taxonomy');
if(isset($items['admin/config/regional/translate/translate']))
$items['admin/config/regional/translate/translate']['access arguments'] = array('translate_strings');
if(isset($items['admin/config/regional/translate/import']))
$items['admin/config/regional/translate/import']['access arguments'] = array('import_translations');
if(isset($items['admin/config/regional/translate/i18n_string']))
$items['admin/config/regional/translate/i18n_string']['access arguments'] = array('refresh_strings');
if(isset($items['admin/config/regional/translate/update']))
$items['admin/config/regional/translate/update']['access arguments'] = array('update_modules_translations');
if(isset($items['admin/config/regional/translate/export']))
$items['admin/config/regional/translate/export']['access arguments'] = array('export_translations');
}