Project

General

Profile

Paste
Download (3.15 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / i18n / tests / i18n_test.module @ 01f36513

1
<?php
2

    
3
/**
4
 * @file
5
 *   Helper module for testing i18n
6
 */
7

    
8
// Add some multilingual variables, override existing ones from settings so
9
// we have a known list and we don't need any addition to the settings file for testing i18n
10
_i18n_test_variable_init();
11

    
12
/**
13
 * Implements hook_init()
14
 */
15
function i18n_test_init() {
16
  // We just implement this hook so this one is loaded always on bootstap
17
}
18

    
19
/**
20
 * Set default multilingual variables and add any others defined by testing scripts
21
 *
22
 * More variables can be added using 'i18n_variables_test';
23
 */
24
function _i18n_test_variable_init() {
25
  global $conf;
26
  $conf['i18n_variables'] = array_merge(array('site_name', 'site_frontpage'), variable_get('i18n_variables_test', array()));
27
}
28

    
29
/**
30
 * Implements hook_i18n_string_info()
31
 */
32
function i18n_test_i18n_string_info() {
33
  $groups['test'] = array(
34
    'title' => t('Test'),
35
    'description' => t('Translatable menu items: title and description.'),
36
    'format' => FALSE, // This group doesn't have strings with format
37
    'refresh callback' => 'i18n_test_i18n_string_refresh',
38
  );
39
  $groups['test_cached'] = array(
40
    'title' => t('Test Cached Strings'),
41
    'description' => t('Translatable items of a textgroup with caching enabled.'),
42
    'format' => FALSE, // This group doesn't have strings with format
43
    'class' => variable_get('i18n_string_textgroup_class_test_cached', 'i18n_string_textgroup_cached_logged'),
44
  );
45
  return $groups;
46
}
47
/**
48
 * Locale refresh
49
 */
50
function i18n_test_i18n_string_refresh() {
51
  return TRUE;
52
}
53

    
54
/**
55
 * Implements hook_menu().
56
 */
57
function i18n_test_menu() {
58
  // Required for the i18n_string caching tests.
59
  $items['tests/i18n/i18n_string_build/%'] = array(
60
    'title' => 'Load string',
61
    'access callback' => TRUE,
62
    'page callback' => 'i18n_string_build',
63
    'page arguments' => array(3),
64
    'type' => MENU_CALLBACK,
65
    'delivery callback' => 'drupal_json_output',
66
  );
67
  $items['tests/i18n/i18n_string_build/%/%'] = array(
68
    'title' => 'Load string',
69
    'access callback' => TRUE,
70
    'page callback' => 'i18n_string_build',
71
    'page arguments' => array(3, 4),
72
    'type' => MENU_CALLBACK,
73
    'delivery callback' => 'drupal_json_output',
74
  );
75
  $items['tests/i18n/i18n_string_translation_search/%'] = array(
76
    'title' => 'Search string translations',
77
    'access callback' => TRUE,
78
    'page callback' => 'i18n_string_translation_search',
79
    'page arguments' => array(3),
80
    'type' => MENU_CALLBACK,
81
    'delivery callback' => 'drupal_json_output',
82
  );
83
  $items['tests/i18n/i18n_string_translation_search/%/%'] = array(
84
    'title' => 'Search string translations',
85
    'access callback' => TRUE,
86
    'page callback' => 'i18n_string_translation_search',
87
    'page arguments' => array(3, 4),
88
    'type' => MENU_CALLBACK,
89
    'delivery callback' => 'drupal_json_output',
90
  );
91
  return $items;
92
}
93

    
94
class i18n_string_textgroup_cached_logged extends i18n_string_textgroup_cached {
95
  public static function load_translation($i18nstring, $langcode) {
96
    $strings = variable_get('i18n_loaded_translations', array());
97
    $strings[$i18nstring->get_name()] = true;
98
    variable_set('i18n_loaded_translations', $strings);
99
    parent::load_translation($i18nstring, $langcode);
100
  }
101
}