i18n_string.variable.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * Variable information
  5. */
  6. /**
  7. * Implements hook_variable_info().
  8. */
  9. function i18n_string_variable_info($options = array()) {
  10. $variables['i18n_string_translate_langcode_[language]'] = array(
  11. 'type' => 'multiple_language',
  12. 'title' => t('Enable translation for language'),
  13. 'multiple values' => array('type' => 'boolean'),
  14. 'group' => 'i18n',
  15. );
  16. $variables['i18n_string_allowed_formats'] = array(
  17. 'title' => t('Translatable text formats'),
  18. 'options callback' => 'i18n_string_variable_format_list',
  19. 'type' => 'options',
  20. 'default callback' => 'i18n_string_variable_format_default',
  21. 'access' => 'administer filters',
  22. 'description' => t('The translation system only translates strings with the selected text formats. All other strings will be ignored and removed from the list of translatable strings.'),
  23. );
  24. $variables['i18n_string_source_language'] = array(
  25. 'title' => t('Source language'),
  26. 'type' => 'language',
  27. 'default callback' => 'i18n_string_source_language',
  28. 'description' => t('Language that will be used as the source language for string translations. The default is the site default language.'),
  29. );
  30. $variables['i18n_string_debug'] = array(
  31. 'type' => 'enable',
  32. 'title' => t('Debug string translation', array(), $options),
  33. 'default' => 0,
  34. 'group' => 'debug',
  35. );
  36. $variables['i18n_string_textgroup_class_[textgroup]'] = array(
  37. 'title' => t('Class to use for the text group'),
  38. 'description' => t('Determines which the class will be use for string translation in the text group.', array(), $options),
  39. 'repeat' => array(
  40. 'type' => 'select',
  41. 'default' => 'i18n_string_textgroup_default',
  42. 'options callback' => 'i18n_string_variable_textgroup_class_list',
  43. ),
  44. 'submit callback' => 'i18n_string_variable_textgroup_class_submit_callback',
  45. 'group' => 'i18n',
  46. );
  47. return $variables;
  48. }
  49. /**
  50. * Implements hook_variable_type_info().
  51. */
  52. function i18n_string_variable_type_info() {
  53. $type['textgroup'] = array(
  54. 'title' => t('Text group'),
  55. 'type' => 'select',
  56. 'options callback' => 'i18n_string_variable_textgroup_list',
  57. );
  58. return $type;
  59. }
  60. /**
  61. * Options callback, format list
  62. */
  63. function i18n_string_variable_format_list() {
  64. $list = array();
  65. // As the user has administer filters permissions we get a full list here
  66. foreach (filter_formats() as $fid => $format) {
  67. $list[$fid] = $format->name;
  68. }
  69. return $list;
  70. }
  71. /**
  72. * Allowed formats default value
  73. */
  74. function i18n_string_variable_format_default() {
  75. return array(filter_fallback_format());
  76. }
  77. /**
  78. * Options callback, text groups list.
  79. */
  80. function i18n_string_variable_textgroup_list() {
  81. $groups = array();
  82. foreach (i18n_string_group_info() as $name => $info) {
  83. $groups[$name] = $info['title'];
  84. }
  85. return $groups;
  86. }
  87. /**
  88. * Options callback, text group classes list.
  89. */
  90. function i18n_string_variable_textgroup_class_list($variable, $options = array()) {
  91. return array(
  92. 'i18n_string_textgroup_default' => t('Text group handler default.', array(), $options),
  93. 'i18n_string_textgroup_cached' => t('Text group handler which include persistent caching.', array(), $options),
  94. );
  95. }
  96. /**
  97. * Submit callback. Execute Reset the persistent caches after save the text group class variables.
  98. */
  99. function i18n_string_variable_textgroup_class_submit_callback($variable, $options, $form, $form_state) {
  100. // Reset the persistent caches.
  101. cache_clear_all('i18n:string:' , 'cache', TRUE);
  102. }