r19187 - htdocs/trunk - Fix multi-language search, patch by Tao Wang

Geert Janssens gjanssens at code.gnucash.org
Thu May 20 14:10:14 EDT 2010


Author: gjanssens
Date: 2010-05-20 14:10:14 -0400 (Thu, 20 May 2010)
New Revision: 19187
Trac: http://svn.gnucash.org/trac/changeset/19187

Modified:
   htdocs/trunk/Makefile
   htdocs/trunk/externals/header.phtml
   htdocs/trunk/externals/menu.phtml
   htdocs/trunk/lang.php
Log:
Fix multi-language search, patch by Tao Wang

Modified: htdocs/trunk/Makefile
===================================================================
--- htdocs/trunk/Makefile	2010-05-20 13:25:33 UTC (rev 19186)
+++ htdocs/trunk/Makefile	2010-05-20 18:10:14 UTC (rev 19187)
@@ -33,6 +33,7 @@
 LOCALFILE=local.php
 URLBASE=
 FILETAIL=
+LOCALE=
 FILE=
 HOME=http://www.gnucash.org$(URLBASE)
 TMPLBASE=search/templates/NMZ.
@@ -40,7 +41,8 @@
 # add when we have utf-8 translations: iconv -f UTF-8 -t ISO8859-1 
 
 nmz.onefile:
-	( cat $(TMPLBASE)$(FILE).php_tmpl ) | php -q > \
+	( echo '<?php $$locale = "$(LOCALE)"; ?>' ; \
+	  cat $(TMPLBASE)$(FILE).php_tmpl ) | php -q > \
 	  $(TMPLBASE)$(FILE)$(FILETAIL)
 
 nmz.lang:
@@ -53,5 +55,5 @@
 	# other NMZ langs not merged into po system: ja
 	# note: PL is only "mostly" translated.  it diff's differently
 	for l in en ${languages} ; do \
-	  $(MAKE) nmz.lang FILETAIL=.$$l ; \
+	  $(MAKE) nmz.lang FILETAIL=.$$l LOCALE=$$l; \
 	done

Modified: htdocs/trunk/externals/header.phtml
===================================================================
--- htdocs/trunk/externals/header.phtml	2010-05-20 13:25:33 UTC (rev 19186)
+++ htdocs/trunk/externals/header.phtml	2010-05-20 18:10:14 UTC (rev 19187)
@@ -7,16 +7,16 @@
 { ?>
   <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
 <?php } ?>
-<link rel="stylesheet" href="<?=$top_dir?>/externals/gnucash.css" type="text/css" />
-<link rel="icon" href="<?=$top_dir?>/favicon.ico" type="image/x-icon" />
-<link rel="shortcut icon" href="<?=$top_dir?>/favicon.ico" type="image/x-icon" />
+<link rel="stylesheet" href="<?=$home?>/externals/gnucash.css" type="text/css" />
+<link rel="icon" href="<?=$home?>/favicon.ico" type="image/x-icon" />
+<link rel="shortcut icon" href="<?=$home?>/favicon.ico" type="image/x-icon" />
 <?php echo $mimeline;  ?>
 <?php
 include("$top_dir/externals/global_params.php");
-$current_page = basename($_SERVER["SCRIPT_NAME"]);
+$current_page = array_key_exists('HTTP_HOST', $_SERVER) ? ($top_dir . "/" . basename($_SERVER["SCRIPT_NAME"])) : "";
 
 if (isset($homepage)) { ?>
-  <link rel="alternate" type="application/atom+xml" title="Atom Feed" href="<?=$top_dir?>/atom.php">
+  <link rel="alternate" type="application/atom+xml" title="Atom Feed" href="<?=$home?>/atom.php">
 <?php } ?>
 
 <title><?= T_($title); ?> | GnuCash</title>
@@ -25,23 +25,23 @@
 <body>
 
 <div id="head">
-<a href="<?=$home?>/"><!--img src="<?=$top_dir?>/externals/gnucash_logo1.png" alt="[GnuCash Logo]" id="gnclogo" width="179" height="45" border="0"/ -->
-<img src="<?=$top_dir?>/externals/banner5.png" width="453" height="45" />
+<a href="<?=$home?>/"><!--img src="<?=$home?>/externals/gnucash_logo1.png" alt="[GnuCash Logo]" id="gnclogo" width="179" height="45" border="0"/ -->
+<img src="<?=$home?>/externals/banner5.png" width="453" height="45" />
 </a>
 <br/>
 <span id="language">
 <?= T_("Language"); ?>:
-  <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=en_US">English</a>
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=de_DE">Deutsch</a>
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=es_ES">Espa&ntilde;ol</a>
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=fr_FR">Fran&ccedil;ais</a>
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=it_IT">Italiano</a>
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=ja_JP">日本語</a> <!-- Japanese -->
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=nl_NL">Nederlands</a>
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=nb_NO">Norsk Bokm&aring;l</a>
-<!-- | <a class="nav" href="<?=$top_dir;?>/pl/">Polska</a> -->
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=pt_PT">Portugu&ecirc;s</a>
-| <a class="nav" href="<?=$top_dir;?>/<?=$current_page;?>?lang=zh_CN">中文</a> <!-- Simplified Chinese -->
+  <a class="nav" href="<?=$current_path;?>?lang=en_US">English</a>
+| <a class="nav" href="<?=$current_path;?>?lang=de_DE">Deutsch</a>
+| <a class="nav" href="<?=$current_path;?>?lang=es_ES">Espa&ntilde;ol</a>
+| <a class="nav" href="<?=$current_path;?>?lang=fr_FR">Fran&ccedil;ais</a>
+| <a class="nav" href="<?=$current_path;?>?lang=it_IT">Italiano</a>
+| <a class="nav" href="<?=$current_path;?>?lang=ja_JP">日本語</a> <!-- Japanese -->
+| <a class="nav" href="<?=$current_path;?>?lang=nl_NL">Nederlands</a>
+| <a class="nav" href="<?=$current_path;?>?lang=nb_NO">Norsk Bokm&aring;l</a>
+<!-- | <a class="nav" href="<?=$current_path;?>?lang=pl_PL">Polska</a> -->
+| <a class="nav" href="<?=$current_path;?>?lang=pt_PT">Portugu&ecirc;s</a>
+| <a class="nav" href="<?=$current_path;?>?lang=zh_CN">中文</a> <!-- Simplified Chinese -->
 </span>
 <span id="location">&nbsp; <!-- <?= _("Continent"); ?>:
  (<a class="nav" href="http://www.gnucash.org/">US</a>)

Modified: htdocs/trunk/externals/menu.phtml
===================================================================
--- htdocs/trunk/externals/menu.phtml	2010-05-20 13:25:33 UTC (rev 19186)
+++ htdocs/trunk/externals/menu.phtml	2010-05-20 18:10:14 UTC (rev 19187)
@@ -1,25 +1,19 @@
-<?php
-$self = $_SERVER["HTTP_HOST"];
-if (ereg("lists.gnucash.org", $self)) {
-  $home = "http://www.gnucash.org";
-}
-?>
 <div id="news">
 <div class="othernews">
   <span class="linktop">
-    <img class="dot" src="<?=$top_dir?>/externals/webding.png" alt="marker">
+    <img class="dot" src="<?=$home?>/externals/webding.png" alt="marker">
     <b><?= T_("Information")?></b>
   </span>
   <ul>
     <li><a href="<?=$home?>/index.phtml"><?= T_("About / News")?></a></li>
-    <li><a href="<?=$home?>/atom.php"><img src="<?=$top_dir?>/externals/feed-icon-12x12.png" width="12" height="12" alt="[atom feed]" /> <?= T_("News Feed")?></a></li>
+    <li><a href="<?=$home?>/atom.php"><img src="<?=$home?>/externals/feed-icon-12x12.png" width="12" height="12" alt="[atom feed]" /> <?= T_("News Feed")?></a></li>
     <li><a href="<?=$home?>/features.phtml"><?=T_("Screenshots, Features")?></a></li>
     <li><a href="http://wiki.gnucash.org/wiki/Development"><?= T_("How to help")?></a></li>
   </ul>
 </div>
 <div class="othernews">
   <span class="linktop">
-    <img class="dot" src="<?=$top_dir?>/externals/webding.png" alt="marker" />
+    <img class="dot" src="<?=$home?>/externals/webding.png" alt="marker" />
     <b><?=T_("Documentation")?></b></span>
     <ul>
       <li><a href="<?=$home?>/docs.phtml"><?=T_("Documentation")?></a></li>
@@ -28,7 +22,7 @@
       <a href="http://wiki.gnucash.org/wiki/De/GnuCash">[de]</a></li>
       <li><a href="http://wiki.gnucash.org/wiki/Mailing_Lists"><?=T_("Mailing Lists")?></a>
       <li style="list-style-image:none;list-style-type:none;"><ul>
-        <li><a href="https://lists.gnucash.org/search/<? if ($lang_dir != "") { echo "$lang_dir/"; } ?>"><?=T_("Search")?></a></li>
+        <li><a href="https://lists.gnucash.org/search/<? if ($locale != "") { echo "?lang=$locale"; } ?>"><?=T_("Search")?></a></li>
       </ul></li>
       <li><a href="http://wiki.gnucash.org/wiki/Bugzilla"><?=T_("Bug Reports")?></a></li>
       <li><a href="http://wiki.gnucash.org/wiki/IRC"><?=T_("IRC (Chat)")?></a></li>
@@ -38,7 +32,7 @@
 <div class="othernews">
   <!-- ?php include("$top_dir/externals/menu-downloads.phtml");? -->
   <span class="linktop">
-    <img class="dot" src="<?=$top_dir?>/externals/webding.png" alt="marker" />
+    <img class="dot" src="<?=$home?>/externals/webding.png" alt="marker" />
     <b><a href="<?=$home?>/download.phtml"><?=T_("Downloads")?></a></b>
     <ul></ul>
   </span>
@@ -46,7 +40,7 @@
 <div class="othernews">
   <!-- ?php include("$top_dir/externals/menu-developer.phtml");? -->
   <span class="linktop">
-    <img class="dot" src="<?=$top_dir?>/externals/webding.png" alt="marker">
+    <img class="dot" src="<?=$home?>/externals/webding.png" alt="marker">
     <b><?=T_("Developer Information")?></b>
   </span>
   <ul>

Modified: htdocs/trunk/lang.php
===================================================================
--- htdocs/trunk/lang.php	2010-05-20 13:25:33 UTC (rev 19186)
+++ htdocs/trunk/lang.php	2010-05-20 18:10:14 UTC (rev 19187)
@@ -1,10 +1,24 @@
 <?php
 $top_dir = ".";
-$home = $top_dir;
 $locale_dir = "locale";
 
+if (!array_key_exists('HTTP_HOST', $_SERVER) || ($_SERVER["HTTP_HOST"] == "lists.gnucash.org"))
+{
+    $home = "http://www.gnucash.org";
+}else{
+    $home = $top_dir;
+}
+
+if ( !isset($locale) ) { $locale = ""; }
+if ( !isset($lang_dir) ) { $lang_dir = $locale; }
+
 # get the cookie setting
-if (array_key_exists('lang_cookie', $_COOKIE)) { $locale = $_COOKIE['lang_cookie']; }
+if (array_key_exists('lang_cookie', $_COOKIE)) {
+    $locale = $_COOKIE['lang_cookie'];
+    $lang_cookie = $locale;
+}else{
+    $lang_cookie = "";
+}
 
 # allow user override.
 if (array_key_exists('lang', $_GET)) { $locale = $_GET["lang"]; }
@@ -22,6 +36,20 @@
         'zh_CN' => 'zh_CN', 'en_US' => 'en'
         );
 
+# Find the full locale name for short language name.
+if (strlen($locale) == 2) {
+    foreach($supported_languages as $loc_lang => $loc_dir)
+    {
+        if ( (strtolower($locale) == strtolower($loc_dir))
+            || (strtolower($locale) == substr($loc_lang, 0, 2 )) )
+        {
+            $locale = $loc_lang;
+            break;
+        }
+    }
+}
+
+# Find the locale from Client Accept language
 if ($locale == "") {
         # Get user prefered languages, and match agasint supported language
         if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
@@ -66,6 +94,5 @@
 
 T_textdomain($domain);
 
-$lang_cookie = $_COOKIE['lang_cookie'];
 echo ("<!-- $locale , locale_res [$locale_res] , dir_res $dir_res, lang_cookie [$lang_cookie] -->\n");
 ?>



More information about the gnucash-changes mailing list