--- F:/WebServers/home/api/www/modules/api/api_old.module Fri Jan 25 20:34:44 2008 +++ F:/WebServers/home/api/www/modules/api/api.module Sat May 31 09:49:20 2008 @@ -24,6 +24,53 @@ */ define('API_RE_FILENAME', '([a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)+)'); + +/** + * This function breaks a string on chunks by paragraphs or headers and + * than puts all of them into the t() function. After that, it implodes + * all of the chunks and returns translated result to the api module. + */ +function localize_paragraphs($s){ + if ((arg(1)=='file')&&(arg(2)=='topics')){ + return $s; + } else { + $tags = array('p','h2','h3','h4','h5'); + foreach ($tags as $tag){ + $s = str_replace('','#####',$s); + } + + $arr = explode("#####",$s); + $new = array(); + foreach ($arr as $str){ + $str = _open_tags(trim($str),$tags,$b,$e); + + if ($str){ + //We don't need function names in translation queue + if (!((strpos($str,' ') === FALSE)&&(strpos($str,'()') === strlen($str)-2))) { + $new[] = $b.t($str).$e; + } else { + $new[] = $b.$str.$e; + } + } + } + return (implode("\n",$new)); + } +} + +function _open_tags($str, $tags, &$b, &$e){ + foreach ($tags as $tag){ + if (strpos($str,'<'.$tag.'>')!==FALSE){ + $str = str_replace('<'.$tag.'>','',$str); + $str = str_replace('','',$str); + $b = '<'.$tag.'>'; + $e = ''; + } + break; + } + $str = trim($str); + return ($str); +} + /** * Implementation of hook_help() */ @@ -640,6 +687,8 @@ $rows = array(); while ($object = db_fetch_object($result)) { $row = array(); + if ($object->object_type == 'group') + $object->title = t($object->title); $row[] = l($object->title, 'api/'. $object->object_type .'/'. $object->object_name .'/'. $object->branch_name); $row[] = l(str_replace('/', '/ ', $object->file_name), 'api/file/'. $object->file_name .'/'. $object->branch_name); $row[] = api_link_documentation($object->summary, $object->branch_name); @@ -696,7 +745,7 @@ $result = db_query("SELECT d.object_name, d.title, d.summary FROM {api_reference_storage} r INNER JOIN {api_documentation} d ON r.to_did = d.did AND d.object_type = 'group' WHERE r.from_did = %d". tablesort_sql($headers), $function->did); while ($group = db_fetch_object($result)) { $rows[] = array( - l($group->title, 'api/group/'. $group->object_name .'/'. $branch_name), + l(t($group->title), 'api/group/'. $group->object_name .'/'. $branch_name), api_link_documentation($group->summary, $branch_name)); } if (count($rows) > 0) { @@ -732,7 +781,7 @@ $result = db_query("SELECT d.object_name, d.title, d.summary FROM {api_reference_storage} r INNER JOIN {api_documentation} d ON r.to_did = d.did AND d.object_type = 'group' WHERE r.from_did = %d". tablesort_sql($headers), $function->did); while ($group = db_fetch_object($result)) { $rows[] = array( - l($group->title, 'api/group/'. $group->object_name .'/'. $branch_name), + l(t($group->title), 'api/group/'. $group->object_name .'/'. $branch_name), api_link_documentation($group->summary, $branch_name)); } if (count($rows) > 0) { @@ -799,7 +848,7 @@ $result = db_query("SELECT d.object_name, d.title, d.summary FROM {api_reference_storage} r INNER JOIN {api_documentation} d ON r.to_did = d.did AND d.object_type = 'group' WHERE r.from_did = %d". tablesort_sql($headers), $constant->did); while ($group = db_fetch_object($result)) { $rows[] = array( - l($group->title, 'api/group/'. $group->object_name .'/'. $branch_name), + l(t($group->title), 'api/group/'. $group->object_name .'/'. $branch_name), api_link_documentation($group->summary, $branch_name)); } if (count($rows) > 0) { @@ -843,7 +892,7 @@ $result = db_query("SELECT d.object_name, d.title, d.summary FROM {api_reference_storage} r INNER JOIN {api_documentation} d ON r.to_did = d.did AND d.object_type = 'group' WHERE r.from_did = %d". tablesort_sql($headers), $global->did); while ($group = db_fetch_object($result)) { $rows[] = array( - l($group->title, 'api/group/'. $group->object_name .'/'. $branch_name), + l(t($group->title), 'api/group/'. $group->object_name .'/'. $branch_name), api_link_documentation($group->summary, $branch_name)); } if (count($rows) > 0) { @@ -1009,7 +1058,7 @@ $output .= theme('table', $headers, $rows); } - drupal_set_title($group->title); + drupal_set_title(t($group->title)); return $output; } else { @@ -1285,6 +1334,7 @@ * identifiers which are linked frequently change. */ function api_link_documentation($documentation, $branch_name) { + $documentation = localize_paragraphs($documentation); return _api_link_documentation($documentation, $branch_name, array('tags', 'function', 'file')); }