Annonce

Important : WordPress 2.6 est disponible en français. À lire avant la migration !
Annonce 1 : Le Codex en français a besoin de vous pour avancer !
Annonce 2 : Avant de poster, n'oubliez pas de faire une petite Recherche et de lire les règles de ce forum.
Annonce 3 : Lisez notre blog, il regorge de bonnes informations.

#1 13-06-2007 05:10:46

radiCarl
Habitué WP
Lieu: Québec
Date d'inscription: 17-11-2006
Messages: 93
Site web

traduction de WP-PostViews

J’utilise un merveilleux petit plugin de l’auteur Lester 'GaMerZ' Chan
Cependant, après plusieurs tentatives, je me résigne à faire appelle à la communauté WP francophone pour traduire ce petit bijoux : WP-PostViews,  (qui devrait ultérieurement être incorporé à WordPress par défaut),

De la sorte,  je recherche simplement à traduire l’expression  « views » sur la page d’entrée de mes articles par « visionnements ». Et vraiment, je ne vois pas lequel des "Views" je dois modifier dans le code du plugin tellement le mot revient souvent. Je vous laisse donc regarder par vous-même.

Code:

  1. <?php
  2. /*
  3. Plugin Name: WP-PostViews
  4. Plugin URI: http://www.lesterchan.net/portfolio/programming.php
  5. Description: Enables you to display how many times a post had been viewed. It will not count registered member views, but that can be changed easily.
  6. Version: 1.10
  7. Author: GaMerZ
  8. Author URI: http://www.lesterchan.net
  9. */
  10.  
  11.  
  12. /* 
  13.   Copyright 2007  Lester Chan  (email : gamerz84@hotmail.com)
  14.  
  15.     This program is free software; you can redistribute it and/or modify
  16.     it under the terms of the GNU General Public License as published by
  17.     the Free Software Foundation; either version 2 of the License, or
  18.     (at your option) any later version.
  19.  
  20.     This program is distributed in the hope that it will be useful,
  21.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.     GNU General Public License for more details.
  24.  
  25.     You should have received a copy of the GNU General Public License
  26.     along with this program; if not, write to the Free Software
  27.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  28. */
  29.  
  30.  
  31. ### Create Text Domain For Translation
  32. load_plugin_textdomain('wp-postviews', 'wp-content/plugins/postviews');
  33.  
  34.  
  35. ### Function: Calculate Post Views
  36. add_action('loop_start', 'process_postviews');
  37. function process_postviews() {
  38.   global $id;
  39.   $post_views = get_post_custom($post_id);
  40.   $post_views = intval($post_views['views'][0]);
  41.   if(empty($_COOKIE[USER_COOKIE])) {
  42.     if(is_single() || is_page()) {   
  43.       if($post_views > 0) {
  44.         update_post_meta($id, 'views', ($post_views+1)); 
  45.       } else {
  46.         add_post_meta($id, 'views', 1, true);
  47.       }
  48.       remove_action('loop_start', 'process_postviews');
  49.     }
  50.   }
  51. }
  52.  
  53.  
  54. ### Function: Display The Post Views
  55. function the_views($text_views = '', $display = true) {
  56.   if(empty($text_views)) {
  57.     $text_views = __('Views', 'wp-postviews');
  58.   }
  59.   $post_views = intval(post_custom('views'));
  60.   if($display) {
  61.     echo number_format($post_views).' '.$text_views;
  62.   } else {
  63.     return $post_views;
  64.   }
  65. }
  66.  
  67.  
  68. ### Function: Display Most Viewed Page/Post
  69. if(!function_exists('get_most_viewed')) {
  70.   function get_most_viewed($mode = '', $limit = 10, $chars = 0, $display = true) {
  71.     global $wpdb, $post;
  72.     $where = '';
  73.     $temp = '';
  74.     if(!empty($mode) && $mode != 'both') {
  75.       $where = "post_type = '$mode'";
  76.     } else {
  77.       $where = '1=1';
  78.     }
  79.     $most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER  BY views DESC LIMIT $limit");
  80.     if($most_viewed) {
  81.       if($chars > 0) {
  82.         foreach ($most_viewed as $post) {
  83.           $post_title = htmlspecialchars(stripslashes($post->post_title));
  84.           $post_views = intval($post->views);
  85.           $post_views = number_format($post_views);
  86.           $temp .= "<li><a href=\"".get_permalink()."\">".snippet_chars($post_title, $chars)."</a> - $post_views ".__('Views', 'wp-postviews')."</li>\n";
  87.         }
  88.       } else {
  89.         foreach ($most_viewed as $post) {
  90.           $post_title = htmlspecialchars(stripslashes($post->post_title));
  91.           $post_views = intval($post->views);
  92.           $post_views = number_format($post_views);
  93.           $temp .= "<li><a href=\"".get_permalink()."\">$post_title</a> - $post_views ".__('Views', 'wp-postviews')."</li>\n";
  94.         }
  95.       }
  96.     } else {
  97.       $temp = '<li>'.__('N/A', 'wp-postviews').'</li>'."\n";
  98.     }
  99.     if($display) {
  100.       echo $temp;
  101.     } else {
  102.       return $temp;
  103.     }
  104.   }
  105. }
  106.  
  107.  
  108. ### Function: Display Most Viewed Page/Post By Category ID
  109. if(!function_exists('get_most_viewed_category')) {
  110.   function get_most_viewed_category($category_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true) {
  111.     global $wpdb, $post;
  112.     $where = '';
  113.     $temp = '';
  114.     if(!empty($mode) && $mode != 'both') {
  115.       $where = "post_type = '$mode'";
  116.     } else {
  117.       $where = '1=1';
  118.     }
  119.     $most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID LEFT JOIN $wpdb->post2cat ON $wpdb->post2cat.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $wpdb->post2cat.category_id = $category_id AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER  BY views DESC LIMIT $limit");
  120.     if($most_viewed) {
  121.       if($chars > 0) {
  122.         foreach ($most_viewed as $post) {
  123.           $post_title = htmlspecialchars(stripslashes($post->post_title));
  124.           $post_views = intval($post->views);
  125.           $post_views = number_format($post_views);
  126.           $temp .= "<li><a href=\"".get_permalink()."\">".snippet_chars($post_title, $chars)."</a> - $post_views ".__('Views', 'wp-postviews')."</li>\n";
  127.         }
  128.       } else {
  129.         foreach ($most_viewed as $post) {
  130.           $post_title = htmlspecialchars(stripslashes($post->post_title));
  131.           $post_views = intval($post->views);
  132.           $post_views = number_format($post_views);
  133.           $temp .= "<li><a href=\"".get_permalink()."\">$post_title</a> - $post_views ".__('Views', 'wp-postviews')."</li>\n";
  134.         }
  135.       }
  136.     } else {
  137.       $temp = '<li>'.__('N/A', 'wp-postviews').'</li>'."\n";
  138.     }
  139.     if($display) {
  140.       echo $temp;
  141.     } else {
  142.       return $temp;
  143.     }
  144.   }
  145. }
  146.  
  147.  
  148. ### Added by Paolo Tagliaferri (http://www.vortexmind.net - webmaster@vortexmind.net)
  149. function get_timespan_most_viewed($mode = '', $limit = 10, $days = 7, $display = true) {
  150.   global $wpdb, $post; 
  151.   $limit_date = current_time('timestamp') - ($days*86400);
  152.   $limit_date = date("Y-m-d H:i:s",$limit_date); 
  153.   $where = '';
  154.   $temp = '';
  155.   if(!empty($mode) && $mode != 'both') {
  156.     $where = "post_type = '$mode'";
  157.   } else {
  158.     $where = '1=1';
  159.   }
  160.   $most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND post_date > '".$limit_date."' AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER  BY views DESC LIMIT $limit");
  161.   if($most_viewed) {
  162.     foreach ($most_viewed as $post) {
  163.       $post_title = htmlspecialchars(stripslashes($post->post_title));
  164.       $post_views = intval($post->views);
  165.       $post_views = number_format($post_views);
  166.       $temp .= "<li><a href=\"".get_permalink()."\">$post_title</a> - $post_views ".__('Views', 'wp-postviews')."</li>";
  167.     }
  168.   } else {
  169.     $temp = '<li>'.__('N/A', 'wp-postviews').'</li>'."\n";
  170.   }
  171.   if($display) {
  172.     echo $temp;
  173.   } else {
  174.     return $temp;
  175.   }
  176. }
  177.  
  178.  
  179. ### Function: Display Total Views
  180. if(!function_exists('get_totalviews')) {
  181.   function get_totalviews($display = true) {
  182.     global $wpdb;
  183.     $total_views = $wpdb->get_var("SELECT SUM(meta_value+0) FROM $wpdb->postmeta WHERE meta_key = 'views'");
  184.     if($display) {
  185.       echo number_format($total_views);
  186.     } else {
  187.       return number_format($total_views);
  188.     }
  189.   }
  190. }
  191.  
  192.  
  193. ### Function: Snippet Text
  194. if(!function_exists('snippet_chars')) {
  195.   function snippet_chars($text, $length = 0) {
  196.     $text = htmlspecialchars_decode($text);
  197.      if (strlen($text) > $length){       
  198.       return htmlspecialchars(substr($text,0,$length)).'...';             
  199.      } else {
  200.       return htmlspecialchars($text);
  201.      }
  202.   }
  203. }
  204.  
  205.  
  206. ### Function: HTML Special Chars Decode
  207. if (!function_exists('htmlspecialchars_decode')) {
  208.    function htmlspecialchars_decode($text) {
  209.        return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
  210.    }
  211. }
  212.  
  213.  
  214. ### Function: Modify Default WordPress Listing To Make It Sorted By Post Views
  215. function views_join($content) {
  216.   global $wpdb;
  217.   $content .= " LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID";
  218.   return $content;
  219. }
  220. function views_where($content) {
  221.   global $wpdb;
  222.   $content .= " AND $wpdb->postmeta.meta_key = 'views'";
  223.   return $content;
  224. }
  225. function views_orderby($content) {
  226.   global $wpdb;
  227.   $content = " $wpdb->postmeta.meta_value DESC";
  228.   return $content;
  229. }
  230. //add_filter('posts_join', 'views_join');
  231. //add_filter('posts_where', 'views_where');
  232. //add_filter('posts_orderby', 'views_orderby');
  233. ?>

Merci Groupe pour l'attention

Hors ligne

 

#2 13-06-2007 09:46:42

dlo
Blogodépendant
Date d'inscription: 10-04-2007
Messages: 1480

Re: traduction de WP-PostViews

Bonjour,

Il faut changer tous ceux qui correspondent aux chaînes de recherche suivantes:

__('Views' et _e('Views

Mais, en toute logique, vu que le plugin est "internationalisé" (cf. code suivant : ### Create Text Domain For Translation
load_plugin_textdomain('wp-postviews', 'wp-content/plugins/postviews')wink, il faudrait créer un fichier .mo avec les traductions et ne pas modifier le plugin directement.

Cordialement

PS: Je traduirais 'Views' par 'A été vu x fois' plutôt que par 'visionnements'. Mais c'est un avis qui n'engage que moi... tongue

Dernière modification par dlo (13-06-2007 09:50:56)


Non, je ne suis pas blogodépendant... C'est juste que je n'ai toujours pas trouvé la sortie de ce forum !

Hors ligne

 

#3 13-06-2007 19:49:04

radiCarl
Habitué WP
Lieu: Québec
Date d'inscription: 17-11-2006
Messages: 93
Site web

Re: traduction de WP-PostViews

Permettez mon ignorance... mais il y a à l'intérieur du dossier du plugin un fichier .pot

Or, à lire quelques mots dans le code, il me semble que ce fichier est lié d'une certaine façon à la traduction.

De la sorte, si c'est le cas... si je comprends bien, il suffirait de traduire ce fichier pour offrir ici  ce plugin en français :
big_smile

Code:

  1. msgid ""
  2. msgstr ""
  3. "Project-Id-Version: WP-PostViews 1.10\n"
  4. "POT-Creation-Date: \n"
  5. "PO-Revision-Date: 2007-01-30 20:31+0800\n"
  6. "Last-Translator: Lester 'GaMerZ' Chan <gamerz84@hotmail.com>\n"
  7. "Language-Team: Lester Chan <gamerz84@hotmail.com>\n"
  8. "MIME-Version: 1.0\n"
  9. "Content-Type: text/plain; charset=utf-8\n"
  10. "Content-Transfer-Encoding: 8bit\n"
  11. "X-Poedit-Language: English\n"
  12. "X-Poedit-Country: SINGAPORE\n"
  13. "X-Poedit-KeywordsList: __;_e\n"
  14. "X-Poedit-Basepath: .\n"
  15. "X-Poedit-SearchPath-0: .\n"
  16.  
  17. #: postviews.php:57
  18. #: postviews.php:86
  19. #: postviews.php:93
  20. #: postviews.php:126
  21. #: postviews.php:133
  22. #: postviews.php:166
  23. msgid "Views"
  24. msgstr ""
  25.  
  26. #: postviews.php:97
  27. #: postviews.php:137
  28. #: postviews.php:169
  29. msgid "N/A"
  30. msgstr ""

Hors ligne

 

#4 13-06-2007 20:18:53

BenKenobi
Jedi WordPress
Lieu: Châteauroux
Date d'inscription: 19-09-2005
Messages: 4255
Site web

Re: traduction de WP-PostViews

Utilise POedit, c'est un logiciel qui te permettra d'ouvrit le POT et de le traduire pour en faire un MO, fichier qui te traduira le plugin... attention ces fichiers doivent avoir un nom précis.


Que la Force soit avec vous...
-----------------------------------------------------------------------------
Si vous aimez la BD, vous aimerez www.kroniks.net

Hors ligne

 

#5 14-06-2007 02:50:32

radiCarl
Habitué WP
Lieu: Québec
Date d'inscription: 17-11-2006
Messages: 93
Site web

Re: traduction de WP-PostViews

Finalement, en suivant le conseil de dlo, la traduction fut un jeu d'enfant.

Merci.resolu

En passant Ben, POedit peut s'ouvrir dans Dreamweaver aussi.

Dernière modification par radiCarl (14-06-2007 02:50:51)

Hors ligne

 

Pied de page des forums

Propulsé par PunBB 1.2.20
© Copyright 2005-2006 WordPress France