summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Reyero2007-02-03 00:16:34 (GMT)
committer Jose Reyero2007-02-03 00:16:34 (GMT)
commit4113023daa3c41d96757dcbd1e148c380e465cb0 (patch)
treec449e8ad701a75bbdf7ccb3f36e761818950c74f
parent02f90a558163c15b59b4124e677defd64cf24d78 (diff)
Implemented: language switch after user login
Implemented: terms with no language copied over when translating Fixed http://drupal.org/node/114386 (wrong default language) Fixed http://drupal.org/node/104020 (taxonomy query error in postgres) Added version to info files
-rw-r--r--CHANGELOG.txt5
-rw-r--r--i18n.info2
-rw-r--r--i18n.module151
-rw-r--r--translation/translation.info2
-rw-r--r--translation/translation.module30
5 files changed, 108 insertions, 82 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 4e1dd2f..1fa31ae 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,5 +1,10 @@
4-7-4 to 5-0
--------------
+- Added terms with no language for translations
+- Added: Switch to user's language after login
+- Fixed bug with default language
+29/01/2007
+- Added automatic taxonomy translation when translating nodes
- Added language session tracking
- Added per language menu items
- Added support for RTL languages
diff --git a/i18n.info b/i18n.info
index f402c4a..678b775 100644
--- a/i18n.info
+++ b/i18n.info
@@ -2,4 +2,4 @@ name = Internationalization
description = Enables multilingual content.
dependencies = locale
package = Multilanguage - i18n
-version = 5.0 dev \ No newline at end of file
+version = "$Name$" \ No newline at end of file
diff --git a/i18n.module b/i18n.module
index 62f52ec..8f599ed 100644
--- a/i18n.module
+++ b/i18n.module
@@ -2,6 +2,7 @@
// $Id$
/**
+ * @file
* Internationalization (i18n) module
*
* @author Jose A. Reyero, 2004
@@ -82,7 +83,7 @@ function i18n_init(){
$_GET['q'] = i18n_frontpage($lang);
}
} elseif ($lang == $path) { // When path is only language code
- $_GET['q'] = i18n_frontpage($lang);
+ $_GET['q'] = i18n_frontpage($lang);
}
elseif ($i18n_langpath) {
//search alias with and without lang and remove lang.
@@ -203,7 +204,7 @@ function i18n_taxonomy($op, $type, $edit = NULL) {
$language = isset($edit['language']) ? $edit['language'] : '';
db_query("UPDATE {vocabulary} SET language='%s' WHERE vid=%d", $language, $edit['vid']);
if ($language && $op == 'update') {
- db_query("UPDATE {term_data} t SET t.language='%s' WHERE t.vid=%d", $edit['language'], $edit['vid']);
+ db_query("UPDATE {term_data} SET language='%s' WHERE vid=%d", $edit['language'], $edit['vid']);
drupal_set_message(t('Reset language for all terms.'));
}
break;
@@ -211,6 +212,18 @@ function i18n_taxonomy($op, $type, $edit = NULL) {
}
/**
+ * Implementation of hook_user()
+ *
+ * Switch to user's language after login
+ */
+function i18n_user($op, &$edit, &$account, $category = NULL) {
+ if($op == 'login' && $account->language) {
+ $_SESSION['language'] = $account->language;
+ i18n_get_lang($account->language);
+ }
+}
+
+/**
* Form builder function.
*
* Some options have been removed from previous versions:
@@ -473,69 +486,6 @@ function i18n_get_links($path = '', $query = NULL) {
}
/**
- * Gets language, checking in order:
- *
- * 1. Path language
- * 2. Session language
- * 3. User language
- * 4. Browser language
- * 5. Default language
- */
-
-function _i18n_get_lang() {
- global $user, $i18n_langpath;
- static $i18n_lang;
- // Check whether the language is already set.
- if ($i18n_lang) {
- return $i18n_lang;
- }
- // Language not set, find one
- $languages = i18n_supported_languages();
- if ($i18n_langpath && array_key_exists($i18n_langpath,$languages)) {
- // Sets session language only when language is in path, not for other cases
- $_SESSION['language'] = $i18n_lang = $i18n_langpath;
- }
- elseif (isset($_SESSION['language']) && array_key_exists($_SESSION['language'], $languages)) {
- $i18n_lang = $_SESSION['language'];
- }
- elseif ($user->uid && $user->language && array_key_exists($user->language,$languages)) {
- $i18n_lang = $user->language;
- }
- elseif (variable_get("i18n_browser",0) && $lang=i18n_get_browser_lang()) {
- $i18n_lang=$lang;
- }
- else {
- $i18n_lang=key($languages);
- }
- return $i18n_lang;
-}
-
-/**
- * Check whether we are in bootstrap mode
- */
-function _i18n_is_bootstrap(){
- return !function_exists('drupal_get_headers');
-}
-
-/**
- * Sets db_prefix to given language
- */
-function _i18n_set_db_prefix($lang) {
- global $db_prefix, $db_prefix_i18n;
- if (is_array($db_prefix_i18n)) {
- $db_prefix = array_merge($db_prefix, str_replace('**', $lang, $db_prefix_i18n));
- }
-}
-
-/**
- * To get the original path.
- * Cannot use $_GET["q"] cause it may have been already changed
- */
-function _i18n_get_original_path() {
- return isset($_REQUEST["q"]) ? trim($_REQUEST["q"],"/") : '';
-}
-
-/**
* Returns list of enabled languages from locale module
*
* Some code borrowed from locale module.
@@ -983,6 +933,44 @@ function i18n_variable_del($name, $language) {
}
/**
+ * Gets language, checking in order:
+ *
+ * 1. Path language
+ * 2. Session language
+ * 3. User language
+ * 4. Browser language
+ * 5. Default language
+ */
+function _i18n_get_lang() {
+ global $user, $i18n_langpath;
+ static $i18n_lang;
+ // Check whether the language is already set.
+ if ($i18n_lang) {
+ return $i18n_lang;
+ }
+ // Language not set, find one
+ $languages = i18n_supported_languages();
+
+ if ($i18n_langpath && array_key_exists($i18n_langpath,$languages)) {
+ // Sets session language only when language is in path, not for other cases
+ $_SESSION['language'] = $i18n_lang = $i18n_langpath;
+ }
+ elseif (isset($_SESSION['language']) && array_key_exists($_SESSION['language'], $languages)) {
+ $i18n_lang = $_SESSION['language'];
+ }
+ elseif ($user->uid && $user->language && array_key_exists($user->language,$languages)) {
+ $i18n_lang = $user->language;
+ }
+ elseif (variable_get("i18n_browser",0) && $lang=i18n_get_browser_lang()) {
+ $i18n_lang=$lang;
+ }
+ else {
+ $i18n_lang= i18n_default_language();
+ }
+ return $i18n_lang;
+}
+
+/**
* Helper function to create language selector
*/
function _i18n_language_select($value ='', $description ='', $weight = -20){
@@ -996,6 +984,9 @@ function _i18n_language_select($value ='', $description ='', $weight = -20){
);
}
+/**
+ * Load language variables into array
+ */
function _i18n_variable_init(){
$lang = _i18n_get_lang();
$variables = array();
@@ -1009,9 +1000,7 @@ function _i18n_variable_init(){
}
cache_set('variables:'.$lang, 'cache', serialize($variables));
}
-
- return $variables;
-
+ return $variables;
}
/**
@@ -1037,3 +1026,29 @@ function _i18n_variable_exit(){
}
}
}
+
+/**
+ * Check whether we are in bootstrap mode
+ */
+function _i18n_is_bootstrap(){
+ return !function_exists('drupal_get_headers');
+}
+
+/**
+ * Sets db_prefix to given language
+ */
+function _i18n_set_db_prefix($lang) {
+ global $db_prefix, $db_prefix_i18n;
+ if (is_array($db_prefix_i18n)) {
+ $db_prefix = array_merge($db_prefix, str_replace('**', $lang, $db_prefix_i18n));
+ }
+}
+
+/**
+ * To get the original path.
+ * Cannot use $_GET["q"] cause it may have been already changed
+ */
+function _i18n_get_original_path() {
+ return isset($_REQUEST["q"]) ? trim($_REQUEST["q"],"/") : '';
+}
+
diff --git a/translation/translation.info b/translation/translation.info
index 8fbda1d..a8d613b 100644
--- a/translation/translation.info
+++ b/translation/translation.info
@@ -2,4 +2,4 @@ name = Translation
description = Manages translations between nodes and taxonomy terms.
dependencies = i18n
package = Multilanguage - i18n
-version = 5.0 dev
+version = "$Name$"
diff --git a/translation/translation.module b/translation/translation.module
index d81950f..0525d02 100644
--- a/translation/translation.module
+++ b/translation/translation.module
@@ -162,7 +162,6 @@ function translation_block($op = 'list', $delta = 0) {
* Implementation of hook_form_alter().
*/
function translation_form_alter($form_id, &$form) {
- // drupal_set_message('translation_form_alter');
// Node edit form
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && variable_get('i18n_node_'.$form['type']['#value'], 0)) {
$node = $form['#node'];
@@ -239,21 +238,28 @@ function translation_form_alter($form_id, &$form) {
}
}
// Translate taxonomy terms
- // TO-DO: take care of module order. Default ordering is filename so it depends on install which is too bad!!
if(isset($trans->taxonomy) && is_array($trans->taxonomy)) {
// Set translated taxonomy terms
- $form['#node']->taxonomy = array();
+ $taxonomy = array();
foreach ($trans->taxonomy as $tid => $term) {
- $translated_terms = translation_term_get_translations(array('tid' =>$tid));
- if ($translated_terms && $newterm = $translated_terms[$language]) {
- $form['#node']->taxonomy[$newterm->tid] = $newterm;
- //drupal_set_message("DEBUG: Translated term $tid to ". $newterm->tid);
- }
- // Run again taxonomy_form_alter ?
- if(isset($form['taxonomy'])) {
- unset($form['taxonomy']);
- taxonomy_form_alter($form_id, $form);
+ if ($term->language) {
+ $translated_terms = translation_term_get_translations(array('tid' =>$tid));
+ if($translated_terms && $newterm = $translated_terms[$language]) {
+ $taxonomy[$newterm->tid] = $newterm;
+ //drupal_set_message("DEBUG: Translated term $tid to ". $newterm->tid);
+ }
+ } else {
+ // Term has no language. Should be ok
+ $taxonomy[$tid] = $term;
}
+ }
+ $form['#node']->taxonomy = $taxonomy;
+
+ // Run again taxonomy_form_alter. Better yes so we don't mess with module weights
+ // TO-DO: take care of module order. Default ordering is filename so it depends on install which is too bad!!
+ if (isset($form['taxonomy'])) {
+ unset($form['taxonomy']);
+ taxonomy_form_alter($form_id, $form);
}
}
}