summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNedjo Rogers2009-01-20 20:35:55 (GMT)
committer Nedjo Rogers2009-01-20 20:35:55 (GMT)
commitac152d40909de170c7a407f14dd7973f7d65c252 (patch)
tree722e001f710db628a46fe6746b3dc92f34299e49
parent5b8132f40af0cddd7d0a3dec98307a7ac52bae97 (diff)
Issue #314721, fix nodereference issue in translations.
-rw-r--r--i18n.js17
-rw-r--r--i18n.module52
2 files changed, 69 insertions, 0 deletions
diff --git a/i18n.js b/i18n.js
new file mode 100644
index 0000000..c84192f
--- /dev/null
+++ b/i18n.js
@@ -0,0 +1,17 @@
+// $Id$
+
+/**
+ * Rewrite autocomplete inputs to pass the language of the node currently being
+ * edited in the path.
+ *
+ * This functionality ensures node autocompletes get suggestions for the node's
+ * language rather than the current interface language.
+ */
+Drupal.behaviors.i18n = function (context) {
+ if (Drupal.settings && Drupal.settings.i18n) {
+ $('form[id^=node-form]', context).find('input.autocomplete[value^=' + Drupal.settings.i18n.interface_path + ']').each(function () {
+ $(this).val($(this).val().replace(Drupal.settings.i18n.interface_path, Drupal.settings.i18n.content_path));
+ });
+ }
+};
+
diff --git a/i18n.module b/i18n.module
index a7d5502..85a489c 100644
--- a/i18n.module
+++ b/i18n.module
@@ -262,6 +262,58 @@ function i18n_user($op, &$edit, &$account, $category = NULL) {
}
/**
+ * Implementation of hook_elements().
+ *
+ * Add a process callback for textfields.
+ */
+function i18n_elements() {
+ $type = array();
+ $type['textfield'] = array('#process' => array('i18n_textfield_process'));
+ return $type;
+}
+
+/**
+ * Process callback for textfield elements.
+ *
+ * When editing or translating a node, set Javascript to rewrite autocomplete
+ * paths to use the node language prefix rather than the current content one.
+ */
+function i18n_textfield_process($element) {
+ global $language;
+ static $sent = FALSE;
+
+ // Ensure we send the Javascript only once.
+ if (!$sent && isset($element['#autocomplete_path']) && !empty($element['#autocomplete_path']) && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) != LANGUAGE_NEGOTIATION_NONE) {
+ // Add a JS file for node forms.
+ // Determine if we are either editing or translating an existing node.
+ // We can't act on regular node creation because we don't have a specified
+ // node language.
+ $node_edit = $node = menu_get_object() && arg(2) == 'edit' && isset($node->language) && !empty($node->language);
+ $node_translate = arg(0) == 'node' && arg(1) == 'add' && !empty($_GET['translation']) && !empty($_GET['language']);
+ if ($node_edit || $node_translate) {
+ $node_language = $node_edit ? $node->language : $_GET['language'];
+ // Only needed if the node language is different from the interface one.
+ if ($node->language != $language->language) {
+ $languages = language_list();
+ if (isset($languages[$node_language])) {
+ drupal_add_js(drupal_get_path('module', 'i18n') . '/i18n.js');
+ // Pass the interface and content language base paths.
+ // Remove any trailing forward slash. Doing so prevents a mismatch
+ // that occurs when a language has no prefix and hence gets a path
+ // with a trailing forward slash.
+ $interface = rtrim(url('', array('absolute' => TRUE)), '/');
+ $content = rtrim(url('', array('absolute' => TRUE, 'language' => $languages[$node_language])), '/');
+ $data = array('interface_path' => $interface, 'content_path' => $content);
+ drupal_add_js(array('i18n' => $data), 'setting');
+ }
+ }
+ }
+ $sent = TRUE;
+ }
+ return $element;
+}
+
+/**
* Simple i18n API
*/