diff --git a/metatag.inc b/metatag.inc index d2f9aac..0466bea 100644 --- a/metatag.inc +++ b/metatag.inc @@ -94,6 +94,8 @@ class DrupalTextMetaTag extends DrupalDefaultMetaTag { } public function getValue(array $options = array()) { + $name = "metatag:" . $options["instance"] . ":" . $this->info["name"]; + $options += array( 'token data' => array(), 'clear' => TRUE, @@ -101,8 +103,11 @@ class DrupalTextMetaTag extends DrupalDefaultMetaTag { 'raw' => FALSE, ); - $value = $this->data['value']; + $value = metatag_translate($name, $this->data['value']); if (empty($options['raw'])) { + // Give other modules the opportunity to use hook_metatag_pattern_alter() + // to modify defined token patterns and values before replacement. + drupal_alter('metatag_pattern', $value, $options['token data']); $value = token_replace($value, $options['token data'], $options); } $value = strip_tags(decode_entities($value)); diff --git a/metatag.module b/metatag.module index 6f0a493..5c9a250 100644 --- a/metatag.module +++ b/metatag.module @@ -254,6 +254,16 @@ function metatag_config_save($config) { // Allow modules to alter the configuration before it is saved using // hook_metatag_config_presave(). module_invoke_all('metatag_config_presave', $config); + + // Update the i18n string + if (function_exists('i18n_string_update')) { + $instance = $config->instance; + + foreach ($config->config as $field => $item) { + $name = "metatag:" . $instance . ":" . $field; + i18n_string_update($name, $item['value']); + } + } if ($config->is_new) { drupal_write_record('metatag_config', $config); @@ -752,7 +762,9 @@ function metatag_metatags_view($instance, array $metatags = array(), array $opti // Add any default tags to the mix. $metatags += metatag_config_load_with_defaults($instance); - + + $options['instance'] = $instance; + foreach ($metatags as $metatag => $data) { if ($metatag_instance = metatag_get_instance($metatag, $data)) { $output[$metatag] = $metatag_instance->getElement($options); @@ -781,7 +793,7 @@ function metatag_metatags_values($instance, array $metatags = array(), array $op // Convert language codes to a language object. $languages = language_list(); $options['language'] = isset($languages[$language]) ? $languages[$language] : NULL; - + $options['instance'] = $instance; // Get output elements. foreach ($metatags[$language] as $metatag => $data) { if ($metatag_instance = metatag_get_instance($metatag, $data)) { @@ -816,6 +828,7 @@ function metatag_metatags_form(array &$form, $instance, array $metatags = array( $options += array( 'token types' => array(), 'defaults' => metatag_config_load_with_defaults($instance), + 'instance' => $instance, ); $form['metatags'] = array( @@ -1262,7 +1275,9 @@ function metatag_field_attach_form($entity_type, $entity, &$form, &$form_state, $options['token types'] = array(token_get_entity_mapping('entity', $entity_type)); $options['context'] = $entity_type; - + // Allow hook_metatag_token_types_alter() to modify the defined tokens. + drupal_alter('metatag_token_types', $options); + // @todo Remove metatag_form_alter() when http://drupal.org/node/1284642 is fixed in core. //metatag_metatags_form($form, $instance, $metatags, $options); @@ -1369,6 +1384,7 @@ function metatag_get_instance($metatag, array $data = array()) { function metatag_get_value($metatag, array $data, array $options = array()) { $value = ''; if ($metatag_instance = metatag_get_instance($metatag, $data)) { + $options["instance"] = $metatag; $value = $metatag_instance->getValue($options); } return $value; @@ -1726,3 +1742,25 @@ function metatag_entity_translation_delete($entity_type, $entity, $langcode) { // Delete the translation. metatag_metatags_delete($entity_type, $entity_id, $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 + * @param $options + * An associative array of additional options. @see i18n_string_translate() + */ +function metatag_translate($name, $string, $langcode = NULL, $update = FALSE) { + if (function_exists('i18n_string')) { + $options = array( + 'langcode' => $langcode, + 'update' => $update, + ); + return i18n_string_translate($name, $string, $options); + } + else { + return $string; + } +}