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 'default' => 0, // LOCALE_NOT_CUSTOMIZED
115 'description' => 'Boolean indicating whether the translation is custom to this site.',
118 'primary key' => ['language', 'lid'],
120 'locales_source' => [
121 'table' => 'locales_source',
122 'columns' => ['lid' => 'lid'],
130 $schema['locales_location'] = [
131 'description' => 'Location information for source strings.',
136 'description' => 'Unique identifier of this location.',
141 'description' => 'Unique identifier of this string.',
144 'type' => 'varchar_ascii',
148 'description' => 'The location type (file, config, path, etc).',
155 'description' => 'Type dependent location information (file name, path, etc).',
158 'type' => 'varchar_ascii',
162 'description' => 'Version of Drupal where the location was found.',
165 'primary key' => ['lid'],
167 'locales_source' => [
168 'table' => 'locales_source',
169 'columns' => ['sid' => 'lid'],
173 'string_id' => ['sid'],
174 'string_type' => ['sid', 'type'],
178 $schema['locale_file'] = [
179 'description' => 'File import status information for interface translation files.',
182 'type' => 'varchar_ascii',
186 'description' => 'A unique short name to identify the project the file belongs to.',
189 'type' => 'varchar_ascii',
193 'description' => 'Language code of this translation. References {language}.langcode.',
200 'description' => 'Filename of the imported file.',
207 'description' => 'Version tag of the imported file.',
214 'description' => 'URI of the remote file, the resulting local file or the locally imported file.',
220 'description' => 'Unix timestamp of the imported file.',
226 'description' => 'Unix timestamp of the last time this translation was confirmed to be the most recent release available.',
229 'primary key' => ['project', 'langcode'],
235 * Implements hook_requirements().
237 function locale_requirements($phase) {
239 if ($phase == 'runtime') {
240 $available_updates = [];
242 $languages = locale_translatable_language_list();
245 // Determine the status of the translation updates per language.
246 $status = locale_translation_get_status();
248 foreach ($status as $project) {
249 foreach ($project as $langcode => $project_info) {
250 if (empty($project_info->type)) {
251 $untranslated[$langcode] = $languages[$langcode]->getName();
253 elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
254 $available_updates[$langcode] = $languages[$langcode]->getName();
259 if ($available_updates || $untranslated) {
260 if ($available_updates) {
261 $requirements['locale_translation'] = [
262 'title' => 'Translation update status',
263 'value' => \Drupal::l(t('Updates available'), new Url('locale.translate_status')),
264 'severity' => REQUIREMENT_WARNING,
265 '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')]),
269 $requirements['locale_translation'] = [
270 'title' => 'Translation update status',
271 'value' => t('Missing translations'),
272 'severity' => REQUIREMENT_INFO,
273 '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')]),
278 $requirements['locale_translation'] = [
279 'title' => 'Translation update status',
280 'value' => t('Up to date'),
281 'severity' => REQUIREMENT_OK,
286 $requirements['locale_translation'] = [
287 'title' => 'Translation update status',
288 'value' => \Drupal::l(t('Can not determine status'), new Url('locale.translate_status')),
289 'severity' => REQUIREMENT_WARNING,
290 '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')]),
295 return $requirements;
299 * Delete translation status data in state.
301 function locale_update_8300() {
302 // Delete the old translation status data, it will be rebuilt and stored in
303 // the new key value collection.
304 \Drupal::state()->delete('locale.translation_status');