metatag_views.i18n.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) hooks.
  5. */
  6. /**
  7. * Implements hook_i18n_object_info().
  8. */
  9. function metatag_views_i18n_object_info() {
  10. $info['metatag_views'] = array(
  11. 'title' => t('Metatag:Views configurations'),
  12. // Callback to load all config objects.
  13. 'list callback' => 'metatag_views_i18n_list_displays',
  14. // The object load callback.
  15. // 'load callback' => 'metatag_views_i18n_load',
  16. // Custom i18n object overrides. Right now this avoids problems with the
  17. // object ID as defined by get_string_context().
  18. 'class' => 'metatag_views_i18n_metatag',
  19. // @todo Is this needed? What does it do?
  20. // 'translation set' => TRUE,
  21. // The object key field; multiple values will be concatenated with ":" as
  22. // the separator.
  23. 'key' => array('vid', 'id'),
  24. // Placeholders for automatic paths. This connects the 'key' to strings in
  25. // the paths listed below.
  26. // 'placeholders' => array(
  27. // '%did' => 'did',
  28. // ),
  29. // To produce edit links automatically.
  30. // 'edit path' => 'admin/config/search/metatags/config/%instance',
  31. // Auto-generate a 'translate' tab.
  32. // 'translate tab' => 'admin/config/search/metatags/config/%instance/translate',
  33. // Properties for string translation.
  34. 'string translation' => array(
  35. // The textgroup, type and (below) name will be concatenated into a single
  36. // string as the {locales_source} context.
  37. 'textgroup' => 'metatag',
  38. 'type' => 'metatag_views',
  39. // Table where the object is stored, to automate string lists.
  40. // 'table' => 'views_display',
  41. // Translatable properties of these objects, this will be added later.
  42. 'properties' => array(),
  43. // The path to translate individual strings.
  44. // 'translate path' => 'admin/config/search/metatags/config/%instance/translate/%i18n_language',
  45. ),
  46. );
  47. // Compile all of the tags to add to the translation stack.
  48. $meta_tag_info = metatag_get_info();
  49. $groups = $meta_tag_info['groups'];
  50. foreach ($meta_tag_info['tags'] as $tag_info) {
  51. // Ignore certain field types that aren't translatable, mostly fields that
  52. // list predetermined options in various forms.
  53. if (!empty($tag_info['class']) && $tag_info['class'] == 'DrupalListMetaTag') {
  54. continue;
  55. }
  56. elseif (!empty($tag_info['form']['#type']) && $tag_info['form']['#type'] == 'select') {
  57. continue;
  58. }
  59. elseif (!empty($tag_info['form']['#options'])) {
  60. continue;
  61. }
  62. // Build a suitable structure for this meta tag.
  63. $tag_name = $tag_info['name'];
  64. $title = $tag_info['label'];
  65. if (!empty($tag_info['group'])) {
  66. $tag_group = $tag_info['group'];
  67. $group_label = !empty($groups[$tag_group]['label']) ? $groups[$tag_group]['label'] : $tag_group;
  68. $title = $group_label . ': ' . $title;
  69. }
  70. $info['metatag_views']['string translation']['properties'][$tag_name] = array(
  71. 'title' => $title,
  72. 'field' => "display_options.metatags.und.{$tag_name}.value",
  73. );
  74. }
  75. return $info;
  76. }
  77. /**
  78. * List callback.
  79. */
  80. function metatag_views_i18n_list_displays() {
  81. $displays = array();
  82. foreach (views_get_all_views() as $view_id => $view) {
  83. foreach ($view->display as $display) {
  84. if (!empty($display->display_options['metatags'][LANGUAGE_NONE])) {
  85. // Need to rig i18n_string's ability to find the record.
  86. $display->view_id = $view_id;
  87. $displays[$display->view_id . METATAG_VIEWS_CONTEXT_SEPARATOR . $display->id] = $display;
  88. }
  89. }
  90. }
  91. return $displays;
  92. }