Revision: 8844
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=8844&view=rev
Author:   dnaber
Date:     2013-01-04 22:46:36 +0000 (Fri, 04 Jan 2013)
Log Message:
-----------
use browser's default language to show a link to a translated page, if 
available; improve layout of text box slightly

Modified Paths:
--------------
    trunk/website/include/checkform.php
    trunk/website/www/index.php

Added Paths:
-----------
    trunk/website/include/browser_language.php

Added: trunk/website/include/browser_language.php
===================================================================
--- trunk/website/include/browser_language.php                          (rev 0)
+++ trunk/website/include/browser_language.php  2013-01-04 22:46:36 UTC (rev 
8844)
@@ -0,0 +1,39 @@
+<?php
+#########################################################
+# Copyright © 2008 Darrin Yeager                        #
+# http://www.dyeager.org/                               #
+# Licensed under BSD license.                           #
+#   http://www.dyeager.org/downloads/license-bsd.txt    #
+#########################################################
+
+function getDefaultLanguage() {
+   if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
+      return parseDefaultLanguage($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
+   else
+      return parseDefaultLanguage(NULL);
+}
+
+function parseDefaultLanguage($http_accept, $deflang = "en") {
+   if(isset($http_accept) && strlen($http_accept) > 1)  {
+      # Split possible languages into array
+      $x = explode(",",$http_accept);
+      foreach ($x as $val) {
+         #check for q-value and create associative array. No q-value means 1 
by rule
+         if(preg_match("/(.*);q=([0-1]{0,1}\.\d{0,4})/i",$val,$matches))
+            $lang[$matches[1]] = (float)$matches[2];
+         else
+            $lang[$val] = 1.0;
+      }
+
+      #return default language (highest q-value)
+      $qval = 0.0;
+      foreach ($lang as $key => $value) {
+         if ($value > $qval) {
+            $qval = (float)$value;
+            $deflang = $key;
+         }
+      }
+   }
+   return strtolower($deflang);
+}
+?>
\ No newline at end of file

Modified: trunk/website/include/checkform.php
===================================================================
--- trunk/website/include/checkform.php 2013-01-04 20:16:50 UTC (rev 8843)
+++ trunk/website/include/checkform.php 2013-01-04 22:46:36 UTC (rev 8844)
@@ -13,7 +13,7 @@
     <textarea 
             onfocus="javascript: if(document.checkform.text.value == '<?php 
print $checkDefaultText ?>') { document.checkform.text.value='' } " 
             onblur="javascript: if(document.checkform.text.value == '') { 
document.checkform.text.value='<?php print $checkDefaultText ?>' } " 
-        style="width:100%; height:70px" name="text"><?php print 
$checkDefaultText ?></textarea>
+        style="padding:5px;width:100%; height:70px" name="text"><?php print 
$checkDefaultText ?></textarea>
     <div style="margin-top:4px; text-align: right">
         <?php if ($showLanguageBox) { ?>
             Language: <select name="lang" id="lang" >

Modified: trunk/website/www/index.php
===================================================================
--- trunk/website/www/index.php 2013-01-04 20:16:50 UTC (rev 8843)
+++ trunk/website/www/index.php 2013-01-04 22:46:36 UTC (rev 8844)
@@ -2,9 +2,10 @@
 $page = "homepage";
 $title = "LanguageTool";
 $title2 = "Style and Grammar Checker";
-$lastmod = "2012-12-30 17:21:00 CET";
+$lastmod = "2013-01-04 23:21:00 CET";
 $enable_fancybox = 1;
 include("../include/header.php");
+include("../include/browser_language.php");
 ?>
 
 <a title="LanguageTool installed as an add-on in LibreOffice 3.3" 
class="fancyboxImage"
@@ -18,6 +19,20 @@
 <p>LanguageTool finds errors by looking for text patterns defined in an XML 
file. Alternatively, error detection
 rules can be written in Java.</p>
 
+<?php
+// language codes of languages that have their own page:
+$languagesWithPage = array("br", "ca", "zh", "eo", "de", "it", "pl", "ru");
+// names of those languages:
+$languageNamesWithPage = array("Breton", "Catalan", "Chinese", "Esperanto", 
"German", "Italian", "Polish", "Russian");
+$defaultLang = getDefaultLanguage();
+error_reporting(E_ALL);
+foreach ($languagesWithPage as $i => $value) {
+    if ($value == $defaultLang || substr($defaultLang, 0, 3) == $value."-") {
+      $langName = $languageNamesWithPage[$i];
+      print "<p style='width:50%;padding:10px;background-color:#f1ffa9'>Note: 
we also have a <a href='$value/'>page in $langName</a>.</p>";
+    }
+}
+?>
 
 <h2 style="margin-top: 40px">Try it online</h2>
 
@@ -64,8 +79,8 @@
 
           <ul style="padding-left: 20px">
             <li><strong>We strongly recommend using
-              <a href="http://www.libreoffice.org/download";>LibreOffice 
3.5.4</a></strong> or
-              <strong><a href="http://www.openoffice.org/download/";>Apache 
OpenOffice 3.4.1</a></strong> or later as older versions
+              <a href="http://www.libreoffice.org/download";>LibreOffice 
3.5.4</a></strong> (or later) or
+              <strong><a href="http://www.openoffice.org/download/";>Apache 
OpenOffice 3.4.1</a></strong> (or later) as older versions
               have a bug that causes a freeze on startup</li>
             <li>Use <em>Tools -&gt; Extension Manager -&gt; Add...</em> in 
LibreOffice/OpenOffice.org to install this file</li>
             <li><strong>Restart OpenOffice.org/LibreOffice</strong> after 
installation of the extension</li>

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits

Reply via email to