Annonce

Important, migration recommandée : WordPress 2.6.5 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 22-06-2006 04:03:56

Jean-Marc
Passionné WP
Lieu: Rimouski - Québec - Canada
Date d'inscription: 16-05-2006
Messages: 161

Site complètement trilingue

Salut à toutes et à tous,

Devant refaire au complet un site pour une association en Belgique, je me dis que WordPress serait idéal, surtout que, comme en Belgique il y a 2 langues officielles, je me dis qu'il serait bien de faire un site trilingue (Français, Néerlandais et anglais pour les visiteurs étrangers qui sont quand-même assez nombreux à ce qu'on me dit).
J'ai vu des sites avec des petits drapeaux et j'ai constaté que le texte change de langue, mais pas toujours le thème.
Comment fait-on pour que tout change de langue (textes, thèmes, WordPress lui-même (pour les dates et le reste des "détails")) ?
Enfin, je suis à chercher des thèmes avec des fichiers .mo car je suppose que ça va être indispensable et que créer un thème localisé de toutes pièces ne doit pas être un jeu d'enfant. Si qqn sait où en trouver ...

Pour les plugins, j'ai trouvé une discussion où Xavier explique comment on localise. Je vais essayer et voir si je m'en sors.

Merci de vos z'avis z'avisés,
Jean-Marc


Il n'y a pas de problème.
Il n'y a que des solutions.
Le tout étant de les trouver ...

Hors ligne

 

#2 23-06-2006 16:51:29

Jean-Marc
Passionné WP
Lieu: Rimouski - Québec - Canada
Date d'inscription: 16-05-2006
Messages: 161

Re: Site complètement trilingue

J'avance, mais il me reste encore des questions sans réponse.
Avec polyglot et la localisation du thème, j'arrive à avoir la grande majorité du site qui change de langue.
toutefois, il me reste à trouver le moyen de traduire les catégories. Si qqn sait comment on fait ...
De même, les dates ne sont traduites qu'à moitié. L'ordre des choses (jour, mois, année, etc ...) se met à sa place, mais tout reste ne français. Je n'arrive pas à trouver comment traduire mercredi en woensdag ou wednesday selon la langue chosie. Je suis sur qu'il doit y avoir moyen de trouver qqch mais je n'y arrive pas, aussi je fais appel à l'équipe ... wink
Allez donc faire une petit tour sur le site et dites moi ce que vous en pensez (http://www.crorb.org/wordpress)

Merci de vos z'avis z'avisés,
Jean-Marc


Il n'y a pas de problème.
Il n'y a que des solutions.
Le tout étant de les trouver ...

Hors ligne

 

#3 24-06-2006 01:31:09

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

Re: Site complètement trilingue

Ca m'intéresserait de savoir comment on utilise le plugin Polyglot... je dois un peu bête... j'ai pas tout compris... (et pourtant j'ai essayé)


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

Hors ligne

 

#4 26-06-2006 00:01:26

Jean-Marc
Passionné WP
Lieu: Rimouski - Québec - Canada
Date d'inscription: 16-05-2006
Messages: 161

Re: Site complètement trilingue

Il existe une nouvelle version : polyglot 2. Sans doute est-elle simplifiée, parce que je n'ai pas eu de difficulté réelle à arriver à ce que vous pouvez voir sur le site http://www.crorb.org/wordpress.
Cette version de polyglot permet aussi, via un cookie, de se souvenir de la langue du site chez le visiteur pour rouvrir le site dans la même langue la fois suivante. Et même, via la langue du browser, de s'imaginer la langue dans laquelle afficher à la première ouverture.

J'ai téléchargé polyglot 2 ici : http://fredfred.net/skriker/index.php/polyglot

Ensuite j'ai modifié le php comme expliqué sur la page de téléchargement, soit :


Code:

  1. $polyglot_settings['default_lang'] = 'fr';

C'est la langue par défaut de ton site pour quand un visiteur y vient la première fois




Code:

  1. $polyglot_settings['trans']['en'] = 'english';
  2. $polyglot_settings['trans']['de'] = 'deutsch';
  3. $polyglot_settings['trans']['nl'] = 'nederlands';
  4. $polyglot_settings['trans']['fr'] = 'français';

Et les lignes suivantes déterminent les textes à afficher pour les traductions (quand tu n'utilises pas les drapeaux)




Code:

  1. $polyglot_settings['knownlangs'] = array('fr','nl','en');

Ce sont les langues que tu veux sur ton site.




Code:

  1. $polyglot_settings['use_flags'] = true;

(si tu mets true, tu vois les drapeaux. si tu mets false, tu vois les textes. Par défaut : false)




Code:

  1. $polyglot_settings['time_format']['en'] = 'g.i a';
  2. $polyglot_settings['time_format']['nl'] = 'G:i';
  3. $polyglot_settings['time_format']['fr'] = 'G:i';
  4.  
  5. $polyglot_settings['date_format']['en'] = 'Y-m-d';
  6. $polyglot_settings['date_format']['nl'] = 'j F Y';
  7. $polyglot_settings['date_format']['fr'] = 'j F Y';

Ceci est supposé faire modifier les dates suivant les langues. En fait, la position de chaque partie de la date se met à jour, mais les noms des jours et des mois restent en fr, dans mon cas.




Code:

  1. $polyglot_settings['wplang']['ar'] = 'ar';
  2. $polyglot_settings['wplang']['bg'] = 'bg_BG';
  3. $polyglot_settings['wplang']['cs'] = 'cs_CZ';
  4. $polyglot_settings['wplang']['cy'] = 'cy';
  5. $polyglot_settings['wplang']['da'] = 'da_DK';
  6. $polyglot_settings['wplang']['de'] = 'de_DE';
  7. $polyglot_settings['wplang']['el'] = 'el';
  8. $polyglot_settings['wplang']['eo'] = 'eo';
  9. $polyglot_settings['wplang']['es'] = 'es_ES';
  10. $polyglot_settings['wplang']['fa'] = 'fa';
  11. $polyglot_settings['wplang']['fi'] = 'fi_FI';
  12. $polyglot_settings['wplang']['fr'] = 'fr_FR';//fr_BE
  13. $polyglot_settings['wplang']['hu'] = 'hu_HU';
  14. $polyglot_settings['wplang']['it'] = 'it_IT';
  15. $polyglot_settings['wplang']['ja'] = 'ja_JP';
  16. $polyglot_settings['wplang']['ko'] = 'ko';
  17. $polyglot_settings['wplang']['nb'] = 'nb_NO';//nn_NO
  18. $polyglot_settings['wplang']['nl'] = 'nl_NL';
  19. $polyglot_settings['wplang']['pl'] = 'pl_PL';
  20. $polyglot_settings['wplang']['pt'] = 'pt_BR';
  21. $polyglot_settings['wplang']['ru'] = 'ru_RU';
  22. $polyglot_settings['wplang']['sk'] = 'sk';
  23. $polyglot_settings['wplang']['sq'] = 'sq';
  24. $polyglot_settings['wplang']['sr'] = 'sr_CS';
  25. $polyglot_settings['wplang']['sv'] = 'sv_SE';
  26. $polyglot_settings['wplang']['zh'] = 'zh_CN';

Ceci défini les nom des fichiers .mo pour les langues utilisées. J'y ajouté le nl parce qu'il n'existait pas dans la liste et que donc la traduction ne se faisait pas vers le nl.

Enfin, j'ai enlever les <ul class ...> </ul> et <li> </li> pour que les drapeaux se mettent l'un à côté de l'autre et pas l'un en dessous de l'autre, avec des points de li.
La fonction modifiée devient :

Code:

  1. function polyglot_list_langs($flags=false){
  2.     global $polyglot_settings,$wp_query;
  3.                 $clean_uri = polyglot_uri_cleaner($_SERVER['REQUEST_URI']);
  4.                
  5.                 if(!$polyglot_settings['use_helpers_in_uri']){
  6.                     $uri_helper = '';
  7.                 }
  8.                 else {
  9.                     $uri_helper = "{$polyglot_settings['uri_helpers']['lang_pref']}/";
  10.                 }
  11.                
  12.                
  13.                     foreach($polyglot_settings['knownlangs'] as  $value){
  14.                        
  15.                         if ( $value==$polyglot_settings['lang_pref'] ) {
  16.                             $highlight = "language_item current_language_item";
  17.                         } else {
  18.                             $highlight = "language_item";
  19.                         }
  20.                         echo " <a href=\"";
  21.                        
  22.                         if(  $polyglot_settings['lang_rewrite'] ){
  23.                            
  24.                             if(strpos(get_settings('permalink_structure'),'index.php') === FALSE){
  25.                                     echo polyglot_trailingslashit($clean_uri)."{$uri_helper}{$value}/";
  26.                                 }
  27.                             else {
  28.                                 $qm_pos = strpos($clean_uri,'?');
  29.                                 if(strpos($clean_uri,'index.php') === FALSE){
  30.                                         if( ($qm_pos) === FALSE){
  31.                                                 echo polyglot_trailingslashit($clean_uri)."index.php/{$uri_helper}{$value}/";
  32.                                             }
  33.                                         else {
  34.                                                 echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos))."index.php/{$uri_helper}{$value}/".substr($clean_uri,$qm_pos);
  35.                                             }
  36.                                     }
  37.                                 else {
  38.                                
  39.                                         if($qm_pos === FALSE){
  40.                                                     echo polyglot_trailingslashit($clean_uri)."{$uri_helper}{$value}/";
  41.                                                 }
  42.                                             else {
  43.                                                     echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos))."{$uri_helper}{$value}/".substr($clean_uri,strpos($clean_uri,'?'));
  44.                                                 }
  45.                                     }
  46.                                
  47.                                
  48.                                
  49.                                 }
  50.                         }
  51.                         else {
  52.                        
  53.                             //if('' != get_settings('permalink_structure')){
  54.                                 echo $clean_uri.((strpos($clean_uri,'?') === FALSE) ? '?' : '&amp;' )."lang_pref={$value}";
  55.                             //}
  56.                        
  57.                         }
  58.                         echo "\">". (($flags) ? "<img src=\"".$polyglot_settings['path_to_flags'].$polyglot_settings['flags'][$value] ."\" alt=\"".get_trans($value)."\" title=\"".get_trans($value)."\" />" : get_trans($value)) ."</a>";
  59.                     }
  60. }

A ce que j'ai vu sur le site du créateur, on pourrait écrire le nom des catégories avec les balises de langues, mais chez moi il supprime les balises quand il sauve dans la bdd. Donc quand je retourne sur le site, au lieu d'avoir le nom de la catégorie dans la langue choisie, j'ai les trois noms dans toutes les langues.
En allant ajouter les balises directement dans la bdd via phpmyadmin, ça passe. Mais comme ce n'est pas moi qui serai rédacteur, je ne trouve pas le système idéal. Une autre solution proposée est de localiser les noms des catégories. Là encore, le rédacteur ca devoir aller jouer dans le .po et devra avoir un poedit pour recompiler puis repousser le tout sur le serveur. Vraiment repoussant pour le rédacteur basique, et vraiment risqué pour le site qui, selon, ne mettra pas longtemps à ne plus fonctionner du point de vue des langues.
Enfin, lorsque je suis dans l'archive, il me met les 3 noms pour le nom de catégorie. Là aussi je pense qu'il y aurait une petite modif à faire.

En résumé, polyglot peut-être pas mal pour un site statique, mais pour un site mis à jour régulièrement ...
Quoi qu'il en soit, ça me paraît vraiment une bonne base et un bon départ.

Si qqn trouve le moyen de localiser les catégories directement dans l'admin, je suis preneur.
Je suis aussi preneur d'un moyen pour que les noms des mois, des jours etc se traduisent aussi.

Jean-Marc


Il n'y a pas de problème.
Il n'y a que des solutions.
Le tout étant de les trouver ...

Hors ligne

 

#5 29-06-2006 13:39:00

dbma
Connaisseur WP
Date d'inscription: 29-06-2006
Messages: 19

Re: Site complètement trilingue

merci, pour ton tutos, trop cool mais j'ai un dernier prob, c'est que sur mon site...www.dbmacity.com...tout apparait comme il le faux mais une fos que je clique sur un floag ca plante , je pense qu'il manque des .mo mais ou je vais les mettre..

merci d'avance..

Hors ligne

 

#6 29-06-2006 15:47:39

Jean-Marc
Passionné WP
Lieu: Rimouski - Québec - Canada
Date d'inscription: 16-05-2006
Messages: 161

Re: Site complètement trilingue

Salut,

J'ai été me promener sur ton site et je n'ai rien vu de spécial. Tout fonctionne parfaitement.
Mais comme ce poste parle de polyglot et que je n'ai vu aucune traduction possible, je me dis que tu as désactivé le plugin. Pour voir ce qui ne va pas, il faudrait que tu le réactives.
Pour les .mo, tu as les .mo "d'origine" (pour WP lui-même) qui sont dans wp-includes/languages et les .mo pour traduire ton thème qui doivent se trouver dans ton thème. Si tu veux traduire des plugins, tu fais des .mo pour eux aussi.

Jean-Marc


Il n'y a pas de problème.
Il n'y a que des solutions.
Le tout étant de les trouver ...

Hors ligne

 

#7 29-06-2006 16:08:45

dbma
Connaisseur WP
Date d'inscription: 29-06-2006
Messages: 19

Re: Site complètement trilingue

oups c'est vrais que ce n'etais pas pratique, voila c'est mis


donc a l'activation de poliglot dan les plugins wordpress j'ai ca :

Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-admin/plugins.php on line 15

apres sur mon site j'ai ...

Not Found
The requested URL /lang-pref/it/ was not found on this server.

Apache/1.3.36 Server at www.dbmacity.com Port 80


merci de m'aide

Ps j'ai mis les .mo dans le theme...


quand je me deconnecte de wordpress admin j'ai


Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-login.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-includes/pluggable-functions.php on line 337

Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-includes/pluggable-functions.php on line 338

Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-includes/pluggable-functions.php on line 339

Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-includes/pluggable-functions.php on line 340

Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-includes/pluggable-functions.php on line 288

Dernière modification par dbma (29-06-2006 16:09:57)

Hors ligne

 

#8 30-06-2006 01:32:04

Jean-Marc
Passionné WP
Lieu: Rimouski - Québec - Canada
Date d'inscription: 16-05-2006
Messages: 161

Re: Site complètement trilingue

Salut,

Not Found
The requested URL /lang-pref/it/ was not found on this server.

Il semble que la langue de préférence définie dans polyglot.php soit l'italien. Vérifie si tu as bien un it_IT.mo dans ton répertoire de thème.

Si ce n'est pas l'italien que tu veux, change ton polyglot.php pour avoir une langue dont tu as les .mo dans ton répertoire.

Pour les autres erreurs, il te faudrait l'aide de qqn d'autre. Selon moi c'est plus un pbl avec WP, peut-être créé par polyglot ou par ton thème.
Désactive polyglot, mets un autre thème puis réactive polyglot. Si tu as toujours les mêmes messages, ce n'est pas du côté du thème qu'il faut chercher.
Ensuite, essaye d'installer ou de désactiver et réactiver un autre plugin et vois si tu as toujours le même genre de messages, auquel cas il faudrait chercher dans WP, ou bien désactiver polyglot et l'enlever complètement du serveur (Tu le mers qq part sur ton disque dur pour le remettre par la suite si ce n'est pas lui le problème). Si une fois que polyglot est enlevé, tu n'as plus de messages avec un autre plugin qui générait les mêmes messages, c'est que c'était polyglot le problème.

Tiens nous au courant de la suite, et de la solution si tu la trouves.

Jean-Marc


Il n'y a pas de problème.
Il n'y a que des solutions.
Le tout étant de les trouver ...

Hors ligne

 

#9 30-06-2006 10:29:51

dbma
Connaisseur WP
Date d'inscription: 29-06-2006
Messages: 19

Re: Site complètement trilingue

Donc : j'ai remis les langues .mo dasn TOUT les repertoire...renommer lang-pref: ca ne marche pas
j'ai desactiver le plugin ca remarche apparement c'estun problème du plogin

bref...c'est la merde..je le desactive.. et basta


j'ai toujours le messgae dêrreur.. seulement avec le plugin polyglot.

Warning: Cannot modify header information - headers already sent by (output started at /home.1/d/b/m/dbmacity/www/wp-content/plugins/polyglot.php:1) in /home.1/d/b/m/dbmacity/www/wp-admin/plugins.php on line 15

Hors ligne

 

#10 30-06-2006 18:19:17

Jean-Marc
Passionné WP
Lieu: Rimouski - Québec - Canada
Date d'inscription: 16-05-2006
Messages: 161

Re: Site complètement trilingue

Salut,

En cherchant ton pbl, j'ai eu le même chez moi. Je ne dis pas que ce n'est pas polyglot, je n'en sais rien, et en effet, si tu n'as plus le problème lorsque tu l'enlèves, il est fort probable que ce soit lui qui cause un problème avec WP.
Par contre, ce que j'ai remarqué c'est que cette erreur vient toujours quand le fichier du plugin que j'active est codé en utf-8. Je me demande pas pourquoi ça ne marche pas. Je n'en sais rien. C'est juste un constat que je fais. Lorsque je passe le fichier en ansi et que mets les codes html pour les caractères accentués, le problème disparaît.
Cela dit, ce n'est pas parce que c'est comme ça chez moi que ce sera comme ça pour toi.
A part ça, pour moi polyglot fonctionne bien. Tu peux le voir sur le site que je suis en train de développer (http://www.crorb.org/wordpress/).
Je dirais peut-être qu'il a qq problèmes, mais je n'irais pas jusqu'à dire que c'est de la merde. Une maladie de jeunesse tout au plus, selon moi. Mais ceci n'est que mon avis.

Jean-Marc


Il n'y a pas de problème.
Il n'y a que des solutions.
Le tout étant de les trouver ...

Hors ligne

 

#11 01-07-2006 00:32:23

dbma
Connaisseur WP
Date d'inscription: 29-06-2006
Messages: 19

Re: Site complètement trilingue

je ne dis pas que c'est de la merde mais bon , c'est chiant...

peut tu me donner ton fichier polyglot.php ou mettre ta config sur ton post, comme ca j'essaye de le mettre dans ma BDD et je te dis ...

merci.

Hors ligne

 

#12 01-07-2006 03:36:46

Jean-Marc
Passionné WP
Lieu: Rimouski - Québec - Canada
Date d'inscription: 16-05-2006
Messages: 161

Re: Site complètement trilingue

Voici le polyglot que j'utilise.

J'ai juste fais quelques transformations pour avoir les drapeaux l'un à côté de l'autre et pas l'un en dessous et de l'autre et pour pouvoir traduire les noms des jours et des mois.

Code:

  1. <?php
  2. /*
  3. Plugin Name: Polyglot
  4. Plugin URI: http://fredfred.net/skriker/index.php/polyglot
  5. Description: Plugin that helps you make your Wordpress powered web completely multilingual. With full support of multiple time and date formats, localization of your RSS feeds and, of course, publishing your posts and pages in any number of languages. Inspired by <a href="http://www.noprerequisite.com/language_picker/">Language Picker</a>. For more information, comments or questions visit the <a href="http://fredfred.net/skriker/index.php/polyglot">Polyglot's homepage</a>.
  6. Version: 2.0
  7. Author: Martin Chlupac
  8. Author URI: http://fredfred.net/skriker/
  9. Update: http://fredfred.net/skriker/plugin-update.php?p=198
  10.  
  11.  
  12.  This program is free software; you can redistribute it and/or
  13.  modify it under the terms of the GNU General Public License
  14.  as published by the Free Software Foundation; either version 2
  15.  of the License, or (at your option) any later version.
  16. */
  17.  
  18. // Default language version - used when proper language version of the text is not present or the visitor's prefered language is unknown
  19. $polyglot_settings['default_lang'] = 'fr';
  20.  
  21. //You can define your own translations of language shortcuts
  22.  
  23. $polyglot_settings['trans']['en'] = 'english';
  24. $polyglot_settings['trans']['de'] = 'deutsch';
  25. $polyglot_settings['trans']['nl'] = 'nederlands';
  26. $polyglot_settings['trans']['fr'] = 'français';
  27.  
  28. $polyglot_settings['trans']['cs'] = '&#269;esky';
  29. $polyglot_settings['trans']['it'] = 'italiano';
  30. $polyglot_settings['trans']['sv'] = 'svenska';
  31.  
  32.  
  33. //Which language versions you offer for the whole web - use the proper ISO codes!
  34. $polyglot_settings['knownlangs'] = array('fr','nl','en');
  35.  
  36. //set to 'true' if there should be shown flags instead of names of languages
  37. $polyglot_settings['use_flags'] = true;
  38.  
  39. //list of ISO codes and their image represantations (flags).
  40. //all flags can be found in 'polyglot_flags' directory
  41.  
  42. $polyglot_settings['flags']['en'] = 'gb.png';
  43. $polyglot_settings['flags']['de'] = 'de.png';
  44. $polyglot_settings['flags']['nl'] = 'nl.png';
  45. $polyglot_settings['flags']['fr'] = 'fr.png';
  46.  
  47. $polyglot_settings['flags']['cs'] = 'cz.png';
  48. $polyglot_settings['flags']['it'] = 'it.png';
  49. $polyglot_settings['flags']['sv'] = 'se.png';
  50.  
  51. //time format for each language
  52. //if not set - default WP time format is used
  53. $polyglot_settings['time_format']['en'] = 'g.i a';
  54. $polyglot_settings['time_format']['de'] = 'G:i';
  55. $polyglot_settings['time_format']['nl'] = 'G:i';
  56. $polyglot_settings['time_format']['fr'] = 'G:i';
  57. $polyglot_settings['time_format']['cs'] = 'G.i';
  58.  
  59. $polyglot_settings['date_format']['en'] = 'Y-m-d';
  60. $polyglot_settings['date_format']['de'] = 'j. F Y';
  61. $polyglot_settings['date_format']['nl'] = 'j F Y';
  62. $polyglot_settings['date_format']['fr'] = 'j F Y';
  63. $polyglot_settings['date_format']['cs'] = 'j. n. Y';
  64.  
  65.  
  66. /*path to the plugin directory
  67. don't forget trailing slash if you are changing this value
  68. */
  69. $polyglot_settings['path_to_flags'] = get_bloginfo('wpurl').'/wp-content/plugins/polyglot_flags/';
  70.  
  71. //if you use WP older than 1.5 you must use this:
  72. //$polyglot_settings['path_to_flags'] = get_bloginfo('url').'/wp-content/plugins/';
  73.  
  74.  
  75. //default text that is shown when the proper language version of the post is missing and even the default language version is not there
  76. // use $polyglot_settings['text_is_missing_message'] = '';  if you want to turn it off.
  77. $polyglot_settings['text_is_missing_message'] = '[lang_en]Sorry, but this post is not available in English[/lang_en][lang_fr]D&eacute;sol&eacute; mais cet article n\'a pas &eacute;t&eacute; traduit en fran&ccedil;ais.[/lang_fr]';
  78.  
  79. //----------------------advanced-----------------------------------------------------------------------
  80.  
  81. //Should be printed <meta http-equiv="Content-Language" content="xx" /> where xx stands for ISO code of current language?
  82. $polyglot_settings['print_meta'] = false;
  83.  
  84. // Name of the cookie - default:'wordpress_lang_pref'.$cookiehash
  85. $polyglot_settings['lang_pref_cookie'] = 'wordpress_lang_pref'.$cookiehash;
  86.  
  87. /*
  88. Should Polyglot attempt to dynamically change the WP locale
  89. setting based on user's prefered language? Note, for this to work
  90. .mo files must be renamed to match the name specified in $polyglot_settings['wplang'] array
  91. but you don't have to rename anything in most cases as there is already list of current WP versions present.
  92. */
  93. $polyglot_settings['lang_change_locale'] = TRUE;
  94.  
  95. /*
  96. To use permalinks for other languages set this to "true".
  97. You probably don't have to do anything else if you have "index.php" in your permalink structure.
  98. In some cases it doesn't work smoothly with re-writing rules specified in .htaccess file - then you have to add some rules to that file manually.
  99. For more info check: http://www.google.com/search?hl=en&q=mod_rewrite
  100. */
  101. $polyglot_settings['lang_rewrite'] = true;
  102.  
  103. /**
  104. This should stay turned off unless you had problems with rules in your .htaccess file and you have edited them manually.
  105. */
  106. $polyglot_settings['i_have_manually_edited_my_htaccess_file'] = false; //change this only if you know what you are doing!
  107.  
  108. /**
  109. There are some helpers added (/lang/, /lang-pref/) by default to the url to help Polyglot distinguish between language code and short post slug.
  110. These can be turned off. But don't turn them off unless you have a good reason to do that.
  111. */
  112. $polyglot_settings['use_helpers_in_uri'] = true;
  113.  
  114. /**
  115. If you want to use these helpers but you want to change them - do that here:
  116. */
  117. $polyglot_settings['uri_helpers']['lang_view'] = 'lang';
  118. $polyglot_settings['uri_helpers']['lang_pref'] = 'lang-pref';
  119.  
  120.  
  121. /*
  122. The xx from [lang_xx] will be translated according to this table to the $locale/WPLANG variable in WP. It also suggests the name of the .mo file.
  123. Add your language or change it as you need.
  124. */
  125. $polyglot_settings['wplang']['ar'] = 'ar';
  126. $polyglot_settings['wplang']['bg'] = 'bg_BG';
  127. $polyglot_settings['wplang']['cs'] = 'cs_CZ';
  128. $polyglot_settings['wplang']['cy'] = 'cy';
  129. $polyglot_settings['wplang']['da'] = 'da_DK';
  130. $polyglot_settings['wplang']['de'] = 'de_DE';
  131. $polyglot_settings['wplang']['el'] = 'el';
  132. $polyglot_settings['wplang']['eo'] = 'eo';
  133. $polyglot_settings['wplang']['es'] = 'es_ES';
  134. $polyglot_settings['wplang']['fa'] = 'fa';
  135. $polyglot_settings['wplang']['fi'] = 'fi_FI';
  136. $polyglot_settings['wplang']['fr'] = 'fr_FR';//fr_BE
  137. $polyglot_settings['wplang']['hu'] = 'hu_HU';
  138. $polyglot_settings['wplang']['it'] = 'it_IT';
  139. $polyglot_settings['wplang']['ja'] = 'ja_JP';
  140. $polyglot_settings['wplang']['ko'] = 'ko';
  141. $polyglot_settings['wplang']['nb'] = 'nb_NO';//nn_NO
  142. $polyglot_settings['wplang']['nl'] = 'nl_NL';
  143. $polyglot_settings['wplang']['pl'] = 'pl_PL';
  144. $polyglot_settings['wplang']['pt'] = 'pt_BR';
  145. $polyglot_settings['wplang']['ru'] = 'ru_RU';
  146. $polyglot_settings['wplang']['sk'] = 'sk';
  147. $polyglot_settings['wplang']['sq'] = 'sq';
  148. $polyglot_settings['wplang']['sr'] = 'sr_CS';
  149. $polyglot_settings['wplang']['sv'] = 'sv_SE';
  150. $polyglot_settings['wplang']['zh'] = 'zh_CN';
  151.  
  152. //============================================STOP EDITING HERE! (unless you know what you are doing)=====================================
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. //=====================================HOOKS=====================================
  161. add_filter('the_time','polyglot_the_time',10,2);
  162. add_filter('get_comment_time','polyglot_comment_time');
  163. add_filter('the_date','polyglot_the_date',10,4);
  164. add_filter('get_comment_date','polyglot_comment_date');
  165. add_filter('the_category_rss','__',1);
  166. add_filter('the_content', 'polyglot_filter_with_message',1);
  167. add_filter('the_title', 'polyglot_filter',1);
  168. add_filter('wp_list_pages', 'polyglot_filter_htmlentities',1);
  169. add_filter('single_post_title', 'polyglot_filter',1);
  170. add_filter('the_content_rss', 'polyglot_filter',1);
  171. add_filter('the_excerpt', 'polyglot_filter',1);
  172. add_filter('comment_text', 'polyglot_filter',1);
  173.  
  174. add_filter('bloginfo', 'polyglot_filter',1,1);
  175.  
  176. add_filter('list_cats','__',1);//we register standard gettext function
  177. add_filter('the_category','polyglot_translate_the_category');
  178.  
  179. add_action('wp_head','polyglot_wp_head');
  180. add_action('init','polyglot_init',1);
  181.  
  182. /*
  183. You probably have to incerase the length of 'cat_name' column in MySql table 'categories' in your DB to be able to use this.
  184. 'cat_name' is by default just 55 characters long.
  185. */
  186. add_filter('the_category', 'polyglot_filter_htmlentities',1);
  187. add_filter('list_cats', 'polyglot_filter_htmlentities',2);
  188.  
  189. add_filter('sanitize_title', 'polyglot_sanitize_title', 1);
  190.  
  191. add_filter('polyglot_filter','polyglot_filter');
  192.  
  193.  
  194.  
  195. //here we try to guess which language user wants
  196. //========================================
  197.  
  198. $polyglot_settings['lang_pref'] = polyglot_get_users_pref_lang();//we don't know anything about the user's preferred language yet but we can get it from his browser
  199.  
  200.  
  201.  
  202.  
  203. //----------------------------------------------------------------------------
  204.  
  205.  
  206. /*
  207. This function processes the requested URI and filters it before the rest of the WP gets it
  208. */
  209. function polyglot_init() {
  210.   global $polyglot_settings,$locale;
  211.  
  212.  
  213.   $content = $_SERVER['REQUEST_URI'];
  214.  
  215.   $languages = implode('|',$polyglot_settings['knownlangs']);
  216.  
  217.   if(!$polyglot_settings['use_helpers_in_uri']){
  218.     $find = array(
  219.     "/^(.*)\/($languages)\/?(.*)$/i"
  220.     );
  221.   }
  222.   else {
  223.     $find = array(
  224.     "/^(.*)\/{$polyglot_settings['uri_helpers']['lang_pref']}\/($languages)\/?(.*)$/i",
  225.     "/^(.*)\/{$polyglot_settings['uri_helpers']['lang_view']}\/($languages)\/?(.*)$/i"
  226.    
  227.     );
  228.   }
  229.  
  230.   $replace = array('','');
  231.  
  232.   if (preg_match($find[0], $content, $matches)) {
  233.   $content = $matches[1] . "/" . $matches[3];
  234.   $_GET['lang_pref'] = $matches[2];
  235.   }
  236.  
  237.   if ($polyglot_settings['use_helpers_in_uri'] && preg_match($find[1], $content, $matches)) {
  238.   $content = $matches[1] . "/" . $matches[3];
  239.   $_GET['lang_view'] = $matches[2];
  240.   }
  241.  
  242.   $_SERVER['REQUEST_URI']= $content;
  243.   $_SERVER['PATH_INFO'] = preg_replace($find,$replace,$_SERVER['PATH_INFO']);
  244.   $_SERVER['PHP_SELF'] = preg_replace($find,$replace,$_SERVER['PHP_SELF']);
  245.  
  246.  
  247.  
  248.   //let's check if user has chosen the preferred language
  249.   if ( isset($_GET['lang_pref']) ) {
  250.     $_GET['lang_pref'] = strtolower($_GET['lang_pref']);
  251.    
  252.     if(  in_array($_GET['lang_pref'],$polyglot_settings['knownlangs'])  ){
  253.       setcookie($polyglot_settings['lang_pref_cookie'], $_GET['lang_pref'], time() + 30000000, COOKIEPATH);
  254.       $polyglot_settings['lang_pref']=$_GET["lang_pref"];
  255.       }
  256.  
  257.   }
  258.   //or he wants to see the post in the certain language
  259.   elseif( isset($_GET['lang_view'])){
  260.     $polyglot_settings['lang_pref'] = strtolower($_GET['lang_view']);
  261.   }
  262.   //or at least has the cookie with some value
  263.   elseif( isset($_COOKIE[$polyglot_settings['lang_pref_cookie']])  ) {
  264.     $polyglot_settings['lang_pref'] = strtolower(trim($_COOKIE[$polyglot_settings['lang_pref_cookie']]));
  265.   }
  266.  
  267.  
  268.  
  269. /**
  270. This part should be removed but for some reason it's needed on some installations:(
  271. */
  272. /*if($polyglot_settings['lang_rewrite'] && !$polyglot_settings['i_have_manually_edited_my_htaccess_file']){
  273.           if(preg_match('/\/lang\/(..)/i',$_SERVER['REQUEST_URI'],$matches)){
  274.             $polyglot_settings['lang_pref']=$matches[1];
  275.           }
  276.          
  277.           if(preg_match('/\/lang-pref\/(..)/i',$_SERVER['REQUEST_URI'],$matches)){
  278.             $polyglot_settings['lang_pref']=$matches[1];
  279.             setcookie($polyglot_settings['lang_pref_cookie'], $polyglot_settings['lang_pref'], time() + 30000000, COOKIEPATH);
  280.           }
  281. }*/
  282.  
  283.  
  284. /*
  285. If the Polyglot is supposed to change the global language settings then... let's do that!
  286. */
  287.     if ($polyglot_settings['lang_change_locale']){
  288.    
  289.       $polyglot_foo = ( isset($polyglot_settings['wplang'][$polyglot_settings['lang_pref']]) ) ? $polyglot_settings['wplang'][$polyglot_settings['lang_pref']] : $polyglot_settings['lang_pref'];
  290.    
  291.       if (!defined('WPLANG')){//just try
  292.         define('WPLANG', $polyglot_foo);
  293.       }
  294.    
  295.       if($locale != $polyglot_foo){
  296.         $locale = $polyglot_foo;
  297.          
  298.         load_default_textdomain();
  299.         include(ABSPATH . WPINC . '/locale.php');
  300.         }
  301.     }
  302.  
  303.  
  304.  
  305.  
  306.   return;
  307. }
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315. /**
  316. Useful function when you want to generate new links with lang-pref settings. You must get rid of the old stuff!
  317. */
  318. function polyglot_uri_cleaner($txt){
  319.   global $polyglot_settings;
  320.  
  321.   $search = array(
  322.   "/{$polyglot_settings['uri_helpers']['lang_view']}\/..\/?/i",
  323.    "/{$polyglot_settings['uri_helpers']['lang_pref']}\/..\/?/i",
  324.    "/(\?|&)lang_view=../i",
  325.    "/(\?|&)lang_pref=../i",
  326.    "/^(.*index\.php)\/$/i"
  327.    );
  328.   
  329.   $replace = array('','','','','$1');
  330.  
  331.   if(!$polyglot_settings['use_helpers_in_uri']){
  332.     $search[] = "/\/(".implode("|",$polyglot_settings['knownlangs']).")\/?/i";
  333.     $replace[] = '';
  334.     }
  335.  
  336.   $txt = preg_replace ( $search, $replace, $txt);
  337.  
  338.   return $txt;
  339. }
  340.  
  341.  
  342. //----------------------------------------------------------------------------
  343.  
  344.  
  345. function polyglot_knownlangs(){
  346. global $polyglot_settings;
  347.   return $polyglot_settings['knownlangs'];
  348. }
  349.  
  350. function polyglot_translations(){
  351.   global $polyglot_settings;
  352.   return $polyglot_settings['trans'];
  353. }
  354.  
  355.  
  356.  
  357. //---------------------------------------------------------------time functions ------------------------
  358.  
  359. function polyglot_date($d = '', $time = ''){
  360.   global $polyglot_settings;
  361.  
  362.   if($d == '' && isset($polyglot_settings['date_format'][$polyglot_settings['lang_pref']])){
  363.     $d = $polyglot_settings['date_format'][$polyglot_settings['lang_pref']];
  364.   }
  365.  
  366.     if(strpos($time, '-')){//trick to find you if we've got "mysql time" or unix timestamp
  367.       $time = mysql2date($d, $time);
  368.       }
  369.     else{
  370.       $time = date($d,$time);
  371.     }
  372.  
  373.   return $time;
  374. }
  375.  
  376. function polyglot_time($d = '', $time = ''){
  377.   global $polyglot_settings;
  378.  
  379.   if($d == '' && isset($polyglot_settings['time_format'][$polyglot_settings['lang_pref']])){
  380.     $d = $polyglot_settings['time_format'][$polyglot_settings['lang_pref']];
  381.   }
  382.  
  383.     if(strpos($time, '-')){//trick to find you if we've got "mysql time" or unix timestamp
  384.       $time = mysql2date($d, $time);
  385.       }
  386.     else{
  387.       $time = date($d,$time);
  388.     }
  389.  
  390.   return $time;
  391. }
  392.  
  393. function polyglot_comment_time($time) {
  394.   global $comment,$polyglot_settings;
  395.  
  396.   if( isset($polyglot_settings['time_format'][$polyglot_settings['lang_pref']]) ){
  397.     $d = $polyglot_settings['time_format'][$polyglot_settings['lang_pref']];
  398.     $comment_date =  $comment->comment_date;
  399.     $time = mysql2date($d, $comment_date);
  400.     }
  401.   return $time;
  402. }
  403.  
  404.  
  405. function polyglot_the_time($time,$d = ''){
  406.   global $post,$polyglot_settings;
  407.  
  408.   if( isset($polyglot_settings['time_format'][$polyglot_settings['lang_pref']]) && $d==''){
  409.     $d = $polyglot_settings['time_format'][$polyglot_settings['lang_pref']];
  410.     $time = $post->post_date;
  411.     $time = mysql2date($d, $time);
  412.   }
  413.   return $time;
  414. }
  415.  
  416.  
  417. function polyglot_comment_date($time) {
  418.   global $comment,$polyglot_settings;
  419.  
  420.   if( isset($polyglot_settings['date_format'][$polyglot_settings['lang_pref']]) ){
  421.     $d = $polyglot_settings['date_format'][$polyglot_settings['lang_pref']];
  422.     $comment_date =  $comment->comment_date;
  423.     $time = mysql2date($d, $comment_date);
  424.     }
  425.   return $time;
  426. }
  427.  
  428.  
  429. function polyglot_the_date($the_date, $d = '', $before = '', $after = ''){
  430.   global $post,$polyglot_settings;
  431.  
  432.   if( isset($polyglot_settings['date_format'][$polyglot_settings['lang_pref']]) && $d=='' && $the_date!='' ){
  433.     $d = $polyglot_settings['date_format'][$polyglot_settings['lang_pref']];
  434.     $the_date = $post->post_date;
  435.     $the_date = $before.mysql2date($d, $the_date).$after;
  436.   }
  437.   return $the_date;
  438. }
  439.  
  440.  
  441. //----------------------------------------------
  442. function polyglot_get_lang(){
  443.   global $polyglot_settings;
  444.  
  445.   return $polyglot_settings['lang_pref'];
  446. }
  447.  
  448.  
  449.  
  450. function get_trans($lang){
  451.   global $polyglot_settings;
  452.  
  453.   if(IsSet($polyglot_settings['trans'][$lang]))
  454.     return $polyglot_settings['trans'][$lang];
  455.   else
  456.     return $lang;
  457. }
  458.  
  459. function polyglot_wp_head(){
  460.   global $polyglot_settings;
  461.   if($polyglot_settings['print_meta']){
  462.     echo "<meta http-equiv=\"Content-Language\" content=\"{$polyglot_settings['lang_pref']}\" />";
  463.   }
  464. }
  465.  
  466.  
  467.  
  468. function polyglot_filter_htmlentities($content, $category = null){
  469.  
  470.   $content = preg_replace("/&lt;(\/){0,1}lang_(..)&gt;/i", "<$1lang_$2>", $content);
  471.    
  472.     return polyglot_filter($content);
  473.    
  474.    
  475. }
  476.  
  477.  
  478. /**
  479. Very simple test if the $lang version is present in the text.
  480. */
  481. function polyglot_lang_exists($lang, $content){
  482.     return (   !(strpos($content, "<lang_$lang>") === false) || !(strpos($content, "[lang_$lang]") === false)   );
  483. }
  484.  
  485. function polyglot_list_langs($flags=false){
  486.   global $polyglot_settings,$wp_query;
  487.         $clean_uri = polyglot_uri_cleaner($_SERVER['REQUEST_URI']);
  488.        
  489.         if(!$polyglot_settings['use_helpers_in_uri']){
  490.           $uri_helper = '';
  491.         }
  492.         else {
  493.           $uri_helper = "{$polyglot_settings['uri_helpers']['lang_pref']}/";
  494.         }
  495.        
  496.        
  497.           foreach($polyglot_settings['knownlangs'] as  $value){
  498.            
  499.             if ( $value==$polyglot_settings['lang_pref'] ) {
  500.               $highlight = "language_item current_language_item";
  501.             } else {
  502.               $highlight = "language_item";
  503.             }
  504.             echo " <a href=\"";
  505.            
  506.             if(  $polyglot_settings['lang_rewrite'] ){
  507.              
  508.               if(strpos(get_settings('permalink_structure'),'index.php') === FALSE){
  509.                   echo polyglot_trailingslashit($clean_uri)."{$uri_helper}{$value}/";
  510.                 }
  511.               else {
  512.                 $qm_pos = strpos($clean_uri,'?');
  513.                 if(strpos($clean_uri,'index.php') === FALSE){
  514.                     if( ($qm_pos) === FALSE){
  515.                         echo polyglot_trailingslashit($clean_uri)."index.php/{$uri_helper}{$value}/";
  516.                       }
  517.                     else {
  518.                         echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos))."index.php/{$uri_helper}{$value}/".substr($clean_uri,$qm_pos);
  519.                       }
  520.                   }
  521.                 else {
  522.                
  523.                     if($qm_pos === FALSE){
  524.                           echo polyglot_trailingslashit($clean_uri)."{$uri_helper}{$value}/";
  525.                         }
  526.                       else {
  527.                           echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos))."{$uri_helper}{$value}/".substr($clean_uri,strpos($clean_uri,'?'));
  528.                         }
  529.                   }
  530.                
  531.                
  532.                
  533.                 }
  534.             }
  535.             else {
  536.            
  537.               //if('' != get_settings('permalink_structure')){
  538.                 echo $clean_uri.((strpos($clean_uri,'?') === FALSE) ? '?' : '&amp;' )."lang_pref={$value}";
  539.               //}
  540.            
  541.             }
  542.             echo "\">". (($flags) ? "<img src=\"".$polyglot_settings['path_to_flags'].$polyglot_settings['flags'][$value] ."\" alt=\"".get_trans($value)."\" title=\"".get_trans($value)."\" />" : get_trans($value)) ."</a>";
  543.           }
  544. }
  545.  
  546.  
  547. /*
  548. Original function in WP doesn't work properly:(
  549. */
  550. function polyglot_trailingslashit($uri){
  551.   if($uri{strlen($uri)-1} != '/')
  552.     return $uri.'/';
  553.   else
  554.     return $uri;
  555. }
  556.  
  557.  
  558. /**
  559. The core function of the plugin. Selects only one language version from the passed text.
  560. */
  561. function polyglot_filter($text, $lang = '') {
  562.   global $polyglot_settings;
  563.  
  564.   if($lang == ''){$lang = $polyglot_settings['lang_pref'];}
  565.  
  566.   $text = preg_replace("/\[(\/){0,1}lang_(..)\]/i", "<$1lang_$2>", $text);//fix for [lang_xx] 
  567.   $text = preg_replace ('/<p>(<(\/){0,1}lang_..>)<\/p>/i',"$1",$text);//fix for <p><lang_xx></p>
  568.  
  569.   $text = preg_replace ('/(<lang_..>)/i',"</lang_all>\\1",$text);//adds lang_all to all other stuff that is not enclosed in lang_xx tags
  570.   $text = preg_replace ('/(<\/lang_..>)/i',"\\1<lang_all>",$text);
  571.   $text = '<lang_all>'.$text.'</lang_all>';
  572.  
  573.  
  574.  
  575.  
  576.   if (preg_match_all ( '/<lang_(..)>/', $text , $match, PREG_PATTERN_ORDER)) {
  577.         if (isset($polyglot_settings['lang_pref']) && polyglot_lang_exists($polyglot_settings['lang_pref'],$text)){
  578.         //lets try to get proper language version
  579.             $text=str_replace("<lang_all>","<lang_{$polyglot_settings['lang_pref']}>",$text);//we don't want just lang_pref parts but also lang_all parts
  580.             $text=str_replace("</lang_all>","</lang_{$polyglot_settings['lang_pref']}>",$text);
  581.      
  582.             $find = "/(?s)<lang_{$polyglot_settings['lang_pref']}>(.*?)<\/lang_{$polyglot_settings['lang_pref']}>/";
  583.             preg_match_all ( $find, $text , $match, PREG_PATTERN_ORDER);
  584.             $text = implode('',$match[1]);
  585.            
  586.         }
  587.         elseif(polyglot_lang_exists($polyglot_settings['default_lang'],$text)){
  588.         //or at least the default language
  589.       $text=str_replace("<lang_all>","<lang_{$polyglot_settings['default_lang']}>",$text);
  590.             $text=str_replace("</lang_all>","</lang_{$polyglot_settings['default_lang']}>",$text);
  591.             $find = "/(?s)<lang_{$polyglot_settings['default_lang']}>(.*?)<\/lang_{$polyglot_settings['default_lang']}>/";
  592.             preg_match_all ( $find, $text , $match, PREG_PATTERN_ORDER);
  593.             $text = implode('',$match[1]);
  594.         }
  595.        
  596.          else {
  597.             //all untranslated stuff
  598.             $text=str_replace("<lang_all>","",$text);
  599.             $text=str_replace("</lang_all>","",$text);
  600.             $find = "/(?s)<lang_(.*?)>(.*?)<\/lang_(.*?)>/";
  601.             $replace = "";
  602.             $text = preg_replace($find,$replace,$text);
  603.         }
  604.     }
  605.  
  606.   return str_replace(array("<lang_all>","</lang_all>"),array('',''),$text);
  607. }
  608.  
  609.  
  610. /**
  611. Handy shortcuts of polyglot_filter function for direct use in the templates
  612. */
  613. function p__($text){
  614.   return polyglot_filter($text);
  615. }
  616.  
  617. function p__e($text){
  618.   return polyglot_filter($text);
  619. }
  620.  
  621.  
  622. /**
  623. Does the same as polyglot_filter but shows the message that informs visitor that selected language version is not available
  624. */
  625. function polyglot_filter_with_message($text){
  626. global $polyglot_settings;
  627.   $text = trim(polyglot_filter($text));
  628.   if($text == ''){
  629.     $text = polyglot_filter($polyglot_settings['text_is_missing_message']);
  630.   }
  631.   return $text;
  632. }
  633.  
  634.  
  635. /*function safe_link(){
  636.   global $post;
  637.  
  638.   $permalink = get_settings('home') . '/' . get_settings('blogfilename') . '?';
  639.  
  640.     if ($post->post_status == 'static')
  641.       $permalink .= 'page_id';
  642.     else
  643.       $permalink .= 'p';
  644.      
  645.   $permalink .= '='.$post->ID;
  646.    
  647.  
  648.   return $permalink;
  649. }*/
  650.  
  651.  
  652. /**
  653. Prints out the list of other language versions contained in the current post.
  654. */
  655. function polyglot_other_langs($none='none', $before='<ul>', $after='</ul>', $pre='<li>(', $afters=')</li>'){
  656.     global $polyglot_settings, $post;
  657.  
  658.  
  659.   if(!$polyglot_settings['use_helpers_in_uri']){
  660.     $uri_helper = '';
  661.   }
  662.   else {
  663.     $uri_helper = "{$polyglot_settings['uri_helpers']['lang_view']}/";
  664.   }
  665.  
  666.     $content = $post->post_content;//fred
  667.    
  668.     $before = polyglot_filter($before);
  669.     $after = polyglot_filter($after);
  670.     $pre = polyglot_filter($pre);
  671.     $afters = polyglot_filter($afters);
  672.     $other_langs = polyglot_filter($none);
  673.  
  674.     if (preg_match_all ( '/[<|\[]lang_(..)[>|\]]/', $content , $match, PREG_PATTERN_ORDER)) {
  675.         $match = array_unique($match[1]);
  676.         $other_langs = $before;
  677.      
  678.         foreach ($match as $lang){
  679.             if ($polyglot_settings['lang_pref'] != $lang) {
  680.        
  681.         $foo = ($polyglot_settings['use_flags'] ) ?  "<img src=\"".$polyglot_settings['path_to_flags'].$polyglot_settings['flags'][$lang] ."\" alt=\"".get_trans($lang)."\" title=\"".get_trans($lang)."\" />" : get_trans($lang);
  682.  
  683.            
  684.         $other_langs .= "$pre<a href='".get_permalink();
  685.      
  686.                 if ($polyglot_settings['lang_rewrite']) {
  687.           if($polyglot_settings['i_have_manually_edited_my_htaccess_file'] || strpos(get_permalink(),'?') === false){
  688.             $other_langs .= "{$uri_helper}{$lang}/";
  689.             }
  690.           else {
  691.             $other_langs .= "&amp;lang_view=$lang'";
  692.           }
  693.                 } else {
  694.           if(strpos(get_permalink(),'?') === false){
  695.               $other_langs .= "?lang_view=$lang'";
  696.           }
  697.           else {
  698.               $other_langs .= "&amp;lang_view=$lang'";
  699.           }
  700.                    
  701.                 }
  702.        
  703.         $other_langs .= "'>{$foo}</a>$afters";
  704.             }
  705.         }
  706.     if($other_langs != $before)//to avoid empty <ul></ul>
  707.           $other_langs .= $after;
  708.     else
  709.       $other_langs = $none;
  710.     }
  711.     echo $other_langs;
  712. }
  713.  
  714. /**
  715. Prepares text for slug
  716. */
  717. function polyglot_sanitize_title($text){
  718.   global $polyglot_settings;
  719.  
  720.  
  721.   $text = polyglot_filter($text, $polyglot_settings['default_lang']);
  722.  
  723.   return $text;
  724. }
  725.  
  726. //------------code from 'translate categories' plugin-----------
  727.  
  728. function polyglot_translate_callback($matches){
  729.  
  730. return $matches[1].__($matches[2]).$matches[3];
  731.  
  732. }
  733. /**
  734. Not very nice way how to tranlate category name:(
  735. It uses standard gettex function __ and works only when we have the category name in the .mo file!
  736. */
  737. function polyglot_translate_the_category($text){
  738.  
  739.   return preg_replace_callback('/(<a[^>]*>)(.*?)(<\/a>)/i','polyglot_translate_callback',$text); 
  740. }
  741.  
  742. //---------------------------------------------------------------------------
  743.  
  744. function polyglot_get_users_pref_lang(){
  745.       GLOBAL $polyglot_settings;
  746.       $deflang = $polyglot_settings['default_lang'];
  747.      
  748.       # An advanced PHP Language Detection Script
  749.       # by Fibergeek (fibergeek @ codegurus.be)
  750.       #
  751.       # This script is a modification to a script I found via google
  752.       #
  753.       # 2003-12-18 - Version 1 (I added...)
  754.       #   - you can now also specify the country code in the $knowlangs array
  755.       #   - extraction of the country code ($country)
  756.       #   - I fully documented the code
  757.       #
  758.       # 2004-01-07 - Version 2 (I added...)
  759.       #   - you can now make $knowlangs NULL (the script will set to array to all known languages (ISO-639))
  760.       #
  761.       # NOTE : for those using Brion's script, I renamed $lastquality to $quality
  762.       #
  763.       # Found at URL    : http://mail.wikipedia.org/pipermail/wikitech-l/2002-October/001068.html
  764.       # Assumed creator : Brion VIBBER (wikitech-l@wikipedia.org)
  765.       # HTTP reference  : RFC 2616 - ftp://ftp.isi.edu/in-notes/rfc2616.txt
  766.      
  767.       # ==================================================================================================
  768.       # TODO
  769.       #   You need to add the 2 lines to your source code, and change the content of them of course ;-)
  770.       # ==================================================================================================
  771.       #$polyglot_settings['knownlangs'] = NULL;                                // default to all known languages (ISO-639)
  772.       #$deflang    = NULL;                                // there is no default language
  773.       #
  774.       #$polyglot_settings['knownlangs'] = array('en-us', 'en-uk', 'en', 'nl'); // We know : English (US & UK) and Dutch
  775.       #$deflang    = 'en-uk';                             // In case of an error, we default to English UK
  776.      
  777.       # ==================================================================================================
  778.       # INFORMATION
  779.       # The following variables are returned by this program
  780.       #   $lclist  : the full list with the languages accepted by the client's browser
  781.       #   $lctag   : the tag we are supporting (includes the country code if any)
  782.       #   $quality : the quality
  783.       #   $lang    : the language code
  784.       #   $country : the country code (if any)
  785.       #
  786.       # The following variables are used by this program (and may be overwritten if you use them also!)
  787.       #   $langtag
  788.       #   $qvalue
  789.       #   $eachbit
  790.       #   $tmppos
  791.       #   $tmplclist
  792.       #   $tmplctag
  793.       #   $tmptagarray
  794.       # ==================================================================================================
  795.      
  796.       # ==================================================================================================
  797.       # THE SCRIPT
  798.       # ==================================================================================================
  799.      
  800.       # Check that $knowlangs is an array!
  801.       # NOTE : the list is taken from this URL : http://www.w3.org/WAI/ER/IG/ert/iso639.htm
  802.       if(!is_array($polyglot_settings['knownlangs']))
  803.       {
  804.         if(is_string($polyglot_settings['knownlangs']) || is_object($polyglot_settings['knownlangs']) || $polyglot_settings['knownlangs'] != NULL)
  805.           die("Fibergeek's PHP Language Detection Script : You need define \$polyglot_settings['knownlangs'] as an array or as NULL!<br>\n");
  806.         $polyglot_settings['knownlangs'] = array('aa', 'ab', 'af', 'am', 'ar', 'as', 'ay', 'az', 'ba', 'be', 'bg', 'bh', 'bi', 'bn', 'bo', 'br', 'ca', 'co', 'cs', 'cy', 'da', 'de', 'dz', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'ha', 'he', 'hi', 'hr', 'hu', 'hy', 'ia', 'ie', 'ik', 'in', 'is', 'it', 'iw', 'ja', 'ji', 'jw', 'ka', 'kk', 'kl', 'km', 'kn', 'ko', 'ks', 'ku', 'ky', 'la', 'ln', 'lo', 'lt', 'lv', 'mg', 'mi', 'mk', 'ml', 'mn', 'mo', 'mr', 'ms', 'mt', 'my', 'na', 'ne', 'nl', 'no', 'oc', 'om', 'or', 'pa', 'pl', 'ps', 'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sd', 'sg', 'sh', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'ss', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'uk', 'ur', 'uz', 'vi', 'vo', 'wo', 'xh', 'yo', 'zh', 'zu');
  807.       }
  808.      
  809.       # Initalisation of the default variables
  810.       if(isset($HTTP_SERVER_VARS))
  811.         $lclist = trim($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']); # PHP running from a server
  812.       else
  813.         $lclist = trim($_SERVER['HTTP_ACCEPT_LANGUAGE']);          # PHP 5.0 when the old server variables disabled
  814.       $lctag   = $deflang;
  815.       $tmppos  = strpos($lctag, '-');
  816.       $quality = 0.0;
  817.       if($tmppos == FALSE or $tmppos == NULL)
  818.       {
  819.         $lang    = $deflang;
  820.         if($deflang == NULL)
  821.           $country = NULL;
  822.         else
  823.           $country = '';
  824.       }
  825.       else
  826.       {
  827.         $lang    = substr($lctag, 0, $tmppos);
  828.         $country = substr($lctag, $tmppos + 1);
  829.         echo "lang sub = $lang";
  830.       }
  831.      
  832.       #
  833.       $langtag = '((?:[a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*)';
  834.       $qvalue  ='(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3}))';
  835.       $eachbit = '^' . $langtag . '(?:;q=' . $qvalue . ')?(?:,\s*)?(.*)$';
  836.      
  837.       #
  838.       $tmplclist = $lclist;
  839.      
  840.       # The loop
  841.       while(strlen($tmplclist))
  842.       {
  843.         if(preg_match("/$eachbit/", $tmplclist, $tmptagarray)) # requires 3.0.9
  844.         {
  845.           # Extract data from the tag list
  846.           $tmplctag = $tmptagarray[1];
  847.           $tmpquality = $tmptagarray[2];
  848.           if(strlen($tmpquality) == 0)
  849.             $tmpquality = 1;
  850.           $tmplclist = $tmptagarray[3];
  851.      
  852.           # Find the tag in our $polyglot_settings['knownlangs'] array (this search includes the country code if set)
  853.           if(in_array($tmplctag, $polyglot_settings['knownlangs']) and $tmpquality > $quality)
  854.           {
  855.             # Extract the language & quality
  856.             $lctag   = $tmplctag;
  857.             $lang    = $tmplctag;
  858.             $country = '';
  859.             $quality = $tmpquality;
  860.           }
  861.           else
  862.           {
  863.             # Not found, does the tag include a country code?
  864.             $tmppos = strpos($tmplctag, '-');
  865.             if($tmppos <> FALSE)
  866.             {
  867.               # OK, the tag includes a country code but it's not in the $polyglot_settings['knownlangs'] array, let's extract the language and look it up
  868.               if(in_array(substr($tmplctag, 0, $tmppos), $polyglot_settings['knownlangs']) and $tmpquality > $quality)
  869.               {
  870.                 # Extract the language, country & quality
  871.                 $lctag   = $tmplctag;
  872.                 $lang    = substr($tmplctag, 0, $tmppos);
  873.                 $country = substr($tmplctag, $tmppos + 1);
  874.                 $quality = $tmpquality;
  875.               }
  876.             }
  877.           }
  878.         }
  879.         else
  880.         {
  881.           # There was an error, abort the loop
  882.           break;
  883.         }
  884.       }
  885.    return $lang;
  886.   }//get_users_pref_lang()
  887.  
  888.  
  889.  
  890.  
  891. //===========================  WIDGET CODE============================
  892.  
  893. function widget_polyglot_init() {
  894.  
  895.   if ( !function_exists('register_sidebar_widget') )
  896.     return;
  897.  
  898.   function widget_polyglot($args) {
  899.     extract($args);
  900.     $options = get_option('widget_polyglot');
  901.     $title = $options['title'];
  902.     $listtype = $options['listtype'] ? true : false ;
  903.  
  904.     echo $before_widget . $before_title . polyglot_filter($title) . $after_title . '<br /><ul class="language_item">';
  905.     echo polyglot_list_langs($listtype) . '</ul>';
  906.     echo $after_widget;
  907.   }
  908.  
  909.   function widget_polyglot_control() {
  910.  
  911.     // Get our options and see if we're handling a form submission.
  912.     $options = get_option('widget_polyglot');
  913.     if ( !is_array($options) )
  914.       $options = array('title'=>__('Language'), 'listtype'=>'');
  915.     if ( $_POST['polyglot-submit'] ) {
  916.  
  917.       // Remember to sanitize and format user input appropriately.
  918.       $options['title'] = strip_tags(stripslashes($_POST['polyglot-title']));
  919.       $options['listtype'] = $_POST['polyglot-listtype'];
  920.       update_option('widget_polyglot', $options);
  921.     }
  922.  
  923.     // Be sure you format your options to be valid HTML attributes.
  924.     $title = htmlspecialchars($options['title'], ENT_QUOTES);
  925.     $listtype = $options['listtype'];
  926.  
  927.     echo '<p style="text-align:right;"><label for="polyglot-title">Title: <input style="width: 200px;" id="polyglot-title" name="polyglot-title" type="text" value="'.$title.'" /></label></p>';
  928.     echo '<p style="text-align:right;">Display as: <input type="radio" id="polyListtypeText" name="polyglot-listtype" value=""';
  929.     if ('' == $listtype) echo 'checked="checked" ';
  930.     echo '/><label for="polyListtypeText">normal list</label>
  931.     <input type="radio" id="polyListtypeFlags" name="polyglot-listtype" value="true"' ;
  932.     if ('true' == $listtype) echo 'checked="checked" ';
  933.     echo '/><label for="polyListtypeFlags">flags list</label></p>';
  934.     echo '<input type="hidden" id="polyglot-submit" name="polyglot-submit" value="1" />';
  935.   }
  936.  
  937.   function widget_polyglot_style() {
  938.   ?>
  939.   <style type="text/css">li#polyglot ul li:before, .language_item li{content:"";list-style-type:none;display:inline !important;padding: 2px !important;margin: 0 !important;}</style>
  940.   <?php
  941.   }
  942.  
  943.   register_sidebar_widget('Polyglot', 'widget_polyglot');
  944.   register_widget_control('Polyglot', 'widget_polyglot_control', 300, 90);
  945.   if ( is_active_widget('widget_polyglot') )
  946.     add_action('wp_head', 'widget_polyglot_style');
  947. }
  948.  
  949. // Run our code later in case this loads prior to any required plugins.
  950. add_action('plugins_loaded', 'widget_polyglot_init');
  951.  
  952.  
  953. //================================Backward Compatibility=============================
  954. function lang_picker_respect_more($text){return p