5 * Install, update, and uninstall functions for the Locale module.
11 * Implements hook_install().
13 function locale_install() {
14 // Create the interface translations directory and ensure it's writable.
15 if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) {
16 $site_path = \Drupal::service('site.path');
17 $directory = $site_path . '/files/translations';
18 \Drupal::configFactory()->getEditable('locale.settings')->set('translation.path', $directory)->save();
20 file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
24 * Implements hook_uninstall().
26 function locale_uninstall() {
27 $config = \Drupal::config('locale.settings');
28 // Delete all JavaScript translation files.
29 $locale_js_directory = 'public://' . $config->get('javascript.directory');
31 if (is_dir($locale_js_directory)) {
32 $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
33 foreach ($locale_javascripts as $langcode => $file_suffix) {
34 if (!empty($file_suffix)) {
35 file_unmanaged_delete($locale_js_directory . '/' . $langcode . '_' . $file_suffix . '.js');
38 // Delete the JavaScript translations directory if empty.
39 if (!file_scan_directory($locale_js_directory, '/.*/')) {
40 drupal_rmdir($locale_js_directory);
45 \Drupal::state()->delete('system.javascript_parsed');
46 \Drupal::state()->delete('locale.translation.plurals');
47 \Drupal::state()->delete('locale.translation.javascript');
51 * Implements hook_schema().
53 function locale_schema() {
54 $schema['locales_source'] = [
55 'description' => 'List of English source strings.',
60 'description' => 'Unique identifier of this string.',
64 'mysql_type' => 'blob',
66 'description' => 'The original string in English.',
69 'type' => 'varchar_ascii',
73 'description' => 'The context this string applies to.',
76 'type' => 'varchar_ascii',
80 'description' => 'Version of Drupal where the string was last used (for locales optimization).',
83 'primary key' => ['lid'],
85 'source_context' => [['source', 30], 'context'],
89 $schema['locales_target'] = [
90 'description' => 'Stores translated versions of strings.',
96 'description' => 'Source string ID. References {locales_source}.lid.',
100 'mysql_type' => 'blob',
102 'description' => 'Translation string value in this language.',
105 'type' => 'varchar_ascii',
109 'description' => 'Language code. References {language}.langcode.',
114 // LOCALE_NOT_CUSTOMIZED
116 'description' => 'Boolean indicating whether the translation is custom to this site.',
119 'primary key' => ['language', 'lid'],
121 'locales_source' => [
122 'table' => 'locales_source',
123 'columns' => ['lid' => 'lid'],
131 $schema['locales_location'] = [
132 'description' => 'Location information for source strings.',
137 'description' => 'Unique identifier of this location.',
142 'description' => 'Unique identifier of this string.',
145 'type' => 'varchar_ascii',
149 'description' => 'The location type (file, config, path, etc).',
156 'description' => 'Type dependent location information (file name, path, etc).',
159 'type' => 'varchar_ascii',
163 'description' => 'Version of Drupal where the location was found.',
166 'primary key' => ['lid'],
168 'locales_source' => [
169 'table' => 'locales_source',
170 'columns' => ['sid' => 'lid'],
174 'string_id' => ['sid'],
175 'string_type' => ['sid', 'type'],
179 $schema['locale_file'] = [
180 'description' => 'File import status information for interface translation files.',
183 'type' => 'varchar_ascii',
187 'description' => 'A unique short name to identify the project the file belongs to.',
190 'type' => 'varchar_ascii',
194 'description' => 'Language code of this translation. References {language}.langcode.',
201 'description' => 'Filename of the imported file.',
208 'description' => 'Version tag of the imported file.',
215 'description' => 'URI of the remote file, the resulting local file or the locally imported file.',
221 'description' => 'Unix timestamp of the imported file.',
227 'description' => 'Unix timestamp of the last time this translation was confirmed to be the most recent release available.',
230 'primary key' => ['project', 'langcode'],
236 * Implements hook_requirements().
238 function locale_requirements($phase) {
240 if ($phase == 'runtime') {
241 $available_updates = [];
243 $languages = locale_translatable_language_list();
246 // Determine the status of the translation updates per language.
247 $status = locale_translation_get_status();
249 foreach ($status as $project) {
250 foreach ($project as $langcode => $project_info) {
251 if (empty($project_info->type)) {
252 $untranslated[$langcode] = $languages[$langcode]->getName();
254 elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
255 $available_updates[$langcode] = $languages[$langcode]->getName();
260 if ($available_updates || $untranslated) {
261 if ($available_updates) {
262 $requirements['locale_translation'] = [
263 'title' => 'Translation update status',
264 'value' => \Drupal::l(t('Updates available'), new Url('locale.translate_status')),
265 'severity' => REQUIREMENT_WARNING,
266 'description' => t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => implode(', ', $available_updates), ':updates' => \Drupal::url('locale.translate_status')]),
270 $requirements['locale_translation'] = [
271 'title' => 'Translation update status',
272 'value' => t('Missing translations'),
273 'severity' => REQUIREMENT_INFO,
274 'description' => t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => implode(', ', $untranslated), ':updates' => \Drupal::url('locale.translate_status')]),
279 $requirements['locale_translation'] = [
280 'title' => 'Translation update status',
281 'value' => t('Up to date'),
282 'severity' => REQUIREMENT_OK,
287 $requirements['locale_translation'] = [
288 'title' => 'Translation update status',
289 'value' => \Drupal::l(t('Can not determine status'), new Url('locale.translate_status')),
290 'severity' => REQUIREMENT_WARNING,
291 'description' => t('No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.', [':updates' => \Drupal::url('locale.translate_status')]),
296 return $requirements;
300 * Delete translation status data in state.
302 function locale_update_8300() {
303 // Delete the old translation status data, it will be rebuilt and stored in
304 // the new key value collection.
305 \Drupal::state()->delete('locale.translation_status');