Projet

Général

Profil

Paste
Télécharger (6,41 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / system / language.api.php @ 76597ebf

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Hooks provided by the base system for language support.
6
 */
7
8
/**
9
 * @addtogroup hooks
10
 * @{
11
 */
12
13
/**
14
 * Allows modules to act after language initialization has been performed.
15
 *
16
 * This is primarily needed to provide translation for configuration variables
17
 * in the proper bootstrap phase. Variables are user-defined strings and
18
 * therefore should not be translated via t(), since the source string can
19
 * change without notice and any previous translation would be lost. Moreover,
20
 * since variables can be used in the bootstrap phase, we need a bootstrap hook
21
 * to provide a translation early enough to avoid misalignments between code
22
 * using the original values and code using the translated values. However
23
 * modules implementing hook_boot() should be aware that language initialization
24
 * did not happen yet and thus they cannot rely on translated variables.
25
 */
26
function hook_language_init() {
27
  global $language, $conf;
28
29
  switch ($language->language) {
30
    case 'it':
31
      $conf['site_name'] = 'Il mio sito Drupal';
32
      break;
33
34
    case 'fr':
35
      $conf['site_name'] = 'Mon site Drupal';
36
      break;
37
  }
38
}
39
40
/**
41
 * Perform alterations on language switcher links.
42
 *
43
 * A language switcher link may need to point to a different path or use a
44
 * translated link text before going through l(), which will just handle the
45
 * path aliases.
46
 *
47
 * @param $links
48
 *   Nested array of links keyed by language code.
49
 * @param $type
50
 *   The language type the links will switch.
51
 * @param $path
52
 *   The current path.
53
 */
54
function hook_language_switch_links_alter(array &$links, $type, $path) {
55
  global $language;
56
57
  if ($type == LANGUAGE_TYPE_CONTENT && isset($links[$language->language])) {
58
    foreach ($links[$language->language] as $link) {
59
      $link['attributes']['class'][] = 'active-language';
60
    }
61
  }
62
}
63
64
/**
65
 * Define language types.
66
 *
67
 * @return
68
 *   An associative array of language type definitions. The keys are the
69
 *   identifiers, which are also used as names for global variables representing
70
 *   the types in the bootstrap phase. The values are associative arrays that
71
 *   may contain the following elements:
72
 *   - name: The human-readable language type identifier.
73
 *   - description: A description of the language type.
74
 *   - fixed: A fixed array of language negotiation provider identifiers to use
75
 *     to initialize this language. Defining this key makes the language type
76
 *     non-configurable, so it will always use the specified providers in the
77
 *     given priority order. Omit to make the language type configurable.
78
 *
79
 * @see hook_language_types_info_alter()
80
 * @ingroup language_negotiation
81
 */
82
function hook_language_types_info() {
83
  return array(
84
    'custom_language_type' => array(
85
      'name' => t('Custom language'),
86
      'description' => t('A custom language type.'),
87
    ),
88
    'fixed_custom_language_type' => array(
89
      'fixed' => array('custom_language_provider'),
90
    ),
91
  );
92
}
93
94
/**
95
 * Perform alterations on language types.
96
 *
97
 * @param $language_types
98
 *   Array of language type definitions.
99
 *
100
 * @see hook_language_types_info()
101
 * @ingroup language_negotiation
102
 */
103
function hook_language_types_info_alter(array &$language_types) {
104
  if (isset($language_types['custom_language_type'])) {
105
    $language_types['custom_language_type_custom']['description'] = t('A far better description.');
106
  }
107
}
108
109
/**
110
 * Define language negotiation providers.
111
 *
112
 * @return
113
 *   An associative array of language negotiation provider definitions. The keys
114
 *   are provider identifiers, and the values are associative arrays defining
115
 *   each provider, with the following elements:
116
 *   - types: An array of allowed language types. If a language negotiation
117
 *     provider does not specify which language types it should be used with, it
118
 *     will be available for all the configurable language types.
119
 *   - callbacks: An associative array of functions that will be called to
120
 *     perform various tasks. Possible elements are:
121
 *     - language: (required) Name of the callback function that determines the
122
 *       language value.
123
 *     - switcher: (optional) Name of the callback function that determines
124
 *       links for a language switcher block associated with this provider. See
125
 *       language_switcher_url() for an example.
126
 *     - url_rewrite: (optional) Name of the callback function that provides URL
127
 *       rewriting, if needed by this provider.
128
 *   - file: The file where callback functions are defined (this file will be
129
 *     included before the callbacks are invoked).
130
 *   - weight: The default weight of the provider.
131
 *   - name: The translated human-readable name for the provider.
132
 *   - description: A translated longer description of the provider.
133
 *   - config: An internal path pointing to the provider's configuration page.
134
 *   - cache: The value Drupal's page cache should be set to for the current
135
 *     provider to be invoked.
136
 *
137
 * @see hook_language_negotiation_info_alter()
138
 * @ingroup language_negotiation
139
 */
140
function hook_language_negotiation_info() {
141
  return array(
142
    'custom_language_provider' => array(
143
      'callbacks' => array(
144
        'language' => 'custom_language_provider_callback',
145
        'switcher' => 'custom_language_switcher_callback',
146
        'url_rewrite' => 'custom_language_url_rewrite_callback',
147
      ),
148
      'file' => drupal_get_path('module', 'custom') . '/custom.module',
149
      'weight' => -4,
150
      'types' => array('custom_language_type'),
151
      'name' => t('Custom language negotiation provider'),
152
      'description' => t('This is a custom language negotiation provider.'),
153
      'cache' => 0,
154
    ),
155
  );
156
}
157
158
/**
159
 * Perform alterations on language negoiation providers.
160
 *
161
 * @param $language_providers
162
 *   Array of language negotiation provider definitions.
163
 *
164
 * @see hook_language_negotiation_info()
165
 * @ingroup language_negotiation
166
 */
167
function hook_language_negotiation_info_alter(array &$language_providers) {
168
  if (isset($language_providers['custom_language_provider'])) {
169
    $language_providers['custom_language_provider']['config'] = 'admin/config/regional/language/configure/custom-language-provider';
170
  }
171
}
172
173
/**
174
 * Perform alterations on the language fallback candidates.
175
 *
176
 * @param $fallback_candidates
177
 *   An array of language codes whose order will determine the language fallback
178
 *   order.
179
 */
180
function hook_language_fallback_candidates_alter(array &$fallback_candidates) {
181
  $fallback_candidates = array_reverse($fallback_candidates);
182
}
183
184
/**
185
 * @} End of "addtogroup hooks".
186
 */