diff --git a/metatag.inc b/metatag.inc index 385fe6d..b7788c6 100644 --- a/metatag.inc +++ b/metatag.inc @@ -221,7 +221,7 @@ class DrupalTextMetaTag extends DrupalDefaultMetaTag { $name = "metatag:" . $options["instance"] . ":" . $this->info["name"]; - $value = metatag_translate($name, $this->data['value']); + $value = metatag_translate($this->data['value'], $name); if (empty($options['raw'])) { // Give other modules the opportunity to use hook_metatag_pattern_alter() // to modify defined token patterns and values before replacement. diff --git a/metatag.module b/metatag.module index 4c2dc0c..b083771 100644 --- a/metatag.module +++ b/metatag.module @@ -329,7 +329,7 @@ function metatag_config_save($config) { // hook_metatag_config_presave(). module_invoke_all('metatag_config_presave', $config); - // Update the i18n string + // Update the i18n string. if (function_exists('i18n_string_update')) { $instance = $config->instance; @@ -2228,14 +2228,22 @@ function metatag_entity_translation_delete($entity_type, $entity, $langcode) { /** * Translates the metatag if i18n_string is enabled. - * @param $name - * Array or string concatenated with ':' that contains textgroup and string context + * * @param string $string - * String in default language or array of strings to be translated + * String in default language or array of strings to be translated. + * @param $name + * Array or string concatenated with ':' that contains textgroup and string + * context. * @param $options - * An associative array of additional options. @see i18n_string_translate() + * An associative array of additional options. + * + * @return string + * The translated string if i18n_string is enabled, otherwise the original + * string again. + * + * @see i18n_string_translate() */ -function metatag_translate($name, $string, $langcode = NULL, $update = FALSE) { +function metatag_translate($string, $name, $langcode = NULL, $update = FALSE) { if (function_exists('i18n_string_translate')) { $options = array( 'langcode' => $langcode, @@ -2249,6 +2257,49 @@ function metatag_translate($name, $string, $langcode = NULL, $update = FALSE) { } /** + * Translate a set of metatags to the current language. + * + * @param array $metatags + * List of meta tags to be translated. + */ +function MetatagViews&$metatags) { + global $language; + + if (!empty($metatags[LANGUAGE_NONE])) { + $translated_metatags = array(); + foreach ($metatags[LANGUAGE_NONE] as $key => $data) { + if (!empty($data['value']) && is_string($data['value'])) { + $name = "metatag:" . $key; + $translated_metatags[$key] = array( + 'value' => metatag_translate($data['value'], $name), + ); + } + } + $metatags[$language->language] = $translated_metatags; + } +} + +/** + * Update the translated definitions of meta tags. + * + * @param array $metatags + * List of meta tags to have their translations updated. + */ +function metatag_update_translations(&$metatags) { + global $language; + + // Update the i18n string. + if (function_exists('i18n_string_update')) { + foreach ($metatags as $key => $data) { + if (!empty($data['value']) && is_string($data['value'])) { + $name = 'metatag:' . $key; + i18n_string_update($name, $data['value']); + } + } + } +} + +/** * Checks if this entity is the default revision (published). * * @param object $entity diff --git a/metatag_context/metatag_context.admin.inc b/metatag_context/metatag_context.admin.inc index 2ca07ce..2c80774 100644 --- a/metatag_context/metatag_context.admin.inc +++ b/metatag_context/metatag_context.admin.inc @@ -85,6 +85,10 @@ function metatag_context_config_add_form_submit($form, &$form_state) { $context = metatag_context_load_default_context(); $context->name = $form_state['values']['name']; context_save($context); + + // Update the i18n strings. + metatag_update_translations($context->reactions['metatag_context_reaction']['metatags']); + $form_state['redirect'] = 'admin/config/search/metatags/context/' . $context->name; } @@ -175,6 +179,10 @@ function metatag_context_config_edit_form_submit($form, &$form_state) { $paths = array_combine($paths, $paths); $context->conditions['path']['values'] = $paths; context_save($context); + + // Update the i18n strings. + metatag_update_translations($context->reactions['metatag_context_reaction']['metatags']); + $form_state['redirect'] = 'admin/config/search/metatags/context'; } diff --git a/metatag_context/metatag_context.context.inc b/metatag_context/metatag_context.context.inc index 15984fb..a8808f0 100644 --- a/metatag_context/metatag_context.context.inc +++ b/metatag_context/metatag_context.context.inc @@ -112,9 +112,14 @@ class metatag_context_reaction extends context_reaction { if (isset($metadata_array[LANGUAGE_NONE])) { $metadata_array = $metadata_array[LANGUAGE_NONE]; } - foreach ($metadata_array as $key => $data) { - if (!empty($data['value'])) { - $metatags[$key] = $data;//t(check_plain($data['value'])); + + // Translate all of the meta tags using i18n. + MetatagViews$metadata_array); + + // Add the meta tags to the output. + foreach ($metadata_array as $langcode => $tags) { + foreach ($tags as $name => $value) { + $metatags[$langcode][$name] = $value; } } diff --git a/metatag_context/metatag_context.test b/metatag_context/metatag_context.test index 234a87e..d641fa6 100644 --- a/metatag_context/metatag_context.test +++ b/metatag_context/metatag_context.test @@ -7,7 +7,7 @@ /** * This extends the basic Metatag test class to reduce code duplication. */ -class MetatagContextTestCase extends MetatagTestHelper { +class MetatagContextTest extends MetatagTestHelper { /** * The getInfo() method provides information about the test. * In order for the test to be run, the getInfo() method needs @@ -15,8 +15,8 @@ class MetatagContextTestCase extends MetatagTestHelper { */ public static function getInfo() { return array( - 'name' => 'Meta tag context tests', - 'description' => 'Test basic meta tag context functionality.', + 'name' => 'Metatag:Context tests', + 'description' => 'Test basic Metatag:Context functionality.', 'group' => 'Metatag', ); } @@ -25,6 +25,7 @@ class MetatagContextTestCase extends MetatagTestHelper { * Prepares the testing environment */ public function setUp(array $modules = array()) { + $modules[] = 'context'; $modules[] = 'metatag_context'; parent::setUp($modules); @@ -32,8 +33,8 @@ class MetatagContextTestCase extends MetatagTestHelper { $perms = array( 'bypass node access', ); - $this->privileged_user = $this->createAdminUser($perms); - $this->drupalLogin($this->privileged_user); + $this->adminUser = $this->createAdminUser($perms); + $this->drupalLogin($this->adminUser); // Create a content type, with underscores. $type_name = strtolower($this->randomName(8)) . '_test'; @@ -57,6 +58,7 @@ class MetatagContextTestCase extends MetatagTestHelper { $this->metatag_pages['page'] = $this->createMetatagObject('', 'frontpage_metatags'); foreach ($this->metatag_pages as $page) { $this->generateMetatag($page); + $this->editMetatag($page); $this->checkMetatags($page); } @@ -65,7 +67,6 @@ class MetatagContextTestCase extends MetatagTestHelper { $this->metatag_pages['node']->description = ''; $this->editMetatag($this->metatag_pages['node']); $this->checkMetatags($this->metatag_pages['node']); - } /** @@ -99,12 +100,22 @@ class MetatagContextTestCase extends MetatagTestHelper { * Metatag mapping object. */ function generateMetatag($metatag_object) { - // Add new Metatag object by path. - $edit = array( + // Verify the "add context" page works. + $this->drupalGet('admin/config/search/metatags/context'); + $this->assertResponse(200); + $this->assertText(t('Add a meta tag by path')); + + // Verify the "add context" page works. + $this->drupalGet('admin/config/search/metatags/context/add'); + $this->assertResponse(200); + $this->assertText(t('The unique ID for this metatag path context rule. This must contain only lower case letters, numbers and underscores.')); + + // Add new Metatag object for this configuration. + $values = array( 'name' => $metatag_object->name, ); - $this->drupalPost('admin/config/search/metatags/context/add', $edit, t('Add and configure')); - $this->editMetatag($metatag_object); + + $this->drupalPost('admin/config/search/metatags/context/add', $values, t('Add and configure')); } /** diff --git a/metatag_panels/metatag_panels.module b/metatag_panels/metatag_panels.module index b65daf6..42cc47d 100644 --- a/metatag_panels/metatag_panels.module +++ b/metatag_panels/metatag_panels.module @@ -115,6 +115,9 @@ function metatag_panels_form_submit($form, $form_state) { 'metatags' => $form_state['values']['metatags'][LANGUAGE_NONE], ); + // Update the i18n strings. + metatag_update_translations($conf['metatags']); + $form_state['handler']->conf['metatag_panels'] = $conf; } @@ -141,6 +144,9 @@ function metatag_panels_ctools_render_alter($info, $page, $context) { $metatags = array(LANGUAGE_NONE => $metatags); } + // Translate all of the meta tags using i18n. + MetatagViews$metatags); + // Append global defaults. $all_metatags = array(); foreach ($metatags as $langcode => $values) { diff --git a/metatag_views/metatag_views.metatag.inc b/metatag_views/metatag_views.metatag.inc index 8eee9d4..923e6cd 100644 --- a/metatag_views/metatag_views.metatag.inc +++ b/metatag_views/metatag_views.metatag.inc @@ -1,7 +1,7 @@ name; + + // Include display name if option is overridden. + if (!$view->display_handler->is_defaulted('metatags')) { + $instance = 'view:' . $view->name . ':' . $view->current_display; + } + // Load the meta tags for this view. $metatags = $view->display_handler->get_option('metatags'); if (!is_array($metatags) || empty($metatags)) { @@ -92,10 +102,13 @@ function metatag_views_page_alter(&$page) { $metatags = array(LANGUAGE_NONE => $metatags); } + // Translate all of the meta tags using i18n. + MetatagViews$metatags); + // Build options for meta tag rendering. - $instance = 'view:' . $view->name; $options = array(); $options['token data']['view'] = $view; + $options['language'] = $language->language; // The page region can be changed. $region = variable_get('metatag_page_region', 'content'); diff --git a/metatag_views/metatag_views_plugin_display_extender_metatags.inc b/metatag_views/metatag_views_plugin_display_extender_metatags.inc index 4a5d96d..b134627 100644 --- a/metatag_views/metatag_views_plugin_display_extender_metatags.inc +++ b/metatag_views/metatag_views_plugin_display_extender_metatags.inc @@ -66,6 +66,19 @@ class metatag_views_plugin_display_extender_metatags extends views_plugin_displa } $this->display->set_option('metatags', $metatags); + + if ($this->definition['enabled'] && function_exists('i18n_string_update')) { + // Include only view name by default. + $instance = 'view:' . $this->view->name; + + // Include display name if option is overridden. + if (!$this->display->is_defaulted('metatags')) { + $instance = 'view:' . $this->view->name . ':' . $this->view->current_display; + } + + // Update the i18n strings. + metatag_update_translations($metatags[LANGUAGE_NONE]); + } } }