first import
This commit is contained in:
57
sites/all/modules/i18n/i18n_contact/i18n_contact.i18n.inc
Normal file
57
sites/all/modules/i18n/i18n_contact/i18n_contact.i18n.inc
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Internationalization (i18n) hooks
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_i18n_string_info().
|
||||
*/
|
||||
function i18n_contact_i18n_string_info() {
|
||||
$groups['contact'] = array(
|
||||
'title' => t('Contact forms'),
|
||||
'description' => t('Configurable contact form categories.'),
|
||||
'format' => FALSE,
|
||||
'list' => TRUE,
|
||||
);
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_i18n_object_info().
|
||||
*/
|
||||
function i18n_contact_i18n_object_info() {
|
||||
$info['contact_category'] = array(
|
||||
// Generic object title.
|
||||
'title' => t('Contact category'),
|
||||
// The object key field.
|
||||
'key' => 'cid',
|
||||
// The object load callback.
|
||||
'load callback' => 'contact_load',
|
||||
// Placeholders for automatic paths.
|
||||
'placeholders' => array(
|
||||
'%contact' => 'cid',
|
||||
),
|
||||
// To produce edit links automatically.
|
||||
'edit path' => 'admin/structure/contact/edit/%contact',
|
||||
// Auto-generate translate tab.
|
||||
'translate tab' => 'admin/structure/contact/edit/%contact/translate',
|
||||
// Properties for string translation.
|
||||
'string translation' => array(
|
||||
// Text group that will handle this object's strings.
|
||||
'textgroup' => 'contact',
|
||||
// Object type property for string translation.
|
||||
'type' => 'category',
|
||||
// Table where the object is stored, to automate string lists
|
||||
'table' => 'contact',
|
||||
// Translatable properties of these objects.
|
||||
'properties' => array(
|
||||
'category' => t('Category'),
|
||||
'reply' => t('Auto-reply'),
|
||||
),
|
||||
// Path to translate strings to every language.
|
||||
'translate path' => 'admin/structure/contact/edit/%contact/translate/%i18n_language',
|
||||
)
|
||||
);
|
||||
return $info;
|
||||
}
|
13
sites/all/modules/i18n/i18n_contact/i18n_contact.info
Normal file
13
sites/all/modules/i18n/i18n_contact/i18n_contact.info
Normal file
@@ -0,0 +1,13 @@
|
||||
name = Contact translation
|
||||
description = Makes contact categories and replies available for translation.
|
||||
dependencies[] = contact
|
||||
dependencies[] = i18n_string
|
||||
package = Multilingual - Internationalization
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-01-13
|
||||
version = "7.x-1.8"
|
||||
core = "7.x"
|
||||
project = "i18n"
|
||||
datestamp = "1358075001"
|
||||
|
94
sites/all/modules/i18n/i18n_contact/i18n_contact.module
Normal file
94
sites/all/modules/i18n/i18n_contact/i18n_contact.module
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Internationalization (i18n) submodule: Multilingual contact forms
|
||||
*
|
||||
* @author Jose A. Reyero, 2005
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*
|
||||
* Add translate tab to contact config.
|
||||
*/
|
||||
function i18n_contact_menu() {
|
||||
$items['admin/structure/contact/edit/%contact/edit'] = array(
|
||||
'title' => 'Edit',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -100,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function i18n_contact_form_contact_category_delete_form_alter(&$form, &$form_state) {
|
||||
$form['#submit'][] = 'i18n_contact_form_contact_category_delete_form_submit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove strings for deleted categories.
|
||||
*/
|
||||
function i18n_contact_form_contact_category_delete_form_submit(&$form, $form_state) {
|
||||
i18n_string_object_remove('contact_category', $form['contact']['#value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function i18n_contact_form_contact_category_edit_form_alter(&$form, &$form_state) {
|
||||
$form['actions']['translate'] = array(
|
||||
'#type' => 'submit',
|
||||
'#name' => 'save_translate',
|
||||
'#value' => t('Save and translate'),
|
||||
);
|
||||
$form['#submit'][] = 'i18n_contact_form_contact_category_edit_form_submit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove strings for edited/added categories.
|
||||
*/
|
||||
function i18n_contact_form_contact_category_edit_form_submit($form, &$form_state) {
|
||||
$contact = $form_state['values'];
|
||||
i18n_string_object_update('contact_category', $contact);
|
||||
// If the save and translate button was clicked, redirect to the translate
|
||||
// tab instead of the block overview.
|
||||
if ($form_state['triggering_element']['#name'] == 'save_translate') {
|
||||
$form_state['redirect'] = 'admin/structure/contact/edit/' . $contact['cid'] . '/translate';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function i18n_contact_form_contact_site_form_alter(&$form, &$form_state) {
|
||||
// Example of array translation. The placeholder '*' indicates the name part to be replace by the array keys
|
||||
if (isset($form['cid']['#options'])) {
|
||||
$form['cid']['#options'] = i18n_string_translate("contact:category:*:category", $form['cid']['#options'], array('sanitize' => FALSE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_mail_alter().
|
||||
*/
|
||||
function i18n_contact_mail_alter(&$message) {
|
||||
if (in_array($message['id'], array('contact_page_mail', 'contact_page_copy', 'contact_page_autoreply'))) {
|
||||
// Alter the first part of the subject of emails going out if they need
|
||||
// translation.
|
||||
$contact = i18n_string_object_translate('contact_category', $message['params']['category'], array('langcode' => $message['language']->language));
|
||||
$message['subject'] = t(
|
||||
'[!category] !subject',
|
||||
array('!category' => $contact['category'], '!subject' => $message['params']['subject']),
|
||||
array('langcode' => $message['language']->language)
|
||||
);
|
||||
|
||||
if ($message['id'] == 'contact_page_autoreply') {
|
||||
// Overwrite the whole message body. Maybe this is not entirely responsible
|
||||
// (it might overwrite other existing items altered in by others),
|
||||
// but unfortunately Drupal core cotact module does not make its item
|
||||
// identifiable easily.
|
||||
$message['body'] = array($contact['reply']);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user