summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt2
-rw-r--r--i18n.module43
-rw-r--r--i18nstrings/i18nstrings.install29
-rw-r--r--i18nstrings/i18nstrings.module39
4 files changed, 74 insertions, 39 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 54070d8..8f45b79 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -10,6 +10,8 @@ TO DO
6.x-beta6 to .........
----------------------
+- Mark translations a outdated when source string changes, by nedjo, #355366
+- Changed default behavior: content types with multilingual support disabled are now language neutral, #270655
- Added i18n menu handling to node form, by Roger López, Stella, #348444
- Added additional language support level, by stella, Roger Lopez, #349193
- Fixed duplicated 'ts' function (CiviCRM), renamed to 'i18nstrings_ts', by mfb, #298154
diff --git a/i18n.module b/i18n.module
index 640c5af..03bdf6f 100644
--- a/i18n.module
+++ b/i18n.module
@@ -525,45 +525,20 @@ function i18n_form_alter(&$form, $form_state, $form_id) {
break;
default:
- // Extended language for node edit form.
+ // Extensions for node edit forms
if (isset($form['#id']) && $form['#id'] == 'node-form') {
- if (isset($form['#node']->type) && variable_get('language_content_type_'. $form['#node']->type, 0)) {
- $form['language']['#options'] = i18n_node_language_list($form['#node'], TRUE);
- }
- }
- /** @ TO DO Upgrade
- if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && $node = $form['#node']) {
- // Language field
- if (variable_get('i18n_node_'.$form['type']['#value'], 0) && !isset($form['i18n']['language'])) {
- // Language field
- $form['i18n'] = array(
- '#type' => 'fieldset',
- '#title' => t('Multilingual settings'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#weight' => -4
- );
- // Language will default to current only when creating a node.
- $language = isset($form['#node']->language) ? $form['#node']->language : (arg(1)=='add' ? i18n_get_lang() : '');
- $form['i18n']['language'] = _i18n_language_select($language, t('If you change the language, you must click on <i>Preview</i> to get the right categories &amp; terms for that language.'), -4, i18n_node_language_list($node));
- $form['i18n']['trid'] = array(
- '#type' => 'value',
- '#value' => $form['#node']->trid
- );
- }
- // Correction for lang/node/nid aliases generated by path module.
- // if ($form['#node']->path && $form['#node']->path == i18n_get_lang().'/node/'.$form['#node']->nid) {
- if ($node->path) {
- $alias = drupal_lookup_path('alias', 'node/'.$node->nid);
- if($alias && $alias != 'node/'.$node->nid) {
- $form['#node']->path = $alias;
+ if (isset($form['#node']->type)) {
+ // Set language to empty for not multilingual nodes when creating
+ if (!isset($form['#node']->nid) && !variable_get('language_content_type_'. $form['#node']->type, 0)) {
+ $form['language'] = array('#type' => 'value', '#value' => '');
}
- else {
- unset($form['#node']->path);
+ // Extended language, add all languages to the list
+ if (!empty($form['language']['#options']) && variable_get('language_content_type_'. $form['#node']->type, 0)) {
+ $form['language']['#options'] = i18n_node_language_list($form['#node'], TRUE);
}
}
}
- */
+
// Multilingual variables in settings form.
if (isset($form['#theme']) && $form['#theme'] == 'system_settings_form' && $variables = variable_get('i18n_variables', 0)) {
if (i18n_form_alter_settings($form, $variables)) {
diff --git a/i18nstrings/i18nstrings.install b/i18nstrings/i18nstrings.install
index a3a0420..6161fec 100644
--- a/i18nstrings/i18nstrings.install
+++ b/i18nstrings/i18nstrings.install
@@ -9,22 +9,30 @@
function i18nstrings_install() {
// Create database tables.
drupal_install_schema('i18nstrings');
+
// Set module weight for it to run after core modules.
db_query("UPDATE {system} SET weight = 10 WHERE name = 'i18nstrings' AND type = 'module'");
- // Add custom index to locales_source table.
$ret = array();
+
+ // Add a field to track whether a translation needs updating.
+ db_add_field($ret, 'locales_target', 'status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+
+ // Add custom index to locales_source table.
db_add_index($ret, 'locales_source', 'textgroup_location', array(array('textgroup', 30), 'location'));
}
function i18nstrings_uninstall() {
+ $ret = array();
+
// Create database tables.
drupal_uninstall_schema('i18nstrings');
// @TODO locale table cleanup, think about it.
// Should we drop all strings for groups other than 'default' ?
+ // Drop custom field.
+ db_drop_field($ret, 'locales_target', 'update');
// Drop custom index.
- $ret = array();
db_drop_index($ret, 'locales_source', 'textgroup_location');
}
@@ -73,6 +81,13 @@ function i18nstrings_schema() {
function i18nstrings_schema_alter(&$schema) {
// Add index for textgroup and location to {locales_source}.
$schema['locales_source']['indexes']['textgroup_location'] = array(array('textgroup', 30), 'location');
+ // Add field for tracking whether translations need updating.
+ $schema['locales_target']['status'] = array(
+ 'description' => t('A boolean indicating whether this translation needs to be updated.'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ );
}
/**
@@ -111,3 +126,13 @@ function i18nstrings_update_6002() {
return $ret;
}
+/**
+ * Create i18n_strings_status schema.
+ * Add a field to track whether a translation needs updating.
+ */
+function i18nstrings_update_6003() {
+ $ret = array();
+ db_add_field($ret, 'locales_target', 'status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+ return $ret;
+}
+
diff --git a/i18nstrings/i18nstrings.module b/i18nstrings/i18nstrings.module
index c292c4a..33dc8c4 100644
--- a/i18nstrings/i18nstrings.module
+++ b/i18nstrings/i18nstrings.module
@@ -21,6 +21,16 @@
*/
/**
+ * Translated string is current.
+ */
+define('I18NSTRINGS_STATUS_CURRENT', 0);
+
+/**
+ * Translated string needs updating as the source has been edited.
+ */
+define('I18NSTRINGS_STATUS_UPDATE', 1);
+
+/**
* Implementation of hook_help().
*/
function i18nstrings_help($path, $arg) {
@@ -85,6 +95,23 @@ function i18nstrings_form_alter(&$form, $form_state, $form_id) {
}
}
break;
+ case 'locale_translate_edit_form':
+ $form['#submit'][] = 'i18nstrings_translate_edit_form_submit';
+ }
+}
+
+/**
+ * Process string editing form submissions.
+ *
+ * Mark translations as current.
+ */
+function i18nstrings_translate_edit_form_submit($form, &$form_state) {
+ $lid = $form_state['values']['lid'];
+ foreach ($form_state['values']['translations'] as $key => $value) {
+ if (!empty($value)) {
+ // An update has been made, so we assume the translation is now current.
+ db_query("UPDATE {locales_target} SET status = %d WHERE lid = %d AND language = '%s'", I18NSTRINGS_STATUS_CURRENT, $lid, $key);
+ }
}
}
@@ -310,9 +337,15 @@ function i18nstrings_add_string($name, $string) {
$status = -1;
if ($source) {
- if ($source->source != $string || $source->location != $location) {
- // String has changed or didnt have location.
- db_query("UPDATE {locales_source} SET source = '%s', location = '%s', version = version + 1 WHERE lid = %d", $string, $location, $source->lid);
+ if ($source->source != $string) {
+ // String has changed
+ db_query("UPDATE {locales_source} SET source = '%s', location = '%s' WHERE lid = %d", $string, $location, $source->lid);
+ db_query("UPDATE {locales_target} SET status = %d WHERE lid = %d", I18NSTRINGS_STATUS_UPDATE, $source->lid);
+ $status = SAVED_UPDATED;
+ }
+ elseif ($source->location != $location) {
+ // It's not changed but it didn't have location set
+ db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $location, $source->lid);
$status = SAVED_UPDATED;
}
// Update metadata.