Annonce

Important, migration recommandée : WordPress 2.6.3 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.

#176 04-01-2008 17:07:58

seguelac
Connaisseur WP
Date d'inscription: 19-11-2007
Messages: 10

Re: [Topic unique] Polyglot: plugin de traduction en dur pour wordpress

bonjour,

J'ai installé polyglot sur mon blog et sa marche très bien par contre il y a une solutions pour faire pareil avec les meta tag ?
www.exclusivereception.com
Ou dans ce cas est qu'il est plus facile d'avoir deux blogs distincs ?

Hors ligne

 

#177 04-01-2008 17:48:54

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

Re: [Topic unique] Polyglot: plugin de traduction en dur pour wordpress

Pour le moment, les tags ne peuvent pas être multilingues. Peut-être avec la prochaine version de Polyglot ?


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

Hors ligne

 

#178 04-01-2008 17:53:03

seguelac
Connaisseur WP
Date d'inscription: 19-11-2007
Messages: 10

Re: [Topic unique] Polyglot: plugin de traduction en dur pour wordpress

merci, et y a t il  une autre solution ?

Hors ligne

 

#179 04-01-2008 18:01:57

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

Re: [Topic unique] Polyglot: plugin de traduction en dur pour wordpress

A part taper les tags dans les diverses langues (pain bread, par exemple) pour chaque article, je ne vois pas.... roll

Evidemment, à l'affichage du nuage tous les tags seront visibles (quelque soit la langue choisie par le visiteur) mais est-ce vraiment génant ?


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

Hors ligne

 

#180 06-01-2008 15:23:05

tenprod
Connaisseur WP
Date d'inscription: 13-05-2007
Messages: 34

Re: [Topic unique] Polyglot: plugin de traduction en dur pour wordpress

Bonjour,

j'ai un souci avec polyglot : j'ai bien installé tout comme indiqué (par défaut ou presque), que ce soit dans un post ou dans une page, j'ai ajouté les tags :

[lang_fr]bonne année[/lang_fr]
[lang_en]Happy New Year[/lang_en]

sauf que seule la version française s'affiche quand on clique sur le drapeau anglais.

à noter que j'ai installé Ajaxed WP parmi les nombreux plugins de mon site.

voyez ici : http://www.ctn-music.com
login : wordpress
mot de passe : wordpress

le site devrait ouvrir demain, donc je serai vraiment éternellement reconnaissant à celui qui pourrait m'éclairer un peu ange


Women Folk Music & Discoveries : http://www.ctn-music.com

Hors ligne

 

#181 07-01-2008 10:10:23

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

Re: [Topic unique] Polyglot: plugin de traduction en dur pour wordpress

@tenprod : Il faudrait nous faire une copie du début du polyglot.php pour que l'on puisse voir les paramètres utilisés. A priori, il semble y avoir un souci avec la structure du lien généré par Polyglot.

Cordialement


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

Hors ligne

 

#182 07-01-2008 12:52:52

tenprod
Connaisseur WP
Date d'inscription: 13-05-2007
Messages: 34

Re: [Topic unique] Polyglot: plugin de traduction en dur pour wordpress

voici le code de polyglot.php sur mon serveur
sachez que pour l'instant je l'ai désactivé, en attendant une autre solution...

merci !

Code:

  1. <?php
  2.  
  3. /*
  4.  
  5. Plugin Name: Polyglot
  6.  
  7. Plugin URI: http://fredfred.net/skriker/index.php/polyglot
  8.  
  9. 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>.
  10.  
  11. Version: 2.3
  12.  
  13. Author: Martin Chlupac
  14.  
  15. Author URI: http://fredfred.net/skriker/
  16.  
  17. Update: http://fredfred.net/skriker/plugin-update.php?p=198
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  This program is free software; you can redistribute it and/or
  24.  
  25.  modify it under the terms of the GNU General Public License
  26.  
  27.  as published by the Free Software Foundation; either version 2
  28.  
  29.  of the License, or (at your option) any later version.
  30.  
  31. */
  32.  
  33.  
  34.  
  35. // Default language version - used when proper language version of the text is not present or the visitor's prefered language is unknown
  36.  
  37. $polyglot_settings['default_lang'] = 'fr';
  38.  
  39.  
  40.  
  41. //You can define your own translations of language shortcuts
  42.  
  43.  
  44.  
  45. $polyglot_settings['trans']['en'] = 'english';
  46.  
  47. $polyglot_settings['trans']['de'] = 'deutsch';
  48.  
  49. $polyglot_settings['trans']['nl'] = 'nederlands';
  50.  
  51. $polyglot_settings['trans']['fr'] = 'française';
  52.  
  53.  
  54.  
  55. $polyglot_settings['trans']['cs'] = 'Ä esky';
  56.  
  57. $polyglot_settings['trans']['it'] = 'italiano';
  58.  
  59. $polyglot_settings['trans']['sv'] = 'svenska';
  60.  
  61.  
  62.  
  63.  
  64.  
  65. //Which language versions you offer for the whole web - use the proper ISO codes!
  66.  
  67. $polyglot_settings['knownlangs'] = array('en','fr');
  68.  
  69.  
  70.  
  71. //set to 'true' if there should be shown flags instead of names of languages
  72.  
  73. $polyglot_settings['use_flags'] = true;
  74.  
  75.  
  76.  
  77. //list of ISO codes and their image represantations (flags).
  78.  
  79. //all flags can be found in 'polyglot_flags' directory
  80.  
  81.  
  82.  
  83. $polyglot_settings['flags']['en'] = 'gb.png';
  84.  
  85. $polyglot_settings['flags']['de'] = 'de.png';
  86.  
  87. $polyglot_settings['flags']['nl'] = 'nl.png';
  88.  
  89. $polyglot_settings['flags']['fr'] = 'fr.png';
  90.  
  91.  
  92.  
  93. $polyglot_settings['flags']['cs'] = 'cz.png';
  94.  
  95. $polyglot_settings['flags']['it'] = 'it.png';
  96.  
  97. $polyglot_settings['flags']['sv'] = 'se.png';
  98.  
  99.  
  100.  
  101. //time format for each language
  102.  
  103. //if not set - default WP time format is used
  104.  
  105. $polyglot_settings['time_format']['en'] = 'g.i a';
  106.  
  107. $polyglot_settings['time_format']['de'] = 'G:i';
  108.  
  109. $polyglot_settings['time_format']['nl'] = 'G:i';
  110.  
  111. $polyglot_settings['time_format']['fr'] = 'G:i';
  112.  
  113. $polyglot_settings['time_format']['cs'] = 'G.i';
  114.  
  115.  
  116.  
  117. $polyglot_settings['date_format']['en'] = 'Y-m-d';
  118.  
  119. $polyglot_settings['date_format']['de'] = 'j. F Y';
  120.  
  121. $polyglot_settings['date_format']['nl'] = 'j F Y';
  122.  
  123. $polyglot_settings['date_format']['fr'] = 'j F Y';
  124.  
  125. $polyglot_settings['date_format']['cs'] = 'j. n. Y';
  126.  
  127.  
  128.  
  129.  
  130.  
  131. /*path to the plugin directory
  132.  
  133. don't forget trailing slash if you are changing this value
  134.  
  135. */
  136.  
  137. $polyglot_settings['path_to_flags'] = get_bloginfo('wpurl').'/wp-content/plugins/polyglot_flags/';
  138.  
  139.  
  140.  
  141. //if you use WP older than 1.5 you must use this:
  142.  
  143. //$polyglot_settings['path_to_flags'] = get_bloginfo('url').'/wp-content/plugins/';
  144.  
  145.  
  146.  
  147.  
  148.  
  149. //default text that is shown when the proper language version of the post is missing and even the default language version is not there
  150.  
  151. // use $polyglot_settings['text_is_missing_message'] = '';  if you want to turn it off.
  152.  
  153. $polyglot_settings['text_is_missing_message'] = '[lang_en]Sorry, but this post is not available in English[/lang_en][lang_cs]Tento příspÄ›vek bohužel není dostupný v Ä eÅ¡tinÄ›.[/lang_cs]';
  154.  
  155.  
  156.  
  157. //----------------------advanced-----------------------------------------------------------------------
  158.  
  159.  
  160.  
  161. //Should be printed <meta http-equiv="Content-Language" content="xx" /> where xx stands for ISO code of current language?
  162.  
  163. $polyglot_settings['print_meta'] = false;
  164.  
  165.  
  166.  
  167. // Name of the cookie - default:'wordpress_lang_pref'.$cookiehash
  168.  
  169. $polyglot_settings['lang_pref_cookie'] = 'wordpress_lang_pref'.COOKIEHASH;
  170.  
  171.  
  172.  
  173. /*
  174.  
  175. Should Polyglot attempt to dynamically change the WP locale
  176.  
  177. setting based on user's prefered language? Note, for this to work
  178.  
  179. .mo files must be renamed to match the name specified in $polyglot_settings['wplang'] array
  180.  
  181. but you don't have to rename anything in most cases as there is already list of current WP versions present.
  182.  
  183. */
  184.  
  185. $polyglot_settings['lang_change_locale'] = TRUE;
  186.  
  187.  
  188.  
  189. /*
  190.  
  191. To use permalinks for other languages set this to "true".
  192.  
  193. You probably don't have to do anything else if you have "index.php" in your permalink structure.
  194.  
  195. 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.
  196.  
  197. For more info check: http://www.google.com/search?hl=en&q=mod_rewrite
  198.  
  199. */
  200.  
  201. $polyglot_settings['lang_rewrite'] = true;
  202.  
  203.  
  204.  
  205. /**
  206.  
  207. This should stay turned off unless you had problems with rules in your .htaccess file and you have edited them manually.
  208.  
  209. */
  210.  
  211. $polyglot_settings['i_have_manually_edited_my_htaccess_file'] = false; //change this only if you know what you are doing!
  212.  
  213.  
  214.  
  215. /**
  216.  
  217. There are some helpers added (/lang/, /lang-pref/) by default to the url to help Polyglot distinguish between language code and short post slug.
  218.  
  219. These can be turned off. But don't turn them off unless you have a good reason to do that.
  220.  
  221. */
  222.  
  223. $polyglot_settings['use_helpers_in_uri'] = true;
  224.  
  225.  
  226.  
  227. /**
  228.  
  229. If you want to use these helpers but you want to change them - do that here:
  230.  
  231. */
  232.  
  233. $polyglot_settings['uri_helpers']['lang_view'] = 'lang';
  234.  
  235. $polyglot_settings['uri_helpers']['lang_pref'] = 'lang-pref';
  236.  
  237.  
  238.  
  239.  
  240.  
  241. /*
  242.  
  243. 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.
  244.  
  245. Add your language or change it as you need.
  246.  
  247. */
  248.  
  249. $polyglot_settings['wplang']['ar'] = 'ar';
  250.  
  251. $polyglot_settings['wplang']['bg'] = 'bg_BG';
  252.  
  253. $polyglot_settings['wplang']['cs'] = 'cs_CZ';
  254.  
  255. $polyglot_settings['wplang']['cy'] = 'cy';
  256.  
  257. $polyglot_settings['wplang']['da'] = 'da_DK';
  258.  
  259. $polyglot_settings['wplang']['de'] = 'de_DE';
  260.  
  261. $polyglot_settings['wplang']['el'] = 'el';
  262.  
  263. $polyglot_settings['wplang']['eo'] = 'eo';
  264.  
  265. $polyglot_settings['wplang']['es'] = 'es_ES';
  266.  
  267. $polyglot_settings['wplang']['fa'] = 'fa';
  268.  
  269. $polyglot_settings['wplang']['fi'] = 'fi_FI';
  270.  
  271. $polyglot_settings['wplang']['fr'] = 'fr_FR';//fr_BE
  272.  
  273. $polyglot_settings['wplang']['hu'] = 'hu_HU';
  274.  
  275. $polyglot_settings['wplang']['it'] = 'it_IT';
  276.  
  277. $polyglot_settings['wplang']['ja'] = 'ja_JP';
  278.  
  279. $polyglot_settings['wplang']['ko'] = 'ko';
  280.  
  281. $polyglot_settings['wplang']['nb'] = 'nb_NO';//nn_NO
  282.  
  283. $polyglot_settings['wplang']['pl'] = 'pl_PL';
  284.  
  285. $polyglot_settings['wplang']['pt'] = 'pt_BR';
  286.  
  287. $polyglot_settings['wplang']['ru'] = 'ru_RU';
  288.  
  289. $polyglot_settings['wplang']['sk'] = 'sk';
  290.  
  291. $polyglot_settings['wplang']['sq'] = 'sq';
  292.  
  293. $polyglot_settings['wplang']['sr'] = 'sr_CS';
  294.  
  295. $polyglot_settings['wplang']['sv'] = 'sv_SE';
  296.  
  297. $polyglot_settings['wplang']['zh'] = 'zh_CN';
  298.  
  299.  
  300.  
  301. //============================================STOP EDITING HERE! (unless you know what you are doing)=====================================
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317. //=====================================HOOKS=====================================
  318.  
  319. add_filter('the_time','polyglot_the_time',10,2);
  320.  
  321. add_filter('get_comment_time','polyglot_comment_time');
  322.  
  323. add_filter('the_date','polyglot_the_date',10,4);
  324.  
  325. add_filter('get_comment_date','polyglot_comment_date');
  326.  
  327. add_filter('the_category_rss','__',1);
  328.  
  329. add_filter('the_content', 'polyglot_filter_with_message',1);
  330.  
  331. add_filter('the_title', 'polyglot_filter',1);
  332.  
  333. add_filter('wp_list_pages', 'polyglot_filter_htmlentities',1);
  334.  
  335. add_filter('single_post_title', 'polyglot_filter',1);
  336.  
  337. add_filter('single_cat_title', 'polyglot_filter',1);
  338.  
  339. add_filter('wp_title', 'polyglot_filter',1);
  340.  
  341. add_filter('the_content_rss', 'polyglot_filter',1);
  342.  
  343. add_filter('the_excerpt_rss', 'polyglot_filter',1);
  344.  
  345. add_filter('the_title_rss', 'polyglot_filter',1);
  346.  
  347. add_filter('comment_text_rss', 'polyglot_filter',1);
  348.  
  349. add_filter('bloginfo_rss', 'polyglot_filter',1);
  350.  
  351. add_filter('the_excerpt', 'polyglot_filter',1);
  352.  
  353. add_filter('comment_text', 'polyglot_filter',1);
  354.  
  355.  
  356.  
  357. add_filter('list_cats','__',1);//we register standard gettext function
  358.  
  359. add_filter('the_category','polyglot_translate_the_category');
  360.  
  361.  
  362.  
  363. add_action('wp_head','polyglot_wp_head');
  364.  
  365. add_action('init','polyglot_init',1);
  366.  
  367.  
  368.  
  369. add_filter('bloginfo', 'polyglot_filter',1,1);
  370.  
  371. /*
  372.  
  373. You probably have to incerase the length of 'cat_name' column in MySql table 'categories' in your DB to be able to use this.
  374.  
  375. 'cat_name' is by default just 55 characters long.
  376.  
  377. */
  378.  
  379. add_filter('the_category', 'polyglot_filter_htmlentities',1);
  380.  
  381. add_filter('list_cats', 'polyglot_filter_htmlentities',2);
  382.  
  383.  
  384.  
  385. add_filter('sanitize_title', 'polyglot_sanitize_title', 1);
  386.  
  387.  
  388.  
  389. add_filter('polyglot_filter','polyglot_filter');
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397. //here we try to guess which language user wants
  398.  
  399. //========================================
  400.  
  401.  
  402.  
  403. $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
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413. //----------------------------------------------------------------------------
  414.  
  415.  
  416.  
  417.  
  418.  
  419. /*
  420.  
  421. This function processes the requested URI and filters it before the rest of the WP gets it
  422.  
  423. */
  424.  
  425. function polyglot_init() {
  426.  
  427.   global $polyglot_settings,$locale;
  428.  
  429.  
  430.  
  431.  
  432.  
  433.   $content = $_SERVER['REQUEST_URI'];
  434.  
  435.  
  436.  
  437.   $languages = implode('|',$polyglot_settings['knownlangs']);
  438.  
  439.  
  440.  
  441.   if(!$polyglot_settings['use_helpers_in_uri']){
  442.  
  443.     $find = array(
  444.  
  445.     "/^(.*)\/($languages)\/?(.*)$/i"
  446.  
  447.     );
  448.  
  449.   }
  450.  
  451.   else {
  452.  
  453.     $find = array(
  454.  
  455.     "/^(.*)\/{$polyglot_settings['uri_helpers']['lang_pref']}\/($languages)\/?(.*)$/i",
  456.  
  457.     "/^(.*)\/{$polyglot_settings['uri_helpers']['lang_view']}\/($languages)\/?(.*)$/i"
  458.  
  459.    
  460.  
  461.     );
  462.  
  463.   }
  464.  
  465.  
  466.  
  467.   $replace = array('','');
  468.  
  469.  
  470.  
  471.   if (preg_match($find[0], $content, $matches)) {
  472.  
  473.   $content = $matches[1] . "/" . $matches[3];
  474.  
  475.   $_GET['lang_pref'] = $matches[2];
  476.  
  477.   }
  478.  
  479.  
  480.  
  481.   if ($polyglot_settings['use_helpers_in_uri'] && preg_match($find[1], $content, $matches)) {
  482.  
  483.   $content = $matches[1] . "/" . $matches[3];
  484.  
  485.   $_GET['lang_view'] = $matches[2];
  486.  
  487.   }
  488.  
  489.  
  490.  
  491.   $_SERVER['REQUEST_URI']= $content;
  492.  
  493.   $_SERVER['PATH_INFO'] = preg_replace($find,$replace,$_SERVER['PATH_INFO']);
  494.  
  495.   $_SERVER['PHP_SELF'] = preg_replace($find,$replace,$_SERVER['PHP_SELF']);
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.   //let's check if user has chosen the preferred language
  504.  
  505.   if ( isset($_GET['lang_pref']) ) {
  506.  
  507.     $_GET['lang_pref'] = strtolower($_GET['lang_pref']);
  508.  
  509.    
  510.  
  511.     if(  in_array($_GET['lang_pref'],$polyglot_settings['knownlangs'])  ){
  512.  
  513.       setcookie($polyglot_settings['lang_pref_cookie'], $_GET['lang_pref'], time() + 30000000, COOKIEPATH,COOKIE_DOMAIN);
  514.  
  515.       $polyglot_settings['lang_pref']=$_GET["lang_pref"];
  516.  
  517.       }
  518.  
  519.  
  520.  
  521.   }
  522.  
  523.   //or he wants to see the post in the certain language
  524.  
  525.   elseif( isset($_GET['lang_view'])){
  526.  
  527.     $polyglot_settings['lang_pref'] = strtolower($_GET['lang_view']);
  528.  
  529.   }
  530.  
  531.   //or at least has the cookie with some value
  532.  
  533.   elseif( isset($_COOKIE[$polyglot_settings['lang_pref_cookie']])  ) {
  534.  
  535.     $polyglot_settings['lang_pref'] = strtolower(trim($_COOKIE[$polyglot_settings['lang_pref_cookie']]));
  536.  
  537.   }
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545. /**
  546.  
  547. This part should be removed but for some reason it's needed on some installations:(
  548.  
  549. */
  550.  
  551. /*if($polyglot_settings['lang_rewrite'] && !$polyglot_settings['i_have_manually_edited_my_htaccess_file']){
  552.  
  553.           if(preg_match('/\/lang\/(..)/i',$_SERVER['REQUEST_URI'],$matches)){
  554.  
  555.             $polyglot_settings['lang_pref']=$matches[1];
  556.  
  557.           }
  558.  
  559.          
  560.  
  561.           if(preg_match('/\/lang-pref\/(..)/i',$_SERVER['REQUEST_URI'],$matches)){
  562.  
  563.             $polyglot_settings['lang_pref']=$matches[1];
  564.  
  565.             setcookie($polyglot_settings['lang_pref_cookie'], $polyglot_settings['lang_pref'], time() + 30000000, COOKIEPATH);
  566.  
  567.           }
  568.  
  569. }*/
  570.  
  571.  
  572.  
  573.  
  574.  
  575. /*
  576.  
  577. If the Polyglot is supposed to change the global language settings then... let's do that!
  578.  
  579. */
  580.  
  581.     if ($polyglot_settings['lang_change_locale']){
  582.  
  583.    
  584.  
  585.       $polyglot_foo = ( isset($polyglot_settings['wplang'][$polyglot_settings['lang_pref']]) ) ? $polyglot_settings['wplang'][$polyglot_settings['lang_pref']] : $polyglot_settings['lang_pref'];
  586.  
  587.    
  588.  
  589.       if (!defined('WPLANG')){//just try
  590.  
  591.         define('WPLANG', $polyglot_foo);
  592.  
  593.       }
  594.  
  595.    
  596.  
  597.       if($locale != $polyglot_foo){
  598.  
  599.         $locale = $polyglot_foo;
  600.  
  601.          
  602.  
  603.         load_default_textdomain();
  604.  
  605.         }
  606.  
  607.     }
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.   return;
  618.  
  619. }
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635. /**
  636.  
  637. Useful function when you want to generate new links with lang-pref settings. You must get rid of the old stuff!
  638.  
  639. */
  640.  
  641. function polyglot_uri_cleaner($txt){
  642.  
  643.   global $polyglot_settings;
  644.  
  645.  
  646.  
  647.   $search = array(
  648.  
  649.   "/{$polyglot_settings['uri_helpers']['lang_view']}\/..\/?/i",
  650.  
  651.    "/{$polyglot_settings['uri_helpers']['lang_pref']}\/..\/?/i",
  652.  
  653.    "/(\?|&)lang_view=../i",
  654.  
  655.    "/(\?|&)lang_pref=../i",
  656.  
  657.    "/^(.*index\.php)\/$/i"
  658.  
  659.    );
  660.  
  661.   
  662.  
  663.   $replace = array('','','','','$1');
  664.  
  665.  
  666.  
  667.   if(!$polyglot_settings['use_helpers_in_uri']){
  668.  
  669.     $search[] = "/\/(".implode("|",$polyglot_settings['knownlangs']).")\/?/i";
  670.  
  671.     $replace[] = '';
  672.  
  673.     }
  674.  
  675.  
  676.  
  677.   $txt = preg_replace ( $search, $replace, $txt);
  678.  
  679.  
  680.  
  681.   return $txt;
  682.  
  683. }
  684.  
  685.  
  686.  
  687.  
  688.  
  689. //----------------------------------------------------------------------------
  690.  
  691.  
  692.  
  693.  
  694.  
  695. function polyglot_knownlangs(){
  696.  
  697. global $polyglot_settings;
  698.  
  699.   return $polyglot_settings['knownlangs'];
  700.  
  701. }
  702.  
  703.  
  704.  
  705. function polyglot_translations(){
  706.  
  707.   global $polyglot_settings;
  708.  
  709.   return $polyglot_settings['trans'];
  710.  
  711. }
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719. //---------------------------------------------------------------time functions ------------------------
  720.  
  721.  
  722.  
  723. function polyglot_date($d = '', $time = ''){
  724.  
  725.   global $polyglot_settings;
  726.  
  727.  
  728.  
  729.   if($d == '' && isset($polyglot_settings['date_format'][$polyglot_settings['lang_pref']])){
  730.  
  731.     $d = $polyglot_settings['date_format'][$polyglot_settings['lang_pref']];
  732.  
  733.   }
  734.  
  735.  
  736.  
  737.     if(strpos($time, '-')){//trick to find you if we've got "mysql time" or unix timestamp
  738.  
  739.       $time = mysql2date($d, $time);
  740.  
  741.       }
  742.  
  743.     else{
  744.  
  745.       $time = date($d,$time);
  746.  
  747.     }
  748.  
  749.  
  750.  
  751.   return $time;
  752.  
  753. }
  754.  
  755.  
  756.  
  757. function polyglot_time($d = '', $time = ''){
  758.  
  759.   global $polyglot_settings;
  760.  
  761.  
  762.  
  763.   if($d == '' && isset($polyglot_settings['time_format'][$polyglot_settings['lang_pref']])){
  764.  
  765.     $d = $polyglot_settings['time_format'][$polyglot_settings['lang_pref']];
  766.  
  767.   }
  768.  
  769.  
  770.  
  771.     if(strpos($time, '-')){//trick to find you if we've got "mysql time" or unix timestamp
  772.  
  773.       $time = mysql2date($d, $time);
  774.  
  775.       }
  776.  
  777.     else{
  778.  
  779.       $time = date($d,$time);
  780.  
  781.     }
  782.  
  783.  
  784.  
  785.   return $time;
  786.  
  787. }
  788.  
  789.  
  790.  
  791. function polyglot_comment_time($time) {
  792.  
  793.   global $comment,$polyglot_settings;
  794.  
  795.  
  796.  
  797.   if( isset($polyglot_settings['time_format'][$polyglot_settings['lang_pref']]) ){
  798.  
  799.     $d = $polyglot_settings['time_format'][$polyglot_settings['lang_pref']];
  800.  
  801.     $comment_date =  $comment->comment_date;
  802.  
  803.     $time = mysql2date($d, $comment_date);
  804.  
  805.     }
  806.  
  807.   return $time;
  808.  
  809. }
  810.  
  811.  
  812.  
  813.  
  814.  
  815. function polyglot_the_time($time,$d = ''){
  816.  
  817.   global $post,$polyglot_settings;
  818.  
  819.  
  820.  
  821.   if( isset($polyglot_settings['time_format'][$polyglot_settings['lang_pref']]) && $d==''){
  822.  
  823.     $d = $polyglot_settings['time_format'][$polyglot_settings['lang_pref']];
  824.  
  825.     $time = $post->post_date;
  826.  
  827.     $time = mysql2date($d, $time);
  828.  
  829.   }
  830.  
  831.   return $time;
  832.  
  833. }
  834.  
  835.  
  836.  
  837.  
  838.  
  839. function polyglot_comment_date($time) {
  840.  
  841.   global $comment,$polyglot_settings;
  842.  
  843.  
  844.  
  845.   if( isset($polyglot_settings['date_format'][$polyglot_settings['lang_pref']]) ){
  846.  
  847.     $d = $polyglot_settings['date_format'][$polyglot_settings['lang_pref']];
  848.  
  849.     $comment_date =  $comment->comment_date;
  850.  
  851.     $time = mysql2date($d, $comment_date);
  852.  
  853.     }
  854.  
  855.   return $time;
  856.  
  857. }
  858.  
  859.  
  860.  
  861.  
  862.  
  863. function polyglot_the_date($the_date, $d = '', $before = '', $after = ''){
  864.  
  865.   global $post,$polyglot_settings;
  866.  
  867.  
  868.  
  869.   if( isset($polyglot_settings['date_format'][$polyglot_settings['lang_pref']]) && $d=='' && $the_date!='' ){
  870.  
  871.     $d = $polyglot_settings['date_format'][$polyglot_settings['lang_pref']];
  872.  
  873.     $the_date = $post->post_date;
  874.  
  875.     $the_date = $before.mysql2date($d, $the_date).$after;
  876.  
  877.   }
  878.  
  879.   return $the_date;
  880.  
  881. }
  882.  
  883.  
  884.  
  885.  
  886.  
  887. //----------------------------------------------
  888.  
  889. function polyglot_get_lang(){
  890.  
  891.   global $polyglot_settings;
  892.  
  893.  
  894.  
  895.   return $polyglot_settings['lang_pref'];
  896.  
  897. }
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905. function get_trans($lang){
  906.  
  907.   global $polyglot_settings;
  908.  
  909.  
  910.  
  911.   if(IsSet($polyglot_settings['trans'][$lang]))
  912.  
  913.     return $polyglot_settings['trans'][$lang];
  914.  
  915.   else
  916.  
  917.     return $lang;
  918.  
  919. }
  920.  
  921.  
  922.  
  923. function polyglot_wp_head(){
  924.  
  925.   global $polyglot_settings;
  926.  
  927.   if($polyglot_settings['print_meta']){
  928.  
  929.     echo "<meta http-equiv=\"Content-Language\" content=\"{$polyglot_settings['lang_pref']}\" />";
  930.  
  931.   }
  932.  
  933. }
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941. function polyglot_filter_htmlentities($content, $category = null){
  942.  
  943.  
  944.  
  945.   $content = preg_replace("/&lt;(\/){0,1}lang_(..)&gt;/i", "<$1lang_$2>", $content);
  946.  
  947.    
  948.  
  949.     return polyglot_filter($content);
  950.  
  951.    
  952.  
  953.    
  954.  
  955. }
  956.  
  957.  
  958.  
  959.  
  960.  
  961. /**
  962.  
  963. Very simple test if the $lang version is present in the text.
  964.  
  965. */
  966.  
  967. function polyglot_lang_exists($lang, $content){
  968.  
  969.     return (   !(strpos($content, "<lang_$lang>") === false) || !(strpos($content, "[lang_$lang]") === false)   );
  970.  
  971. }
  972.  
  973.  
  974.  
  975. function polyglot_list_langs($flags=false){
  976.  
  977.   global $polyglot_settings,$wp_query;
  978.  
  979.         $clean_uri = polyglot_uri_cleaner($_SERVER['REQUEST_URI']);
  980.  
  981.        
  982.  
  983.         if(!$polyglot_settings['use_helpers_in_uri']){
  984.  
  985.           $uri_helper = '';
  986.  
  987.         }
  988.  
  989.         else {
  990.  
  991.           $uri_helper = "{$polyglot_settings['uri_helpers']['lang_pref']}/";
  992.  
  993.         }
  994.  
  995.        
  996.  
  997.        
  998.  
  999.           foreach($polyglot_settings['knownlangs'] as  $value){
  1000.  
  1001.            
  1002.  
  1003.             if ( $value==$polyglot_settings['lang_pref'] ) {
  1004.  
  1005.               $highlight = "language_item current_language_item";
  1006.  
  1007.             } else {
  1008.  
  1009.               $highlight = "language_item";
  1010.  
  1011.             }
  1012.  
  1013.             echo "<li class=\"$highlight\"><a href=\"";
  1014.  
  1015.            
  1016.  
  1017.             if(  $polyglot_settings['lang_rewrite'] ){
  1018.  
  1019.              
  1020.  
  1021.               if(strpos(get_settings('permalink_structure'),'index.php') === FALSE){
  1022.  
  1023.                   echo polyglot_trailingslashit($clean_uri)."{$uri_helper}{$value}/";
  1024.  
  1025.                 }
  1026.  
  1027.               else {
  1028.  
  1029.                 $qm_pos = strpos($clean_uri,'?');
  1030.  
  1031.                 if(strpos($clean_uri,'index.php') === FALSE){
  1032.  
  1033.                     if( ($qm_pos) === FALSE){
  1034.  
  1035.                         echo polyglot_trailingslashit($clean_uri)."index.php/{$uri_helper}{$value}/";
  1036.  
  1037.                       }
  1038.  
  1039.                     else {
  1040.  
  1041.                         echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos))."index.php/{$uri_helper}{$value}/".substr($clean_uri,$qm_pos);
  1042.  
  1043.                       }
  1044.  
  1045.                   }
  1046.  
  1047.                 else {
  1048.  
  1049.                
  1050.  
  1051.                     if($qm_pos === FALSE){
  1052.  
  1053.                           echo polyglot_trailingslashit($clean_uri)."{$uri_helper}{$value}/";
  1054.  
  1055.                         }
  1056.  
  1057.                       else {
  1058.  
  1059.                           echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos))."{$uri_helper}{$value}/".substr($clean_uri,strpos($clean_uri,'?'));
  1060.  
  1061.                         }
  1062.  
  1063.                   }
  1064.  
  1065.                
  1066.  
  1067.                
  1068.  
  1069.                
  1070.  
  1071.                 }
  1072.  
  1073.             }
  1074.  
  1075.             else {
  1076.  
  1077.            
  1078.  
  1079.               //if('' != get_settings('permalink_structure')){
  1080.  
  1081.                 echo $clean_uri.((strpos($clean_uri,'?') === FALSE) ? '?' : '&amp;' )."lang_pref={$value}";
  1082.  
  1083.               //}
  1084.  
  1085.            
  1086.  
  1087.             }
  1088.  
  1089.             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></li>";
  1090.  
  1091.           }
  1092.  
  1093. }
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099. /*
  1100.  
  1101. Original function in WP doesn't work properly:(
  1102.  
  1103. */
  1104.  
  1105. function polyglot_trailingslashit($uri){
  1106.  
  1107.   if($uri{strlen($uri)-1} != '/')
  1108.  
  1109.     return $uri.'/';
  1110.  
  1111.   else
  1112.  
  1113.     return $uri;
  1114.  
  1115. }
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121. /**
  1122.  
  1123. The core function of the plugin. Selects only one language version from the passed text.
  1124.  
  1125. */
  1126.  
  1127. function polyglot_filter($text, $lang = '') {
  1128.  
  1129.   global $polyglot_settings;
  1130.  
  1131.  
  1132.  
  1133.   if($lang == ''){$lang = $polyglot_settings['lang_pref'];}
  1134.  
  1135.  
  1136.  
  1137.   $text = preg_replace("/\[(\/){0,1}lang_(..)\]/i", "<$1lang_$2>", $text);//fix for [lang_xx] 
  1138.  
  1139.   $text = preg_replace ('/<p>(<(\/){0,1}lang_..>)<\/p>/i',"$1",$text);//fix for <p><lang_xx></p>
  1140.  
  1141.  
  1142.  
  1143.   $text = preg_replace ('/(<lang_..>)/i',"</lang_all>\\1",$text);//adds lang_all to all other stuff that is not enclosed in lang_xx tags
  1144.  
  1145.   $text = preg_replace ('/(<\/lang_..>)/i',"\\1<lang_all>",$text);
  1146.  
  1147.   $text = '<lang_all>'.$text.'</lang_all>';
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.   if (preg_match_all ( '/<lang_(..)>/', $text , $match, PREG_PATTERN_ORDER)) {
  1158.  
  1159.         if (isset($polyglot_settings['lang_pref']) && polyglot_lang_exists($polyglot_settings['lang_pref'],$text)){
  1160.  
  1161.         //lets try to get proper language version
  1162.  
  1163.             $text=str_replace("<lang_all>","<lang_{$polyglot_settings['lang_pref']}>",$text);//we don't want just lang_pref parts but also lang_all parts
  1164.  
  1165.             $text=str_replace("</lang_all>","</lang_{$polyglot_settings['lang_pref']}>",$text);
  1166.  
  1167.      
  1168.  
  1169.             $find = "/(?s)<lang_{$polyglot_settings['lang_pref']}>(.*?)<\/lang_{$polyglot_settings['lang_pref']}>/";
  1170.  
  1171.             preg_match_all ( $find, $text , $match, PREG_PATTERN_ORDER);
  1172.  
  1173.             $text = implode('',$match[1]);
  1174.  
  1175.            
  1176.  
  1177.         }
  1178.  
  1179.         elseif(polyglot_lang_exists($polyglot_settings['default_lang'],$text)){
  1180.  
  1181.         //or at least the default language
  1182.  
  1183.       $text=str_replace("<lang_all>","<lang_{$polyglot_settings['default_lang']}>",$text);
  1184.  
  1185.             $text=str_replace("</lang_all>","</lang_{$polyglot_settings['default_lang']}>",$text);
  1186.  
  1187.             $find = "/(?s)<lang_{$polyglot_settings['default_lang']}>(.*?)<\/lang_{$polyglot_settings['default_lang']}>/";
  1188.  
  1189.             preg_match_all ( $find, $text , $match, PREG_PATTERN_ORDER);
  1190.  
  1191.             $text = implode('',$match[1]);
  1192.  
  1193.         }
  1194.  
  1195.        
  1196.  
  1197.          else {
  1198.  
  1199.             //all untranslated stuff
  1200.  
  1201.             $text=str_replace("<lang_all>","",$text);
  1202.  
  1203.             $text=str_replace("</lang_all>","",$text);
  1204.  
  1205.             $find = "/(?s)<lang_(.*?)>(.*?)<\/lang_(.*?)>/";
  1206.  
  1207.             $replace = "";
  1208.  
  1209.             $text = preg_replace($find,$replace,$text);
  1210.  
  1211.         }
  1212.  
  1213.     }
  1214.  
  1215.  
  1216.  
  1217.   return str_replace(array("<lang_all>","</lang_all>"),array('',''),$text);
  1218.  
  1219. }
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225. /**
  1226.  
  1227. Handy shortcuts of polyglot_filter function for direct use in the templates
  1228.  
  1229. */
  1230.  
  1231. function p__($text){
  1232.  
  1233.   return polyglot_filter($text);
  1234.  
  1235. }
  1236.  
  1237.  
  1238.  
  1239. function p__e($text){
  1240.  
  1241.   echo polyglot_filter($text);
  1242.  
  1243. }
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249. /**
  1250.  
  1251. Does the same as polyglot_filter but shows the message that informs visitor that selected language version is not available
  1252.  
  1253. */
  1254.  
  1255. function polyglot_filter_with_message($text){
  1256.  
  1257. global $polyglot_settings;
  1258.  
  1259.   $text = trim(polyglot_filter($text));
  1260.  
  1261.   if($text == ''){
  1262.  
  1263.     $text = polyglot_filter($polyglot_settings['text_is_missing_message']);
  1264.  
  1265.   }
  1266.  
  1267.   return $text;
  1268.  
  1269. }
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275. /*function safe_link(){
  1276.  
  1277.   global $post;
  1278.  
  1279.  
  1280.  
  1281.   $permalink = get_settings('home') . '/' . get_settings('blogfilename') . '?';
  1282.  
  1283.  
  1284.  
  1285.     if ($post->post_status == 'static')
  1286.  
  1287.       $permalink .= 'page_id';
  1288.  
  1289.     else
  1290.  
  1291.       $permalink .= 'p';
  1292.  
  1293.      
  1294.  
  1295.   $permalink .= '='.$post->ID;
  1296.  
  1297.    
  1298.  
  1299.  
  1300.  
  1301.   return $permalink;
  1302.  
  1303. }*/
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309. /**
  1310.  
  1311. Prints out the list of other language versions contained in the current post.
  1312.  
  1313. */
  1314.  
  1315. function polyglot_other_langs($none='none', $before='<ul>', $after='</ul>', $pre='<li>(', $afters=')</li>'){
  1316.  
  1317.     global $polyglot_settings, $post;
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.   if(!$polyglot_settings['use_helpers_in_uri']){
  1324.  
  1325.     $uri_helper = '';
  1326.  
  1327.   }
  1328.  
  1329.   else {
  1330.  
  1331.     $uri_helper = "{$polyglot_settings['uri_helpers']['lang_view']}/";
  1332.  
  1333.   }
  1334.  
  1335.  
  1336.  
  1337.     $content = $post->post_content;//fred
  1338.  
  1339.    
  1340.  
  1341.     $before = polyglot_filter($before);
  1342.  
  1343.     $after = polyglot_filter($after);
  1344.  
  1345.     $pre = polyglot_filter($pre);
  1346.  
  1347.     $afters = polyglot_filter($afters);
  1348.  
  1349.     $other_langs = polyglot_filter($none);
  1350.  
  1351.  
  1352.  
  1353.     if (preg_match_all ( '/[<|\[]lang_(..)[>|\]]/', $content , $match, PREG_PATTERN_ORDER)) {
  1354.  
  1355.         $match = array_unique($match[1]);
  1356.  
  1357.         $other_langs = $before;
  1358.  
  1359.      
  1360.  
  1361.         foreach ($match as $lang){
  1362.  
  1363.             if ($polyglot_settings['lang_pref'] != $lang) {
  1364.  
  1365.        
  1366.  
  1367.         $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);
  1368.  
  1369.  
  1370.  
  1371.            
  1372.  
  1373.         $other_langs .= "$pre<a href='".get_permalink();
  1374.  
  1375.      
  1376.  
  1377.                 if ($polyglot_settings['lang_rewrite']) {
  1378.  
  1379.           if($polyglot_settings['i_have_manually_edited_my_htaccess_file'] || strpos(get_permalink(),'?') === false){
  1380.  
  1381.             $other_langs .= "{$uri_helper}{$lang}/";
  1382.  
  1383.             }
  1384.  
  1385.           else {
  1386.  
  1387.             $other_langs .= "&amp;lang_view=$lang'";
  1388.  
  1389.           }
  1390.  
  1391.                 } else {
  1392.  
  1393.           if(strpos(get_permalink(),'?') === false){
  1394.  
  1395.               $other_langs .= "?lang_view=$lang'";
  1396.  
  1397.           }
  1398.  
  1399.           else {
  1400.  
  1401.               $other_langs .= "&amp;lang_view=$lang'";
  1402.  
  1403.           }
  1404.  
  1405.                    
  1406.  
  1407.                 }
  1408.  
  1409.        
  1410.  
  1411.         $other_langs .= "'>{$foo}</a>$afters";
  1412.  
  1413.             }
  1414.  
  1415.         }
  1416.  
  1417.     if($other_langs != $before)//to avoid empty <ul></ul>
  1418.  
  1419.           $other_langs .= $after;
  1420.  
  1421.     else
  1422.  
  1423.       $other_langs = $none;
  1424.  
  1425.     }
  1426.  
  1427.     echo $other_langs;
  1428.  
  1429. }
  1430.  
  1431.  
  1432.  
  1433. /**
  1434.  
  1435. Prepares text for slug
  1436.  
  1437. */
  1438.  
  1439. function polyglot_sanitize_title($text){
  1440.  
  1441.   global $polyglot_settings;
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.   $text = polyglot_filter($text, $polyglot_settings['default_lang']);
  1448.  
  1449.  
  1450.  
  1451.   return $text;
  1452.  
  1453. }
  1454.  
  1455.  
  1456.  
  1457. //------------code from 'translate categories' plugin-----------
  1458.  
  1459.  
  1460.  
  1461. function polyglot_translate_callback($matches){
  1462.  
  1463.  
  1464.  
  1465. return $matches[1].__($matches[2]).$matches[3];
  1466.  
  1467.  
  1468.  
  1469. }
  1470.  
  1471. /**
  1472.  
  1473. Not very nice way how to tranlate category name:(
  1474.  
  1475. It uses standard gettex function __ and works only when we have the category name in the .mo file!
  1476.  
  1477. */
  1478.  
  1479. function polyglot_translate_the_category($text){
  1480.  
  1481.  
  1482.  
  1483.   return preg_replace_callback('/(<a[^>]*>)(.*?)(<\/a>)/i','polyglot_translate_callback',$text); 
  1484.  
  1485. }
  1486.  
  1487.  
  1488.  
  1489. //---------------------------------------------------------------------------
  1490.  
  1491.  
  1492.  
  1493. function polyglot_get_users_pref_lang(){
  1494.  
  1495.       GLOBAL $polyglot_settings;
  1496.  
  1497.       $deflang = $polyglot_settings['default_lang'];
  1498.  
  1499.      
  1500.  
  1501.       # An advanced PHP Language Detection Script
  1502.  
  1503.       # by Fibergeek (fibergeek @ codegurus.be)
  1504.  
  1505.       #
  1506.  
  1507.       # This script is a modification to a script I found via google
  1508.  
  1509.       #
  1510.  
  1511.       # 2003-12-18 - Version 1 (I added...)
  1512.  
  1513.       #   - you can now also specify the country code in the $knowlangs array
  1514.  
  1515.       #   - extraction of the country code ($country)
  1516.  
  1517.       #   - I fully documented the code
  1518.  
  1519.       #
  1520.  
  1521.       # 2004-01-07 - Version 2 (I added...)
  1522.  
  1523.       #   - you can now make $knowlangs NULL (the script will set to array to all known languages (ISO-639))
  1524.  
  1525.       #
  1526.  
  1527.       # NOTE : for those using Brion's script, I renamed $lastquality to $quality
  1528.  
  1529.       #
  1530.  
  1531.       # Found at URL    : http://mail.wikipedia.org/pipermail/wikitech-l/2002-October/001068.html
  1532.  
  1533.       # Assumed creator : Brion VIBBER (wikitech-l@wikipedia.org)
  1534.  
  1535.       # HTTP reference  : RFC 2616 - ftp://ftp.isi.edu/in-notes/rfc2616.txt
  1536.  
  1537.      
  1538.  
  1539.       # ==================================================================================================
  1540.  
  1541.       # TODO
  1542.  
  1543.       #   You need to add the 2 lines to your source code, and change the content of them of course ;-)
  1544.  
  1545.       # ==================================================================================================
  1546.  
  1547.       #$polyglot_settings['knownlangs'] = NULL;                                // default to all known languages (ISO-639)
  1548.  
  1549.       #$deflang    = NULL;                                // there is no default language
  1550.  
  1551.       #
  1552.  
  1553.       #$polyglot_settings['knownlangs'] = array('en-us', 'en-uk', 'en', 'nl'); // We know : English (US & UK) and Dutch
  1554.  
  1555.       #$deflang    = 'en-uk';                             // In case of an error, we default to English UK
  1556.  
  1557.      
  1558.  
  1559.       # ==================================================================================================
  1560.  
  1561.       # INFORMATION
  1562.  
  1563.       # The following variables are returned by this program
  1564.  
  1565.       #   $lclist  : the full list with the languages accepted by the client's browser
  1566.  
  1567.       #   $lctag   : the tag we are supporting (includes the country code if any)
  1568.  
  1569.       #   $quality : the quality
  1570.  
  1571.       #   $lang    : the language code
  1572.  
  1573.       #   $country : the country code (if any)
  1574.  
  1575.       #
  1576.  
  1577.       # The following variables are used by this program (and may be overwritten if you use them also!)
  1578.  
  1579.       #   $langtag
  1580.  
  1581.       #   $qvalue
  1582.  
  1583.       #   $eachbit
  1584.  
  1585.       #   $tmppos
  1586.  
  1587.       #   $tmplclist
  1588.  
  1589.       #   $tmplctag
  1590.  
  1591.       #   $tmptagarray
  1592.  
  1593.       # ==================================================================================================
  1594.  
  1595.      
  1596.  
  1597.       # ==================================================================================================
  1598.  
  1599.       # THE SCRIPT
  1600.  
  1601.       # ==================================================================================================
  1602.  
  1603.      
  1604.  
  1605.       # Check that $knowlangs is an array!
  1606.  
  1607.       # NOTE : the list is taken from this URL : http://www.w3.org/WAI/ER/IG/ert/iso639.htm
  1608.  
  1609.       if(!is_array($polyglot_settings['knownlangs']))
  1610.  
  1611.       {
  1612.  
  1613.         if(is_string($polyglot_settings['knownlangs']) || is_object($polyglot_settings['knownlangs']) || $polyglot_settings['knownlangs'] != NULL)
  1614.  
  1615.           die("Fibergeek's PHP Language Detection Script : You need define \$polyglot_settings['knownlangs'] as an array or as NULL!<br>\n");
  1616.  
  1617.         $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');
  1618.  
  1619.       }
  1620.  
  1621.      
  1622.  
  1623.       # Initalisation of the default variables
  1624.  
  1625.       if(isset($HTTP_SERVER_VARS))
  1626.  
  1627.         $lclist = trim($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']); # PHP running from a server
  1628.  
  1629.       else
  1630.  
  1631.         $lclist = trim($_SERVER['HTTP_ACCEPT_LANGUAGE']);          # PHP 5.0 when the old server variables disabled
  1632.  
  1633.       $lctag   = $deflang;
  1634.  
  1635.       $tmppos  = strpos($lctag, '-');
  1636.  
  1637.       $quality = 0.0;
  1638.  
  1639.       if($tmppos == FALSE or $tmppos == NULL)
  1640.  
  1641.       {
  1642.  
  1643.         $lang    = $deflang;
  1644.  
  1645.         if($deflang == NULL)
  1646.  
  1647.           $country = NULL;
  1648.  
  1649.         else
  1650.  
  1651.           $country = '';
  1652.  
  1653.       }
  1654.  
  1655.       else
  1656.  
  1657.       {
  1658.  
  1659.         $lang    = substr($lctag, 0, $tmppos);
  1660.  
  1661.         $country = substr($lctag, $tmppos + 1);
  1662.  
  1663.         echo "lang sub = $lang";
  1664.  
  1665.       }
  1666.  
  1667.      
  1668.  
  1669.       #
  1670.  
  1671.       $langtag = '((?:[a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*)';
  1672.  
  1673.       $qvalue  ='(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3}))';
  1674.  
  1675.       $eachbit = '^' . $langtag . '(?:;q=' . $qvalue . ')?(?:,\s*)?(.*)$';
  1676.  
  1677.      
  1678.  
  1679.       #
  1680.  
  1681.       $tmplclist = $lclist;
  1682.  
  1683.      
  1684.  
  1685.       # The loop
  1686.  
  1687.       while(strlen($tmplclist))
  1688.  
  1689.       {
  1690.  
  1691.         if(preg_match("/$eachbit/", $tmplclist, $tmptagarray)) # requires 3.0.9
  1692.  
  1693.         {
  1694.  
  1695.           # Extract data from the tag list
  1696.  
  1697.           $tmplctag = $tmptagarray[1];
  1698.  
  1699.           $tmpquality = $tmptagarray[2];
  1700.  
  1701.           if(strlen($tmpquality) == 0)
  1702.  
  1703.             $tmpquality = 1;
  1704.  
  1705.           $tmplclist = $tmptagarray[3];
  1706.  
  1707.      
  1708.  
  1709.           # Find the tag in our $polyglot_settings['knownlangs'] array (this search includes the country code if set)
  1710.  
  1711.           if(in_array($tmplctag, $polyglot_settings['knownlangs']) and $tmpquality > $quality)
  1712.  
  1713.           {
  1714.  
  1715.             # Extract the language & quality
  1716.  
  1717.             $lctag   = $tmplctag;
  1718.  
  1719.             $lang    = $tmplctag;
  1720.  
  1721.             $country = '';