metatag_panels.i18n.inc 4.2 KB

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