1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Internationalization (i18n) package. Multilingual variables API.
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* The type of language used for variables.
|
9 |
|
|
*/
|
10 |
|
|
define('I18N_VARIABLE_LANGUAGE_TYPE', 'i18n_language_variable');
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* Implements hook_language_init()
|
14 |
|
|
*/
|
15 |
|
|
function i18n_variable_language_init() {
|
16 |
|
|
if (drupal_multilingual()) {
|
17 |
|
|
module_invoke('variable_realm', 'initialize', 'language');
|
18 |
|
|
}
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Implements hook_variable_realm_info().
|
23 |
|
|
*/
|
24 |
|
|
function i18n_variable_variable_realm_info() {
|
25 |
|
|
$realm['language'] = array(
|
26 |
|
|
'title' => t('Language'),
|
27 |
|
|
'weight' => 100,
|
28 |
|
|
'controller class' => 'I18nVariableLanguageRealm',
|
29 |
|
|
'store class' => 'VariableStoreRealmStore',
|
30 |
|
|
// Variables for this realm can be selected from a list.
|
31 |
|
|
'select' => TRUE,
|
32 |
|
|
'select path' => 'admin/config/regional/i18n/variable',
|
33 |
|
|
// Name for variables that belong to this realm: 'multilingual' variable/s
|
34 |
|
|
'variable name' => t('multilingual'),
|
35 |
|
|
'variable class' => 'i18n-variable',
|
36 |
|
|
// Automatically handle these variables in system settings forms.
|
37 |
|
|
'form settings' => TRUE,
|
38 |
|
|
'form switcher' => TRUE,
|
39 |
|
|
);
|
40 |
|
|
return $realm;
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* Implements hook_menu()
|
45 |
|
|
*/
|
46 |
|
|
function i18n_variable_menu() {
|
47 |
|
|
$items['admin/config/regional/i18n/variable'] = array(
|
48 |
|
|
'title' => 'Variables',
|
49 |
|
|
'description' => 'Configure multilingual variables.',
|
50 |
|
|
'page callback' => 'drupal_get_form',
|
51 |
|
|
'page arguments' => array('variable_realm_select_variables_form', 'language'),
|
52 |
|
|
'access arguments' => array('administer site configuration'),
|
53 |
|
|
'file' => 'variable_realm.form.inc',
|
54 |
|
|
'file path' => drupal_get_path('module', 'variable_realm'),
|
55 |
|
|
'type' => MENU_LOCAL_TASK,
|
56 |
|
|
);
|
57 |
|
|
return $items;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Get variables language, make sure it is initialized
|
63 |
|
|
*/
|
64 |
|
|
function i18n_variable_language() {
|
65 |
|
|
// If we've got a variables language, it will be that one
|
66 |
|
|
if (!isset($GLOBALS[I18N_VARIABLE_LANGUAGE_TYPE])) {
|
67 |
|
|
$GLOBALS[I18N_VARIABLE_LANGUAGE_TYPE] = i18n_language_interface();
|
68 |
|
|
}
|
69 |
|
|
return $GLOBALS[I18N_VARIABLE_LANGUAGE_TYPE];
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/**
|
73 |
|
|
* Get original value for global variable/s
|
74 |
|
|
*/
|
75 |
|
|
function i18n_variable_global($name = NULL, $default = NULL) {
|
76 |
|
|
return variable_realm_global_get($name, $default);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Get list of multilingual variables or check whether a variable is multilingual
|
81 |
|
|
*/
|
82 |
|
|
function i18n_variable_list($name = NULL) {
|
83 |
|
|
$variables = &drupal_static(__FUNCTION__);
|
84 |
|
|
if (!isset($variables)) {
|
85 |
|
|
$variables = variable_children(variable_get('variable_realm_list_language', array()));
|
86 |
|
|
}
|
87 |
|
|
return $name ? in_array($name, $variables) : $variables;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
/**
|
91 |
|
|
* Load language variables into array.
|
92 |
|
|
*
|
93 |
|
|
* Pull variables from the store but filter out the ones that are not multilingual.
|
94 |
|
|
*/
|
95 |
|
|
function i18n_variable_load($langcode) {
|
96 |
|
|
$variables = array();
|
97 |
|
|
foreach (variable_store('language', $langcode) as $name => $value) {
|
98 |
|
|
if (i18n_variable_list($name)) {
|
99 |
|
|
$variables[$name] = $value;
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
return $variables;
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
/**
|
106 |
|
|
* Set a persistent language dependent variable.
|
107 |
|
|
*
|
108 |
|
|
* @param $name
|
109 |
|
|
* The name of the variable to set.
|
110 |
|
|
* @param $value
|
111 |
|
|
* The value to set. This can be any PHP data type; these functions take care
|
112 |
|
|
* of serialization as necessary.
|
113 |
|
|
* @param $langcode
|
114 |
|
|
* Language code.
|
115 |
|
|
*/
|
116 |
|
|
function i18n_variable_set($name, $value, $langcode) {
|
117 |
|
|
variable_realm_set('language', $langcode, $name, $value);
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
/**
|
121 |
|
|
* Get single multilingual variable
|
122 |
|
|
*/
|
123 |
|
|
function i18n_variable_get($name, $langcode, $default = NULL) {
|
124 |
|
|
return variable_realm_get('language', $langcode, $name, $default);
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
/**
|
128 |
|
|
* Unset a persistent multilingual variable.
|
129 |
|
|
*
|
130 |
|
|
* @param $name
|
131 |
|
|
* The name of the variable to undefine.
|
132 |
|
|
* @param $langcode
|
133 |
|
|
* Language code.
|
134 |
|
|
*/
|
135 |
|
|
function i18n_variable_del($name, $langcode) {
|
136 |
|
|
variable_realm_del('language', $langcode, $name);
|
137 |
|
|
}
|