Prepare Drupal 8 language changes for the bootstrap if needed.
function update_prepare_d8_language() {
if (db_table_exists('languages')) {
$languages = db_select('languages', 'l')
->fields('l')
->execute();
$plurals = array();
$javascript = array();
$prefixes = array();
$domains = array();
foreach ($languages as $language) {
$plurals[$language->language] = array(
'plurals' => $language->plurals,
'formula' => $language->formula,
);
$javascript[$language->language] = $language->javascript;
$prefixes[$language->language] = $language->prefix;
$domains[$language->language] = $language->domain;
}
variable_set('locale_translation_plurals', $plurals);
variable_set('locale_translation_javascript', $javascript);
variable_set('locale_language_negotiation_url_prefixes', $prefixes);
variable_set('locale_language_negotiation_url_domains', $domains);
// Drop now unneeded columns.
db_drop_field('languages', 'plurals');
db_drop_field('languages', 'formula');
db_drop_field('languages', 'javascript');
db_drop_field('languages', 'prefix');
db_drop_field('languages', 'domain');
db_drop_field('languages', 'native');
db_drop_field('languages', 'enabled');
// Update language count.
variable_set('language_count', db_query('SELECT COUNT(language) FROM {languages}')
->fetchField());
// Rename the languages table to language.
db_rename_table('languages', 'language');
// Install/enable the language module. We need to use the update specific
// version of this function to ensure schema conflicts don't happen due to
// our updated data.
$modules = array(
'language',
);
update_module_enable($modules);
// Rename language column to langcode and set it again as the primary key.
if (db_field_exists('language', 'language')) {
db_drop_primary_key('language');
$langcode_spec = array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => "Language code, e.g. 'de' or 'en-US'.",
);
db_change_field('language', 'language', 'langcode', $langcode_spec, array(
'primary key' => array(
'langcode',
),
));
}
// Adds the locked column and saves the special languages.
if (!db_field_exists('language', 'locked')) {
$locked_spec = array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'description' => 'A boolean indicating whether the administrator can edit or delete the language.',
);
db_add_field('language', 'locked', $locked_spec);
$max_language_weight = db_query('SELECT MAX(weight) FROM {language}')
->fetchField();
$languages = language_default_locked_languages($max_language_weight);
foreach ($languages as $language) {
db_insert('language')
->fields(array(
'langcode' => $language->langcode,
'name' => $language->name,
'weight' => $language->weight,
// These languages are locked, default to enabled.
'locked' => 1,
))
->execute();
}
}
// Update the 'language_default' system variable with the langcode change.
$language_default = variable_get('language_default');
if (!empty($language_default)) {
if (isset($language_default->language)) {
$language_default->langcode = $language_default->language;
unset($language_default->language);
}
unset($language_default->enabled);
// In D8, the 'language_default' is not anymore an object, but an array,
// so make sure that the new value that is saved into this variable is an
// array.
variable_set('language_default', (array) $language_default);
}
// Add column to track customized string status to locales_target.
// When updating in a non-English language, the locale translation system is
// triggered, which attempts to query string translations already.
if (db_table_exists('locales_target') && !db_field_exists('locales_target', 'customized')) {
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
// LOCALE_NOT_CUSTOMIZED
'description' => 'Boolean indicating whether the translation is custom to this site.',
);
db_add_field('locales_target', 'customized', $spec);
}
// Add locales_location table to track string locations.
// When updating in a non-English language, this table is used for
// refreshing JavaScript translations.
if (db_table_exists('locales_source') && !db_table_exists('locales_location')) {
$table = array(
'description' => 'Location information for source strings.',
'fields' => array(
'lid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Unique identifier of this location.',
),
'sid' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Unique identifier of this string.',
),
'type' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
'description' => 'The location type (file, config, path, etc).',
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Type dependent location information (file name, path, etc).',
),
'version' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'default' => 'none',
'description' => 'Version of Drupal where the location was found.',
),
),
'primary key' => array(
'lid',
),
'foreign keys' => array(
'locales_source' => array(
'table' => 'locales_source',
'columns' => array(
'sid' => 'lid',
),
),
),
'indexes' => array(
'string_id' => array(
'sid',
),
'string_type' => array(
'sid',
'type',
),
),
);
db_create_table('locales_location', $table);
}
}
}