********************************************************************
INSTALLATION:
-1. Copy i18n.module to the modules folder
-2. Copy i18n.inc to the includes folder
-3. Copy the files in flags folder to misc/flags
-4. To use url rewriting, this line should be added to your configuration file:
+1. Create folder 'modules/i18n'
+2. Copy all the modules files, keeping directory structure, to the folder 'modules/i18n/'
+3. To use url rewriting, this line should be added to your configuration file:
-include 'includes/i18n.inc'
+include 'modules/i18n/i18n.inc'
+
+4. For content translation, this module can manage language dependent tables. Yo need to:
+<warning> This feature is experimental</warning>
+4.1. Modify $db_prefix in .conf file. This is a sample:
+
+ $db_prefix=array{
+ 'default' => 'prefix_', // The default prefix
+ 'node' => 'prefix_**_' // '**' will be replaced by language code at runtime.
+ }
+
+4.2. Create table copys for each language: prefix_es_node, prefix_en_node, etc...
+
+*Any* table can be made language dependant. Just think about whether it makes sense.
+Suggested tables to be made language dependant are node tables, taxonomy tables....
-No modification to the database is required
This module provides support for internationalization of Drupal sites in various ways:
* Translation of the user interface for registered and anonymous users
- * Multi-language for content, combined with url aliasing. For this feature to be used, you must enable it in the module configuration and then use url aliasing to keep pages in various languages. I.e. 'en/mypage', 'es/mypage' should be English and Spanish versions of the same page
+ * Basic multi-language using URL Aliasing, combined with url aliasing. See below.
+ * [EXPERIMENTAL, see INSTALL file] Advanced multi-language using duplicated tables. Selected tables will be made language dependent.
* Detection of the brower language
* Keeps the language settings accross consecutive requests, using a number of methods: URL rewriting, sessions, cookies
* Provides a block for language selection and two theme functions: i18n_flags and i18n_links
theme("i18n_flags") -> Adds just a row with the flags
theme("i18n_links",$flags,$names,$delim1,$delim2) -> Check documentation in the code for different options
+About Multi-Language:
+ There are currently two options to build multi-language sites:
+
+ 1. With URL aliasing - using path module's Custom URLs and i18n's URL rewriting feature
+ You have to create a Custom URL for each language version of a node:
+ I.e. 'en/mypage', 'es/mypage' should be English and Spanish versions of the same page
+ The link to display this page will be only 'mypage'. The language code will be added automatically.
+
+ 2. With duplicated tables [Only in HEAD CVS version of the module]
+ You can keep separated tables -the ones you choose- for each language. You have to create the tables manually and add them to $db_prefix. See INSTALL file.
+ * This feature uses db prefixing (An idea taken from Walkah's translate_node module) to keep separated tables for each language.
+ ** When using language dependent tables other than 'node', some manual synchronization may be needed.
+ *** Currently, the synchronization between languages is only automatic for the node table.
+
Jose A. Reyero, drupal at reyero dot net
function i18n_init(){
global $i18n_langpath;
-
+
// Quick fix, check if called from bootstrap.inc
if(!function_exists("drupal_get_path_map")) return 0;
}else{
$lang= i18n_get_default_lang();
}
-
- if(variable_get("i18n_interface",0)) i18n_set_default_lang($lang);
if(variable_get("i18n_content",0)){
- $original=i18n_get_original_path();
+ i18n_set_db_prefix($lang);
+ $original=i18n_get_original_path();
if(!$i18n_langpath && $trpath=i18n_get_normal_path("$lang/$original")){
$_GET["q"]=$trpath;
}elseif(!$original || $i18n_langpath==$original){
$_GET["q"]=drupal_get_normal_path(i18n_front_page($lang));
}
}
+
+ if(variable_get("i18n_interface",0)) i18n_set_default_lang($lang);
+
+}
+
+function i18n_set_db_prefix($lang){
+ global $db_prefix,$i18n_db_prefix;
+ if(!$i18n_db_prefix) $i18n_db_prefix=$db_prefix;
+ $db_prefix=str_replace('**',$lang,$db_prefix);
+ //var_dump($db_prefix);
}
+
function i18n_front_page($lang){
return variable_get("i18n_front_page",0) ? $lang.'/'.variable_get('site_frontpage','node') : variable_get('site_frontpage','node');
}
+
function i18n_help($section = "admin/help#i18n") {
switch ($section) {
case "admin/help#i18n":
function i18n_settings(){
$output .= form_radios(t("Interface translation"),"i18n_interface",variable_get("i18n_interface",0),array(t("Disabled"),t("Enabled")),t("If disabled, uses Drupal's default. If enabled, translates the interface to selected language"));
$output .= form_radios(t("Content translation"),"i18n_content",variable_get("i18n_content",0),array(t("Disabled"),t("Enabled")),t("If enabled, prepends language code to url and searches for translated content"));
+ $output .= form_group(t("Synchronize content")." <strong>EXPERIMENTAL FEATURE</strong>"
+ ,form_checkbox(t("Nodes"),"i18n_sync_nodes",1,variable_get("i18n_sync_nodes",0))
+ .form_checkbox(t("Taxonomy"),"i18n_sync_taxonomy",1,variable_get("i18n_sync_taxonomy",0))
+ ,t("Synchronize tables for different languages. When some element is created/removed, it will be created/removed for all languages with the same id")
+ );
$output .= form_select(t("Front page"),"i18n_front_page",variable_get("i18n_front_page",0),array(t("Default"),t("Language dependant")),t("If language dependant and <i>Content translation</i> is enabled, default front page will be prepended with language code, i.e. 'en/node'"));
$output .=form_radios(t("Keep Language"),"i18n_keep",variable_get("i18n_keep",'url'),
array( ""=>t("Disabled"),
"cookie" => t("Cookie")
),t("A language code independent of user's language will be kept accross requests using the selected method"));
$output .= form_radios(t("Detect browser language"),"i18n_browser",variable_get("i18n_browser",0),array(t("Disabled"),t("Enabled")));
- $output .= form_textfield(t("Flags directory"),"i18n_flags",variable_get("i18n_flags","misc/flags/*.gif"),70,180,t("Path for flags. Asterisk '*' is a placeholder for language code. This is only needed when you want a language selector block"));
+ $output .= form_textfield(t("Flags directory"),"i18n_flags",variable_get("i18n_flags","modules/i18n/flags/*.gif"),70,180,t("Path for flags. Asterisk '*' is a placeholder for language code. This is only needed when you want a language selector block"));
return $output;
}
}
function _i18n_flag($lang,$attribs=array()){
- if($path=variable_get("i18n_flags","misc/flags/*.gif")){
+ if($path=variable_get("i18n_flags","modules/i18n/flags/*.gif")){
$flag=str_replace("*",$lang,$path);
return "<img class=\"i18n\" src=\"$flag\"".drupal_attributes($attribs)." />";
}
return $result;
}
+
+function i18n_nodeapi(&$node, $op, $arg = 0) {
+ global $languages, $i18n_lang;
+
+ if(variable_get('i18n_sync_nodes',0) && $db_prefix_i18n['node']){
+ switch ($op) {
+ case 'insert':
+ $fields = node_invoke_nodeapi($node, "fields");
+
+ // Prepare the query:
+ foreach ($node as $key => $value) {
+ if (in_array($key, $fields)) {
+ $k[] = check_query($key);
+ $v[] = $value;
+ $s[] = "'%s'";
+ }
+ }
+
+ $keysfmt = implode(", ", $s);
+ // need to quote the placeholders for the values
+ $valsfmt = "'". implode("', '", $s) ."'";
+
+ // Insert copies for each language
+ foreach ($languages as $lang => $desc) {
+ if ($lang != $i18n_lang) {
+ // fake the next id to keep sequences in step
+ $node_table=i18n_get_table('node',$lang);
+ db_next_id($node_table.'_nid');
+ db_query("INSERT INTO $node_table (". implode(", ", $k) .") VALUES(". implode(", ", $s) .")", $v);
+ }
+ }
+ break;
+
+ case 'delete':
+ foreach ($languages as $lang => $desc) {
+ if ($lang != $i18n_lang) {
+ $node_table=i18n_get_table('node',$lang);
+ db_query("DELETE FROM $node_table WHERE nid='%s'", $node->nid);
+ }
+ }
+ }
+ }
+}
+
+function i18n_get_table($table,$lang){
+ global $i18n_db_prefix;
+ if($db_prefix_i18n[$table]) {
+ return str_replace('**',$lang,$db_prefix_i18n[$table]).$table;
+ } elseif(is_array($db_prefix_i18n)){
+ return str_replace('**',$lang,$db_prefix_i18n['default']).$table;
+ } elseif(is_string($db_prefix_i18n)){
+ return str_replace('**',$lang,$db_prefix_i18n).$table;
+ } else {
+ return $table;
+ }
+}
+
+
?>
\ No newline at end of file