metatag_views.i18n.inc 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $tag_group = $tag_info['group'];
  65. $group_label = isset($groups[$tag_group]['label']) ? $groups[$tag_group]['label'] : $tag_group;
  66. $info['metatag_views']['string translation']['properties'][$tag_name] = array(
  67. 'title' => $group_label . ': ' . $tag_info['label'],
  68. 'field' => "display_options.metatags.und.{$tag_name}.value",
  69. );
  70. }
  71. return $info;
  72. }
  73. /**
  74. * List callback.
  75. */
  76. function metatag_views_i18n_list_displays() {
  77. $displays = array();
  78. foreach (views_get_all_views() as $view_id => $view) {
  79. foreach ($view->display as $display) {
  80. if (!empty($display->display_options['metatags'][LANGUAGE_NONE])) {
  81. // Need to rig i18n_string's ability to find the record.
  82. $display->view_id = $view_id;
  83. $displays[$display->view_id . METATAG_VIEWS_CONTEXT_SEPARATOR . $display->id] = $display;
  84. }
  85. }
  86. }
  87. return $displays;
  88. }