-
Notifications
You must be signed in to change notification settings - Fork 15
/
metatag.i18n.inc
147 lines (131 loc) · 4.48 KB
/
metatag.i18n.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* @file
* Internationalization (i18n) hooks.
*/
/**
* Implements hook_i18n_string_info().
*/
function metatag_i18n_string_info() {
// Text groups.
$groups['metatag'] = array(
'title' => t('Metatag'),
'description' => t('Configurable meta tags.'),
// This group does not have strings with text formats.
'format' => FALSE,
// This group can list all strings.
// @todo What does this actually do?
'list' => TRUE,
);
return $groups;
}
/**
* Implements hook_i18n_object_info().
*/
function metatag_i18n_object_info() {
// Compile all of the tags to add to the translation stack.
$meta_tag_info = metatag_get_info();
$groups = $meta_tag_info['groups'];
$config_properties = $output_properties = array();
foreach ($meta_tag_info['tags'] as $tag_name => $tag_info) {
// Ignore certain field types that aren't translatable, mostly fields that
// list predetermined options in various forms.
if (!empty($tag_info['class']) && $tag_info['class'] == 'BackdropListMetaTag') {
continue;
}
elseif (!empty($tag_info['form']['#type']) && $tag_info['form']['#type'] == 'select') {
continue;
}
elseif (!empty($tag_info['form']['#options'])) {
continue;
}
// Build a suitable structure for this meta tag.
if (!empty($tag_info['group']) && !empty($groups[$tag_info['group']]['label'])) {
$group_label = $groups[$tag_info['group']]['label'] . ': ';
}
elseif (!empty($tag_info['group'])) {
$group_label = $tag_info['group'] . ': ';
}
else {
$group_label = '';
}
// Configuration items.
$config_properties[$tag_name] = array(
'title' => $group_label . $tag_info['label'],
'field' => "config.{$tag_name}.value",
);
// Output items.
$output_properties[$tag_name] = array(
'title' => $group_label . ': ' . $tag_info['label'],
'field' => "data.{$tag_name}.value",
);
}
// The main Metatag configuration items.
$info['metatag_config'] = array(
'title' => t('Metatag configuration'),
// Callback to load all config objects.
'list callback' => 'metatag_i18n_list_metatag_config',
// The object load callback.
'load callback' => 'metatag_config_load',
// @todo Custom i18n object overrides.
// 'class' => 'metatag_i18n_metatag',
// @todo Is this needed? What does it do?
// 'translation set' => TRUE,
// The object key field.
'key' => 'instance',
// Placeholders for automatic paths. This connects the 'key' to strings in
// the paths listed below.
'placeholders' => array(
'%instance' => 'instance',
),
// To produce edit links automatically.
'edit path' => 'admin/config/metadata/metatags/config/%instance',
// Auto-generate a 'translate' tab.
'translate tab' => 'admin/config/metadata/metatags/config/%instance/translate',
// Properties for string translation.
'string translation' => array(
// The textgroup, type and (below) name will be concatenated into a single
// string as the {locales_source} context.
'textgroup' => 'metatag',
'type' => 'metatag_config',
// Table where the object is stored, to automate string lists.
'table' => 'metatag_config',
// Translatable properties of these objects.
'properties' => $config_properties,
// The path to translate individual strings.
'translate path' => 'admin/config/metadata/metatags/config/%instance/translate/%i18n_language',
),
);
// The final meta tags being output on the page.
if (config_get('metatag.settings', 'i18n_translate_output')) {
$info['output'] = array(
'title' => t('Metatag final tag output'),
// Properties for string translation.
'string translation' => array(
// The textgroup, type and (below) name will be concatenated into a
// single string as the {locales_source} context.
'textgroup' => 'metatag',
'type' => 'output',
// Translatable properties of these objects.
'properties' => $output_properties,
),
);
}
return $info;
}
/**
* List callback for {metatag_config} strings.
*/
function metatag_i18n_list_metatag_config() {
$names = config_get_names_with_prefix('metatag.instance');
$configs = config_load_multiple($names);
if (!empty($configs)) {
// Unserialize the config array.
foreach ($configs as &$config) {
if (is_string($config->config)) {
$config->config = unserialize($config->config);
}
}
}
return $configs;
}