/[drupal]/drupal/modules/locale/locale.api.php
ViewVC logotype

Contents of /drupal/modules/locale/locale.api.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Fri Oct 16 15:47:46 2009 UTC (6 weeks ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.6: +19 -2 lines
File MIME type: text/x-php
#565480 follow-up by plach: Clean-ups and documentation.
1 <?php
2 // $Id: locale.api.php,v 1.6 2009/10/16 02:04:42 webchick Exp $
3
4 /**
5 * @file
6 * Hooks provided by the Locale module.
7 */
8
9 /**
10 * @addtogroup hooks
11 * @{
12 */
13
14 /**
15 * Allows modules to define their own text groups that can be translated.
16 *
17 * @param $op
18 * Type of operation. Currently, only supports 'groups'.
19 */
20 function hook_locale($op = 'groups') {
21 switch ($op) {
22 case 'groups':
23 return array('custom' => t('Custom'));
24 }
25 }
26
27 /**
28 * Perform alterations on language switcher links.
29 *
30 * A language switcher link may need to point to a different path or use a
31 * translated link text before going through l(), which will just handle the
32 * path aliases.
33 *
34 * @param $links
35 * Nested array of links keyed by language code.
36 * @param $type
37 * The language type the links will switch.
38 * @param $path
39 * The current path.
40 */
41 function hook_language_switch_link_alter(array &$links, $type, $path) {
42 global $language;
43
44 if ($type == LANGUAGE_TYPE_CONTENT && isset($links[$language])) {
45 foreach ($links[$language] as $link) {
46 $link['attributes']['class'][] = 'active-language';
47 }
48 }
49 }
50
51 /**
52 * Allow modules to define their own language types.
53 *
54 * @return
55 * An array of language type definitions. Each language type has an identifier
56 * key. The language type definition is an associative array that may contain
57 * the following key-value pairs:
58 * - "name": The human-readable language type identifier.
59 * - "description": A description of the language type.
60 */
61 function hook_language_types_info() {
62 return array(
63 'custom_language_type' => array(
64 'name' => t('Custom language'),
65 'description' => t('A custom language type.'),
66 ),
67 );
68 }
69
70 /**
71 * Perform alterations on language types.
72 *
73 * @param $language_types
74 * Array of language type definitions.
75 */
76 function hook_language_types_info_alter(array &$language_types) {
77 if (isset($language_types['custom_language_type'])) {
78 $language_types['custom_language_type_custom']['description'] = t('A far better description.');
79 }
80 }
81
82 /**
83 * Allow modules to define their own language providers.
84 *
85 * @return
86 * An array of language provider definitions. Each language provider has an
87 * identifier key. The language provider definition is an associative array
88 * that may contain the following key-value pairs:
89 * - "types": An array of allowed language types. If a language provider does
90 * not specify which language types it should be used with, it will be
91 * available for all the configurable language types.
92 * - "callbacks": An array of functions that will be called to perform various
93 * tasks. Possible key-value pairs are:
94 * - "language": Required. The callback that will determine the language
95 * value.
96 * - "switcher": The callback that will determine the language switch links
97 * associated to the current language provider.
98 * - "url_rewrite": The callback that will provide URL rewriting.
99 * - "file": A file that will be included before the callback is invoked; this
100 * allows callback functions to be in separate files.
101 * - "weight": The default weight the language provider has.
102 * - "name": A human-readable identifier.
103 * - "description": A description of the language provider.
104 * - "config": An internal path pointing to the language provider
105 * configuration page.
106 * - "cache": The value Drupal's page cache should be set to for the current
107 * language provider to be invoked.
108 */
109 function hook_language_negotiation_info() {
110 return array(
111 'custom_language_provider' => array(
112 'callbacks' => array(
113 'language' => 'custom_language_provider_callback',
114 'switcher' => 'custom_language_switcher_callback',
115 'url_rewrite' => 'custom_language_url_rewrite_callback',
116 ),
117 'file' => drupal_get_path('module', 'custom') . '/custom.module',
118 'weight' => -4,
119 'types' => array('custom_language_type'),
120 'name' => t('Custom language provider'),
121 'description' => t('This is a custom language provider.'),
122 'cache' => CACHE_DISABLED,
123 ),
124 );
125 }
126
127 /**
128 * Perform alterations on language providers.
129 *
130 * @param $language_providers
131 * Array of language provider definitions.
132 */
133 function hook_language_negotiation_info_alter(array &$language_providers) {
134 if (isset($language_providers['custom_language_provider'])) {
135 $language_providers['custom_language_provider']['config'] = 'admin/config/regional/language/configure/custom-language-provider';
136 }
137 }
138
139 /**
140 * Allow modules to react to language settings changes.
141 *
142 * Every module needing to act when the number of enabled languages changes
143 * should implement this. This is an "internal" hook and should not be invoked
144 * elsewhere. The typical implementation would trigger some kind of rebuilding,
145 * this way system components could properly react to the change of the enabled
146 * languages number.
147 */
148 function hook_multilingual_settings_changed() {
149 field_info_cache_clear();
150 }
151
152 /**
153 * Perform alterations on the language fallback candidates.
154 *
155 * @param $fallback_candidates
156 * An array of language codes whose order will determine the language fallback
157 * order.
158 */
159 function hook_language_fallback_candidates_alter(array &$fallback_candidates) {
160 $fallback_candidates = array_reverse($fallback_candidates);
161 }
162
163 /**
164 * @} End of "addtogroup hooks".
165 */

  ViewVC Help
Powered by ViewVC 1.1.2