metatag_context.i18n.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) hooks.
  5. */
  6. /**
  7. * Implements hook_i18n_object_info().
  8. */
  9. function metatag_context_i18n_object_info() {
  10. $info['metatag_context'] = array(
  11. 'title' => t('Metatag:Context configurations'),
  12. // Callback to load all config objects.
  13. 'list callback' => 'metatag_context_i18n_list_contexts',
  14. // The object load callback.
  15. // 'load callback' => 'metatag_context_i18n_load',
  16. // @todo Custom i18n object overrides.
  17. // 'class' => 'metatag_context_i18n_metatag',
  18. // @todo Is this needed? What does it do?
  19. // 'translation set' => TRUE,
  20. // The object key field.
  21. 'key' => 'name',
  22. // Placeholders for automatic paths. This connects the 'key' to strings in
  23. // the paths listed below.
  24. // 'placeholders' => array(
  25. // '%name' => 'name',
  26. // ),
  27. // To produce edit links automatically.
  28. // 'edit path' => 'admin/config/search/metatags/config/%instance',
  29. // Auto-generate a 'translate' tab.
  30. // 'translate tab' => 'admin/config/search/metatags/config/%instance/translate',
  31. // Properties for string translation.
  32. 'string translation' => array(
  33. // The textgroup, type and (below) name will be concatenated into a single
  34. // string as the {locales_source} context.
  35. 'textgroup' => 'metatag',
  36. 'type' => 'metatag_context',
  37. // Table where the object is stored, to automate string lists.
  38. 'table' => 'context',
  39. // Translatable properties of these objects, this will be added later.
  40. 'properties' => array(),
  41. // The path to translate individual strings.
  42. // 'translate path' => 'admin/config/search/metatags/config/%instance/translate/%i18n_language',
  43. ),
  44. );
  45. // Compile all of the tags to add to the translation stack.
  46. $meta_tag_info = metatag_get_info();
  47. $groups = $meta_tag_info['groups'];
  48. foreach ($meta_tag_info['tags'] as $tag_info) {
  49. // Ignore certain field types that aren't translatable, mostly fields that
  50. // list predetermined options in various forms.
  51. if (!empty($tag_info['class']) && $tag_info['class'] == 'DrupalListMetaTag') {
  52. continue;
  53. }
  54. elseif (!empty($tag_info['form']['#type']) && $tag_info['form']['#type'] == 'select') {
  55. continue;
  56. }
  57. elseif (!empty($tag_info['form']['#options'])) {
  58. continue;
  59. }
  60. // Build a suitable structure for this meta tag.
  61. $tag_name = $tag_info['name'];
  62. $tag_group = $tag_info['group'];
  63. $group_label = isset($groups[$tag_group]['label']) ? $groups[$tag_group]['label'] : $tag_group;
  64. $info['metatag_context']['string translation']['properties'][$tag_name] = array(
  65. 'title' => $group_label . ': ' . $tag_info['label'],
  66. 'field' => "reactions.metatag_context_reaction.und.{$tag_name}.value",
  67. );
  68. }
  69. return $info;
  70. }
  71. /**
  72. * Implements hook_i18n_string_list().
  73. *
  74. * @todo Functionality to delete translation records when Panels are deleted.
  75. */
  76. function metatag_context_i18n_string_list($group) {
  77. if ($group == 'metatag' || $group == 'all') {
  78. $strings = array();
  79. foreach (context_context_list() as $context_name) {
  80. $context = context_load($context_name);
  81. if (!empty($context->reactions['metatag_context_reaction']['metatags'][LANGUAGE_NONE])) {
  82. $new_strings = array();
  83. foreach ($context->reactions['metatag_context_reaction']['metatags'][LANGUAGE_NONE] as $name => $value) {
  84. if (isset($value['value'])) {
  85. // Don't translate meta tags that are arrays.
  86. if (is_array($value['value'])) {
  87. continue;
  88. }
  89. // Collapse the array down one level.
  90. else {
  91. $new_strings[$name] = $value['value'];
  92. }
  93. }
  94. }
  95. $strings['metatag']['metatag_context'][$context->name] = $new_strings;
  96. }
  97. }
  98. return $strings;
  99. }
  100. }
  101. /**
  102. * List callback.
  103. */
  104. function metatag_context_i18n_list_contexts() {
  105. ctools_include('export');
  106. $configs = ctools_export_crud_load_all('metatag_config');
  107. if (!empty($configs)) {
  108. // Unserialize the config array.
  109. foreach ($configs as &$config) {
  110. if (is_string($config->config)) {
  111. $config->config = unserialize($config->config);
  112. }
  113. }
  114. return $configs;
  115. }
  116. }