[gnomeweb-wp] adapt website footer to support selection of languages when available



commit 59c18b6b9e3c3522a462ea93a43ca137b5a4bd4a
Author: Vinicius Depizzol <vdepizzol gmail com>
Date:   Sat Jun 18 18:28:11 2011 -0300

    adapt website footer to support selection of languages when available

 wp-content/themes/gnome-grass/footer.php           |   33 ++++++++---
 wp-content/themes/gnome-grass/functions.php        |   10 +++
 wp-content/themes/gnome-grass/header.php           |    4 +-
 .../themes/gnome-grass/images/footer-map.png       |  Bin 7599 -> 6856 bytes
 wp-content/themes/gnome-grass/index.php            |    8 ++-
 wp-content/themes/gnome-grass/js/template.js       |    9 ++-
 .../themes/gnome-grass/language-selector.php       |   51 +++++++++--------
 wp-content/themes/gnome-grass/style.css            |   60 +++++++++++++++----
 8 files changed, 123 insertions(+), 52 deletions(-)
---
diff --git a/wp-content/themes/gnome-grass/footer.php b/wp-content/themes/gnome-grass/footer.php
index 45c21d1..0464516 100644
--- a/wp-content/themes/gnome-grass/footer.php
+++ b/wp-content/themes/gnome-grass/footer.php
@@ -12,22 +12,35 @@
                 ?>
             </div>
             
-            <?php
-            /* Hide this since we won't have translated content in time */
-            /*
-            <div class="language grid_3">
-                <div>
-                    <strong><?php _e( 'This website is available in many languages', 'grass' ); ?></strong><br />
-                    <a href="<?php bloginfo('stylesheet_directory'); ?>/language-selector.php" class="map"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/footer-map.png" alt="<?php _e( 'Switch Language', 'grass' ); ?>" title="<?php _e( 'Switch Language', 'grass' ); ?>" /></a>
+            <?php if (function_exists('wppo_get_all_available_langs') && function_exists('wppo_get_lang')) {
+                
+                $list_of_languages = wppo_get_all_available_langs();
+                if (count($list_of_languages) > 1) {
+                                
+                ?>
+                <div class="language grid_3">
+                    <div>
+                        <strong><?php _e( 'This website is available in many languages', 'grass' ); ?></strong>
+                        <a href="<?php echo home_url('/languages/');?>" data-uri="<?php echo home_url('/');?>?select-language&amp;url=<?php echo $_SERVER['REQUEST_URI'];?>">
+                            <span class="switch"><?php _e( 'Switch Language', 'grass' ); ?></span>
+                            <span class="loading"><?php _e( 'Loading...', 'grass' ); ?></span>
+                        </a>
+                    </div>
                 </div>
-            </div>
-            */
+                <?php
+                }
+            }
             ?>
             
             <!-- footnotes -->
             <div id="footnotes" class="grid_9">
                 <?php _e( 'Copyright', 'grass' ); ?> Â 2005â<?php echo date('Y');?> <strong class="gnome_logo"><?php _e( 'The GNOME Project', 'grass' ); ?></strong><br />
-                <small><?php _e( 'Free to share and remix', 'grass' ); ?>: <a href="http://creativecommons.org/licenses/by/3.0/";>Creative Commons CC-BY</a>. <?php _e( 'Optimised for standards', 'grass' ); ?>. <?php _e( 'Hosted by', 'grass' ); ?> <a href="http://www.canonical.com/";>Canonical</a>. <?php _e( 'Powered by', 'grass' ); ?> <a href="http://www.wordpress.org";>WordPress</a></small>
+                <small>
+                    <?php _e( 'Free to share and remix', 'grass' ); ?>: <a href="http://creativecommons.org/licenses/by/3.0/";>Creative Commons CC-BY</a>.
+                    <?php _e( 'Optimised for standards', 'grass' ); ?>.
+                    <?php _e( 'Hosted by', 'grass' ); ?> <a href="http://www.canonical.com/";>Canonical</a>.
+                    <?php _e( 'Powered by', 'grass' ); ?> <a href="http://www.wordpress.org";>WordPress</a>.
+                </small>
             </div>
             
             <div class="clear"></div>
diff --git a/wp-content/themes/gnome-grass/functions.php b/wp-content/themes/gnome-grass/functions.php
index 4805301..9b14ea5 100644
--- a/wp-content/themes/gnome-grass/functions.php
+++ b/wp-content/themes/gnome-grass/functions.php
@@ -75,6 +75,16 @@ function create_post_type() {
   );
 }
 
+/*
+ * Identify Ajax Language Selector
+ */
+if (array_key_exists('select-language', $_GET)) {
+    if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
+        require_once('language-selector.php');
+        die;
+    }
+}
+
 
 // Beautify [galery] shortcode
 
diff --git a/wp-content/themes/gnome-grass/header.php b/wp-content/themes/gnome-grass/header.php
index f6ae461..7417572 100644
--- a/wp-content/themes/gnome-grass/header.php
+++ b/wp-content/themes/gnome-grass/header.php
@@ -43,7 +43,7 @@
     <!-- header -->
     <div id="header" class="container_12">
         <div id="logo" class="grid_3">
-            <h1><a title="<?php _e( 'Go to home page', 'grass' ); ?>" href="<?php bloginfo('url'); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/gnome-logo.png" alt="<?php echo _e('GNOME: The Free Software Desktop Project', 'grass');?>" /></a></h1>
+            <h1><a title="<?php _e( 'Go to home page', 'grass' ); ?>" href="<?php echo home_url('/'); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/gnome-logo.png" alt="<?php echo _e('GNOME: The Free Software Desktop Project', 'grass');?>" /></a></h1>
         </div>
         <div id="top_bar" class="grid_9">
             <div class="left">
@@ -58,7 +58,7 @@
                 </ul> */ ?>
             </div>
             <div class="right">
-                <form role="search" method="get" id="searchform" action="<?php bloginfo('url'); ?>/" >
+                <form role="search" method="get" id="searchform" action="<?php echo home_url('/'); ?>" >
                     <div>
                         <label class="hidden" for="s"><?php _e( 'Search', 'grass' ); ?>: </label><input type="text" value="<?php if(isset($_GET['s'])) { echo htmlspecialchars(stripslashes(strip_tags($_GET['s']))); } ?>" name="s" id="s" placeholder="<?php _e( 'Search', 'grass' ); ?>" />
                     </div>
diff --git a/wp-content/themes/gnome-grass/images/footer-map.png b/wp-content/themes/gnome-grass/images/footer-map.png
index fa178c0..cbd401f 100644
Binary files a/wp-content/themes/gnome-grass/images/footer-map.png and b/wp-content/themes/gnome-grass/images/footer-map.png differ
diff --git a/wp-content/themes/gnome-grass/index.php b/wp-content/themes/gnome-grass/index.php
index 5c04694..97536fb 100644
--- a/wp-content/themes/gnome-grass/index.php
+++ b/wp-content/themes/gnome-grass/index.php
@@ -33,13 +33,17 @@ require_once("header.php"); ?>
                     $parent_id  = $page->post_parent;
                 }
                 $breadcrumbs = array_reverse($breadcrumbs);
-                $first_page = $breadcrumbs[0];
+                if (isset($breadcrumbs[0])) {
+                    $first_page = $breadcrumbs[0];
+                } else {
+                    $first_page = NULL;
+                }
                 ?>
 
                 <?php if(is_page()) {?>
                 <ul class="navigation_list">
                     <?php
-                    if($first_page->ID != '') {
+                    if(isset($first_page) && $first_page->ID != '') {
                         wp_list_pages(array('title_li' => '', 'include' => $first_page->ID));
                         wp_list_pages(array('title_li' => '', 'child_of' => $first_page->ID));
                     } else {
diff --git a/wp-content/themes/gnome-grass/js/template.js b/wp-content/themes/gnome-grass/js/template.js
index bc4214d..d9c3dc7 100644
--- a/wp-content/themes/gnome-grass/js/template.js
+++ b/wp-content/themes/gnome-grass/js/template.js
@@ -28,16 +28,21 @@ $(document).ready(function() {
     /* Language selector
      * ====================================================================== */
     
-    $('#footer .language a.map').click(function(e) {
+    $('#footer .language a').click(function(e) {
         e.preventDefault();
         
+        var el_language = $(this);
+        
         if($('#language_selector').length == 0) {
+            
+            $(el_language).addClass('loading');
         
             $.ajax({
                 'type': 'GET',
-                'url': $(this).attr('href'),
+                'url': $(this).attr('data-uri'),
                 'dataType': 'text',
                 'success': function(data) {
+                    $(el_language).removeClass('loading');
                     $('#footer').after('<div id="language_selector">' + data + '</div>');
                     window.scrollTo(0, $('body').height());
                     $('#language_selector').show().addClass('active');
diff --git a/wp-content/themes/gnome-grass/language-selector.php b/wp-content/themes/gnome-grass/language-selector.php
index bf78655..f7b29d9 100644
--- a/wp-content/themes/gnome-grass/language-selector.php
+++ b/wp-content/themes/gnome-grass/language-selector.php
@@ -5,41 +5,46 @@
  * This must be an automatic list, with proper links and language names.
  */
 
+if (function_exists('wppo_get_all_available_langs') && function_exists('wppo_get_lang')) {
+
 ?>
 <div class="container_12">
     <div class="grid_9">
-        <h3>GNOME speaks your language.</h3>
+        <h3><?php _e( 'GNOME speaks your language.', 'grass' ); ?></h3>
         
         <ul>
-            <li class="active"><a href="#">English</a></li>
-            <li><a href="#">Afrikaans</a></li>
-            <li><a href="#">CatalÃ</a></li>
-            <li><a href="#">ÄeÅtina</a></li>
-            <li><a href="#">Deutsch</a></li>
-            <li><a href="#">EspaÃol</a></li>
-            <li><a href="#">FranÃais</a></li>
-            <li><a href="#">Hrvatski</a></li>
-            <li><a href="#">Magyar</a></li>
-            <li><a href="#">Indonesia</a></li>
-            <li><a href="#">Italiano</a></li>
-            <li><a href="#">ææè</a></li>
-            <li><a href="#">Nederlands</a></li>
-            <li><a href="#">Norsk</a></li>
-            <li><a href="#">Polski</a></li>
-            <li><a href="#">PortuguÃs (BR)</a></li>
-            <li><a href="#">ÐÑÑÑÐÐÐ</a></li>
-            <li><a href="#">ÐÑÐÑÐÐ</a></li>
-            <li><a href="#">Svenska</a></li>
-            <li><a href="#">äæ</a></li>
+            <?php
+            
+            $list_of_languages = wppo_get_all_available_langs();
+            $current_language = wppo_get_lang();
+            
+            $current_url = $_GET['url'];
+            
+            foreach($list_of_languages as $lang_code => $lang_name) {
+                if($lang_code == $current_language) {
+                    $active = ' class="active"';
+                } else {
+                    $active = '';
+                }
+                echo '<li'.$active.'><a href="'.wppo_recreate_url($current_url, $lang_code).'">'.$lang_name.'</a></li>'."\n";
+            }
+            
+            ?>
         </ul>
     </div>
     
     <div class="grid_3">
         
         <div class="help_us_translating">
-            Found a translation bug or want to help translating GNOME? 
-            Join the <a href="http://live.gnome.org/TranslationProject/JoiningTranslation";>GNOME Translation Project</a>!
+            <?php
+            $join_translation_url = 'http://live.gnome.org/TranslationProject/JoiningTranslation';
+            printf(__( 'Found a translation bug or want to help translating GNOME? Join the <a href="%1$s">GNOME Translation Project</a>!', 'grass' ), $join_translation_url);
+            ?>
         </div>
         
     </div>
 </div>
+
+<?php
+
+}
diff --git a/wp-content/themes/gnome-grass/style.css b/wp-content/themes/gnome-grass/style.css
index aa037e2..ab9606a 100644
--- a/wp-content/themes/gnome-grass/style.css
+++ b/wp-content/themes/gnome-grass/style.css
@@ -758,19 +758,50 @@ dl.icon_list dt img {
 }
 #footer div.language {
     float: right;
-    text-align: right;
 }
-#footer div.language .map {
-    margin: 10px 0;
-    display: block;
-    opacity: 0.5;
-    -webkit-transition: opacity linear 200ms;
-    -moz-transition: opacity linear 200ms;
-    transition: opacity linear 200ms;
+#footer div.language a {
+    display: table-cell;
+    vertical-align: middle;
+    text-align: center;
+    width: 220px;
+    height: 110px;
+    background: url(images/footer-map.png) center center no-repeat;
+    outline: none;
+    text-decoration: none;
+}
+#footer div.language a span {
+    background: #f4f4f4;
+    background: -moz-linear-gradient(bottom, #ececec, #fff);
+    background: -webkit-linear-gradient(bottom, #ececec, #fff);
+    background: linear-gradient(bottom, #ececec, #fff);
+    padding: 4px 12px;
+    -moz-border-radius: 10px;
+    -webkit-border-radius: 10px;
+    border-radius: 10px;
+    -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.3);
+    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.3);
+    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
+    color: #333;
+}
+
+#footer div.language a span.loading {
+    display: none;
+}
+#footer div.language a.loading {
+    cursor: wait !important;
+}
+#footer div.language a.loading span.switch {
+    display: none;
 }
-#footer div.language .map:hover {
-    opacity: 1;
+#footer div.language a.loading span.loading {
+    display: inline-block;
 }
+#footer div.language a:hover span.switch {
+    background: #fff;
+    background: -moz-linear-gradient(bottom, #fff, #fff);
+}
+
+
 #footer ul {
     margin: 0;
     padding: 0;
@@ -803,7 +834,10 @@ dl.icon_list dt img {
     margin-top: 20px;
 }
 #footer #footnotes small {
-    font-size: 80%;
+    font-size: 88%;
+}
+#footer #footnotes a {
+    color: inherit;
 }
 
 
@@ -819,7 +853,7 @@ dl.icon_list dt img {
     overflow: hidden;
 }
 #language_selector .container_12 {
-    background: url(images/language-selector-wanda-bg.png) 60px right no-repeat;
+    background: url(images/language-selector-wanda-bg.png) right 60px no-repeat;
     overflow: hidden;
 }
 #language_selector h3 {
@@ -851,7 +885,7 @@ dl.icon_list dt img {
 }
 #language_selector .help_us_translating {
     color: #d3d7cf;
-    margin-top: 118px;
+    margin: 129px 0 30px;
 }
 #language_selector .help_us_translating a {
     color: #fff;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]