i18n_test.module 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @file
  4. * Helper module for testing i18n
  5. */
  6. // Add some multilingual variables, override existing ones from settings so
  7. // we have a known list and we don't need any addition to the settings file for testing i18n
  8. _i18n_test_variable_init();
  9. /**
  10. * Implements hook_init()
  11. */
  12. function i18n_test_init() {
  13. // We just implement this hook so this one is loaded always on bootstap
  14. }
  15. /**
  16. * Set default multilingual variables and add any others defined by testing scripts
  17. *
  18. * More variables can be added using 'i18n_variables_test';
  19. */
  20. function _i18n_test_variable_init() {
  21. global $conf;
  22. $conf['i18n_variables'] = array_merge(array('site_name', 'site_frontpage'), variable_get('i18n_variables_test', array()));
  23. }
  24. /**
  25. * Implements hook_i18n_string_info()
  26. */
  27. function i18n_test_i18n_string_info() {
  28. $groups['test'] = array(
  29. 'title' => t('Test'),
  30. 'description' => t('Translatable menu items: title and description.'),
  31. 'format' => FALSE, // This group doesn't have strings with format
  32. 'refresh callback' => 'i18n_test_i18n_string_refresh',
  33. );
  34. $groups['test_cached'] = array(
  35. 'title' => t('Test Cached Strings'),
  36. 'description' => t('Translatable items of a textgroup with caching enabled.'),
  37. 'format' => FALSE, // This group doesn't have strings with format
  38. 'class' => 'i18n_string_textgroup_cached_logged',
  39. );
  40. return $groups;
  41. }
  42. /**
  43. * Locale refresh
  44. */
  45. function i18n_test_i18n_string_refresh() {
  46. return TRUE;
  47. }
  48. /**
  49. * Implements hook_menu().
  50. */
  51. function i18n_test_menu() {
  52. // Required for the i18n_string caching tests.
  53. $items['tests/i18n/i18n_string_build/%'] = array(
  54. 'title' => 'Load string',
  55. 'access callback' => TRUE,
  56. 'page callback' => 'i18n_string_build',
  57. 'page arguments' => array(3),
  58. 'type' => MENU_CALLBACK,
  59. 'delivery callback' => 'drupal_json_output',
  60. );
  61. $items['tests/i18n/i18n_string_build/%/%'] = array(
  62. 'title' => 'Load string',
  63. 'access callback' => TRUE,
  64. 'page callback' => 'i18n_string_build',
  65. 'page arguments' => array(3, 4),
  66. 'type' => MENU_CALLBACK,
  67. 'delivery callback' => 'drupal_json_output',
  68. );
  69. $items['tests/i18n/i18n_string_translation_search/%'] = array(
  70. 'title' => 'Search string translations',
  71. 'access callback' => TRUE,
  72. 'page callback' => 'i18n_string_translation_search',
  73. 'page arguments' => array(3),
  74. 'type' => MENU_CALLBACK,
  75. 'delivery callback' => 'drupal_json_output',
  76. );
  77. $items['tests/i18n/i18n_string_translation_search/%/%'] = array(
  78. 'title' => 'Search string translations',
  79. 'access callback' => TRUE,
  80. 'page callback' => 'i18n_string_translation_search',
  81. 'page arguments' => array(3, 4),
  82. 'type' => MENU_CALLBACK,
  83. 'delivery callback' => 'drupal_json_output',
  84. );
  85. return $items;
  86. }
  87. class i18n_string_textgroup_cached_logged extends i18n_string_textgroup_cached {
  88. public static function load_translation($i18nstring, $langcode) {
  89. $strings = variable_get('i18n_loaded_translations', array());
  90. $strings[$i18nstring->get_name()] = true;
  91. variable_set('i18n_loaded_translations', $strings);
  92. parent::load_translation($i18nstring, $langcode);
  93. }
  94. }