metatag.i18n.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) hooks.
  5. */
  6. /**
  7. * Implements hook_i18n_string_info().
  8. */
  9. function metatag_i18n_string_info() {
  10. // Text groups.
  11. $groups['metatag'] = array(
  12. 'title' => t('Metatag'),
  13. 'description' => t('Configurable meta tags.'),
  14. // This group does not have strings with text formats.
  15. 'format' => FALSE,
  16. // This group can list all strings.
  17. // @todo What does this actually do?
  18. 'list' => TRUE,
  19. );
  20. return $groups;
  21. }
  22. /**
  23. * Implements hook_i18n_object_info().
  24. */
  25. function metatag_i18n_object_info() {
  26. // Compile all of the tags to add to the translation stack.
  27. $meta_tag_info = metatag_get_info();
  28. $groups = $meta_tag_info['groups'];
  29. $config_properties = $output_properties = array();
  30. foreach ($meta_tag_info['tags'] as $tag_name => $tag_info) {
  31. // Ignore certain field types that aren't translatable, mostly fields that
  32. // list predetermined options in various forms.
  33. if (!empty($tag_info['class']) && $tag_info['class'] == 'DrupalListMetaTag') {
  34. continue;
  35. }
  36. elseif (!empty($tag_info['form']['#type']) && $tag_info['form']['#type'] == 'select') {
  37. continue;
  38. }
  39. elseif (!empty($tag_info['form']['#options'])) {
  40. continue;
  41. }
  42. // Build a suitable structure for this meta tag.
  43. if (!empty($tag_info['group']) && !empty($groups[$tag_info['group']]['label'])) {
  44. $group_label = $groups[$tag_info['group']]['label'] . ': ';
  45. }
  46. elseif (!empty($tag_info['group'])) {
  47. $group_label = $tag_info['group'] . ': ';
  48. }
  49. else {
  50. $group_label = '';
  51. }
  52. // Configuration items.
  53. $config_properties[$tag_name] = array(
  54. 'title' => $group_label . $tag_info['label'],
  55. 'field' => "config.{$tag_name}.value",
  56. );
  57. // Output items.
  58. $output_properties[$tag_name] = array(
  59. 'title' => $group_label . ': ' . $tag_info['label'],
  60. 'field' => "data.{$tag_name}.value",
  61. );
  62. }
  63. // The main Metatag configuration items.
  64. $info['metatag_config'] = array(
  65. 'title' => t('Metatag configuration'),
  66. // Callback to load all config objects.
  67. 'list callback' => 'metatag_i18n_list_metatag_config',
  68. // The object load callback.
  69. 'load callback' => 'metatag_config_load',
  70. // @todo Custom i18n object overrides.
  71. // 'class' => 'metatag_i18n_metatag',
  72. // @todo Is this needed? What does it do?
  73. // 'translation set' => TRUE,
  74. // The object key field.
  75. 'key' => 'instance',
  76. // Placeholders for automatic paths. This connects the 'key' to strings in
  77. // the paths listed below.
  78. 'placeholders' => array(
  79. '%instance' => 'instance',
  80. ),
  81. // To produce edit links automatically.
  82. 'edit path' => 'admin/config/search/metatags/config/%instance',
  83. // Auto-generate a 'translate' tab.
  84. 'translate tab' => 'admin/config/search/metatags/config/%instance/translate',
  85. // Properties for string translation.
  86. 'string translation' => array(
  87. // The textgroup, type and (below) name will be concatenated into a single
  88. // string as the {locales_source} context.
  89. 'textgroup' => 'metatag',
  90. 'type' => 'metatag_config',
  91. // Table where the object is stored, to automate string lists.
  92. 'table' => 'metatag_config',
  93. // Translatable properties of these objects.
  94. 'properties' => $config_properties,
  95. // The path to translate individual strings.
  96. 'translate path' => 'admin/config/search/metatags/config/%instance/translate/%i18n_language',
  97. ),
  98. );
  99. // The final meta tags being output on the page.
  100. if (variable_get('metatag_i18n_translate_output', FALSE)) {
  101. $info['output'] = array(
  102. 'title' => t('Metatag final tag output'),
  103. // Properties for string translation.
  104. 'string translation' => array(
  105. // The textgroup, type and (below) name will be concatenated into a
  106. // single string as the {locales_source} context.
  107. 'textgroup' => 'metatag',
  108. 'type' => 'output',
  109. // Translatable properties of these objects.
  110. 'properties' => $output_properties,
  111. ),
  112. );
  113. }
  114. return $info;
  115. }
  116. /**
  117. * List callback for {metatag_config} strings.
  118. */
  119. function metatag_i18n_list_metatag_config() {
  120. ctools_include('export');
  121. $configs = ctools_export_crud_load_all('metatag_config');
  122. if (!empty($configs)) {
  123. // Unserialize the config array.
  124. foreach ($configs as &$config) {
  125. if (is_string($config->config)) {
  126. $config->config = unserialize($config->config);
  127. }
  128. }
  129. }
  130. return $configs;
  131. }