- Statut : non résolu
- Ce sujet contient 295 réponses, 72 participants et a été mis à jour pour la dernière fois par vivi12, le il y a 9 années et 10 mois.
-
AuteurMessages
-
15 janvier 2010 à 16 h 33 min #580193
où trouvez vous ce plugin polyglot ?
merci
23 novembre 2010 à 8 h 07 min #580194Désolé de publier à deux endroits le même message, mais je crois vraiment que peut aider beaucoup…
http://www.wordpress-fr.net/support/viewtopic.php?pid=230212#p230212Le Plug-In Codestyling Localization fonctionne comme un charme et génère le fichier MO après avoir effectué sa traduction par l’interface d’admin !
C’est ce que WP devrait intégrer pour que la traduction/localisation soit conviviale.
AUCUN code à modifier. Nada.
Après l’installation, il suffit de …
* Prendre le temps de regarder la page Outils et de sélectionner le bon onglet, par exemple pour traduire une Extension ou un Theme ;
* Pour une Extension ou un Theme particulier, tu click le bouton Rescanner pour être certain que le Plug-In a intégré tous les bouts de texte pouvant être traduits ;
* Puis tu click sur le bouton Modifier pour ouvrir le système de traduction
( faites alors les traductions ou adaptations désirées ) ;* et, finalement, assurez-vous de clicker sur le bouton générer le fichier .mo.
Voilà ! ✅
Je suis nouveau à WP. Je gère normalement plusieurs sites complexes en Drupal.
Donc je suis heureux d’avoir trouvé ce Plug-In qui rend simple les traductions (je n’avais pas du tout envie de tout traduire dans le .po pour ensuite trouver le truc pour le convertir en .mo alors que je suis sur un Mac).
C’est gratuit. Et non je ne travaille pas pour le développeur de ce truc 😋
Merci.
23 novembre 2010 à 9 h 02 min #580195Donc je suis heureux d’avoir trouvé ce Plug-In qui rend simple les traductions (je n’avais pas du tout envie de tout traduire dans le .po pour ensuite trouver le truc pour le convertir en .mo alors que je suis sur un Mac).
quel rapport ? POedit est indifférent a mac ou pc ! http://www.poedit.net/download.php
mce plugin est bien mais il a ses limites et il faut faire attention comme dit dans ma reponse à l’autre post.
mais ce post n’est toujours pas a la bonne place…. tu aurais du ouvrir un autre sujet….
6 mai 2011 à 10 h 49 min #580196Bonjour,
j’ai un probleme avec polyglot, dans mon text si je mets [lang_fr]
toto
[/lang_fr] il ne m’affiche plus rien
quelqu’un a t-il une solution ??
merci17 octobre 2011 à 21 h 03 min #580197A mon tour de demander de l’aide:
Les 3 langues s’affichent, mais pas les drapeaux. Comment les mettre les uns à côté des autres au lieu de liste à points?
Aussi: comment changer les titres des pages?J’ai donc WP 3.2.1
URL: cloverbox.net/wordpressJ’ai installé polyglot, fait les modifs expliquées en début de post.
Maintenant, les modifs faites:
1) J’ai édité le fichier polyglot.php pour avoir 3 langues etc.
<?php
/*
Plugin Name: Polyglot
Plugin URI: http://fredfred.net/skriker/index.php/polyglot
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 Language Picker. For more information, comments or questions visit the Polyglot’s homepage.
Version: 2.5
Author: Martin Chlupac
Author URI: http://fredfred.net/skriker/
Update: http://fredfred.net/skriker/plugin-update.php?p=198This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
*/// Default language version – used when proper language version of the text is not present or the visitor’s prefered language is unknown
$polyglot_settings = ‘fr’;//You can define your own translations of language shortcuts
$polyglot_settings = ‘EN’;
$polyglot_settings = ‘NL’;
$polyglot_settings = ‘FR’;//Which language versions you offer for the whole web – use the proper ISO codes!
$polyglot_settings = array(‘fr’,’en’,’nl’);//set to ‘true’ if there should be shown flags instead of names of languages
$polyglot_settings= true ;//list of ISO codes and their image represantations (flags).
//all flags can be found in ‘polyglot_flags’ directory$polyglot_settings = ‘gb.png’;
$polyglot_settings = ‘de.png’;
$polyglot_settings = ‘nl.png’;
$polyglot_settings = ‘fr.png’;$polyglot_settings = ‘cz.png’;
$polyglot_settings = ‘it.png’;
$polyglot_settings = ‘se.png’;//time format for each language
//if not set – default WP time format is used
$polyglot_settings = ‘G:i’;
$polyglot_settings = ‘G:i’;
$polyglot_settings = ‘G:i’;
$polyglot_settings = ‘G:i’;
$polyglot_settings = ‘G.i’;$polyglot_settings = ‘d-m-Y’;
$polyglot_settings = ‘d-m-Y’;
$polyglot_settings = ‘d-m-Y’;
$polyglot_settings = ‘d-m-Y’;
$polyglot_settings = ‘d-m-Y’;/*path to the plugin directory
don’t forget trailing slash if you are changing this value
*/
$polyglot_settings = get_bloginfo(‘wpurl’).’/wp-content/plugins/polyglot_flags/’;//if you use WP older than 1.5 you must use this:
//$polyglot_settings = get_bloginfo(‘url’).’/wp-content/plugins/’;//default text that is shown when the proper language version of the post is missing and even the default language version is not there
// use $polyglot_settings = »; if you want to turn it off.
$polyglot_settings = ‘[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]’;//
advanced
//Should be printed where xx stands for ISO code of current language?
$polyglot_settings = false;// Name of the cookie – default:’wordpress_lang_pref’.$cookiehash
$polyglot_settings = ‘wordpress_lang_pref’.COOKIEHASH;/*
Should Polyglot attempt to dynamically change the WP locale
setting based on user’s prefered language? Note, for this to work
.mo files must be renamed to match the name specified in $polyglot_settings array
but you don’t have to rename anything in most cases as there is already list of current WP versions present.
*/
$polyglot_settings = TRUE;/*
To use permalinks for other languages set this to « true ».
You probably don’t have to do anything else if you have « index.php » in your permalink structure.
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.
For more info check: http://www.google.com/search?hl=en&q=mod_rewrite
*/
$polyglot_settings = true;/**
This should stay turned off unless you had problems with rules in your .htaccess file and you have edited them manually.
*/
$polyglot_settings = false; //change this only if you know what you are doing!/**
There are some helpers added (/lang/, /lang-pref/) by default to the url to help Polyglot distinguish between language code and short post slug.
These can be turned off. But don’t turn them off unless you have a good reason to do that.
*/
$polyglot_settings = true;/**
If you want to use these helpers but you want to change them – do that here:
*/
$polyglot_settings = ‘lang’;
$polyglot_settings = ‘lang-pref’;/*
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.
Add your language or change it as you need.
*/
$polyglot_settings = ‘ar’;
$polyglot_settings = ‘bg_BG’;
$polyglot_settings = ‘cs_CZ’;
$polyglot_settings = ‘cy’;
$polyglot_settings = ‘da_DK’;
$polyglot_settings = ‘de_DE’;
$polyglot_settings = ‘el’;
$polyglot_settings = ‘eo’;
$polyglot_settings = ‘es_ES’;
$polyglot_settings = ‘fa’;
$polyglot_settings = ‘fi_FI’;
$polyglot_settings = ‘fr_FR’;//fr_BE
$polyglot_settings = ‘hu_HU’;
$polyglot_settings = ‘it_IT’;
$polyglot_settings = ‘ja_JP’;
$polyglot_settings = ‘ko’;
$polyglot_settings = ‘nb_NO’;//nn_NO
$polyglot_settings = ‘pl_PL’;
$polyglot_settings = ‘pt_BR’;
$polyglot_settings = ‘ru_RU’;
$polyglot_settings = ‘sk’;
$polyglot_settings = ‘sq’;
$polyglot_settings = ‘sr_CS’;
$polyglot_settings = ‘sv_SE’;
$polyglot_settings = ‘zh_CN’;//============================================STOP EDITING HERE! (unless you know what you are doing)=====================================
$polyglot_settings = false;
//=====================================HOOKS=====================================
add_filter(‘the_time’,’polyglot_the_time’,10,2);
add_filter(‘get_comment_time’,’polyglot_comment_time’);
add_filter(‘the_date’,’polyglot_the_date’,10,4);
add_filter(‘get_comment_date’,’polyglot_comment_date’);
add_filter(‘the_category_rss’,’__’,1);
add_filter(‘the_content’, ‘polyglot_filter_with_message’,1);
add_filter(‘the_title’, ‘polyglot_filter’,1);
add_filter(‘wp_list_pages’, ‘polyglot_filter_htmlentities’,1);
add_filter(‘single_post_title’, ‘polyglot_filter’,1);
add_filter(‘single_cat_title’, ‘polyglot_filter’,1);
add_filter(‘wp_title’, ‘polyglot_filter’,1);
add_filter(‘the_content_rss’, ‘polyglot_filter’,1);
add_filter(‘the_excerpt_rss’, ‘polyglot_filter’,1);
add_filter(‘the_title_rss’, ‘polyglot_filter’,1);
add_filter(‘comment_text_rss’, ‘polyglot_filter’,1);
add_filter(‘bloginfo_rss’, ‘polyglot_filter’,1);
add_filter(‘the_excerpt’, ‘polyglot_filter’,1);
add_filter(‘comment_text’, ‘polyglot_filter’,1);//tags
add_filter(‘get_the_tags’, ‘polyglot_get_the_tags’,1);
add_filter(‘get_tags’, ‘polyglot_get_the_tags’,1);
add_filter(‘single_tag_title’, ‘polyglot_filter’,1);//bookmarks
add_filter(‘get_bookmarks’, ‘polyglot_get_bookmarks’,1);
add_filter(‘link_category’, ‘polyglot_filter’,1);add_filter(‘list_cats’,’__’,1);//we register standard gettext function
add_filter(‘the_category’,’polyglot_translate_the_category’);//locale
add_action(‘locale’,’polyglot_get_locale’,1);add_action(‘wp_head’,’polyglot_wp_head’);
add_action(‘plugins_loaded’,’polyglot_init’,1);//fired even before init
add_action(‘init’,’polyglot_init’,1);add_filter(‘bloginfo’, ‘polyglot_filter’,1,1);
/*
You probably have to incerase the length of ‘cat_name’ column in MySql table ‘categories’ in your DB to be able to use this.
‘cat_name’ is by default just 55 characters long.
*/
add_filter(‘the_category’, ‘polyglot_filter_htmlentities’,1);
add_filter(‘list_cats’, ‘polyglot_filter_htmlentities’,2);add_filter(‘sanitize_title’, ‘polyglot_sanitize_title’, 1);
add_filter(‘polyglot_filter’,’polyglot_filter’);
//here we try to guess which language user wants
//========================================$polyglot_settings = 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
//
/*
This function processes the requested URI and filters it before the rest of the WP gets it
*/
function polyglot_init() {
global $polyglot_settings,$locale;if($polyglot_settings)
{
return;
}$content = $_SERVER;
$languages = implode(‘|’,$polyglot_settings);
if(!$polyglot_settings){
$find = array(
« /^(.*)/($languages)/?(.*)$/i »
);
}
else {
$find = array(
« /^(.*)/{$polyglot_settings}/($languages)/?(.*)$/i »,
« /^(.*)/{$polyglot_settings}/($languages)/?(.*)$/i »);
}$replace = array( », »);
if (preg_match($find[0], $content, $matches)) {
$content = $matches[1] . « / » . $matches[3];
$_GET = $matches[2];
}if ($polyglot_settings && preg_match($find[1], $content, $matches)) {
$content = $matches[1] . « / » . $matches[3];
$_GET = $matches[2];
}$_SERVER= $content;
$_SERVER = preg_replace($find,$replace,$_SERVER);
$_SERVER = preg_replace($find,$replace,$_SERVER);//let’s check if user has chosen the preferred language
if ( isset($_GET) ) {
$_GET = strtolower($_GET);if( in_array($_GET,$polyglot_settings) ){
setcookie($polyglot_settings, $_GET, time() + 30000000, COOKIEPATH,COOKIE_DOMAIN);
$polyglot_settings=$_GET[« lang_pref »];
}}
//or he wants to see the post in the certain language
elseif( isset($_GET)){
$polyglot_settings = strtolower($_GET);
}
//or at least has the cookie with some value
elseif( isset($_COOKIE[$polyglot_settings]) ) {
$polyglot_settings = strtolower(trim($_COOKIE[$polyglot_settings]));
}/**
This part should be removed but for some reason it’s needed on some installations:(
*/
/*if($polyglot_settings && !$polyglot_settings){
if(preg_match(‘//lang/(..)/i’,$_SERVER,$matches)){
$polyglot_settings=$matches[1];
}if(preg_match(‘//lang-pref/(..)/i’,$_SERVER,$matches)){
$polyglot_settings=$matches[1];
setcookie($polyglot_settings, $polyglot_settings, time() + 30000000, COOKIEPATH);
}
}*//*
If the Polyglot is supposed to change the global language settings then… let’s do that!
*/
if ($polyglot_settings){$polyglot_foo = ( isset($polyglot_settings[$polyglot_settings]) ) ? $polyglot_settings[$polyglot_settings] : $polyglot_settings;
if (!defined(‘WPLANG’)){//just try
define(‘WPLANG’, $polyglot_foo);
}if($locale != $polyglot_foo){
$locale = $polyglot_foo;//echo $polyglot_settings;
load_default_textdomain();
}
}$polyglot_settings = true;
return;
}/**
Useful function when you want to generate new links with lang-pref settings. You must get rid of the old stuff!
*/
function polyglot_uri_cleaner($txt){
global $polyglot_settings;$search = array(
« /{$polyglot_settings}/../?/i »,
« /{$polyglot_settings}/../?/i »,
« /(?|&)lang_view=../i »,
« /(?|&)lang_pref=../i »,
« /^(.*index.php)/$/i »
);$replace = array( », », », »,’$1′);
if(!$polyglot_settings){
$search[] = « //(« .implode(« | »,$polyglot_settings). »)/?/i »;
$replace[] = »;
}$txt = preg_replace ( $search, $replace, $txt);
return $txt;
}//
function polyglot_knownlangs(){
global $polyglot_settings;
return $polyglot_settings;
}function polyglot_translations(){
global $polyglot_settings;
return $polyglot_settings;
}//
time functions
function polyglot_date($d = », $time = »){
global $polyglot_settings;if($d == » && isset($polyglot_settings[$polyglot_settings])){
$d = $polyglot_settings[$polyglot_settings];
}if(strpos($time, ‘-‘)){//trick to find you if we’ve got « mysql time » or unix timestamp
$time = mysql2date($d, $time);
}
else{
$time = date($d,$time);
}return $time;
}function polyglot_time($d = », $time = »){
global $polyglot_settings;if($d == » && isset($polyglot_settings[$polyglot_settings])){
$d = $polyglot_settings[$polyglot_settings];
}if(strpos($time, ‘-‘)){//trick to find you if we’ve got « mysql time » or unix timestamp
$time = mysql2date($d, $time);
}
else{
$time = date($d,$time);
}return $time;
}function polyglot_comment_time($time) {
global $comment,$polyglot_settings;if( isset($polyglot_settings[$polyglot_settings]) ){
$d = $polyglot_settings[$polyglot_settings];
$comment_date = $comment->comment_date;
$time = mysql2date($d, $comment_date);
}
return $time;
}function polyglot_the_time($time,$d = »){
global $post,$polyglot_settings;if( isset($polyglot_settings[$polyglot_settings]) && $d== »){
$d = $polyglot_settings[$polyglot_settings];
$time = $post->post_date;
$time = mysql2date($d, $time);
}
return $time;
}function polyglot_comment_date($time) {
global $comment,$polyglot_settings;if( isset($polyglot_settings[$polyglot_settings]) ){
$d = $polyglot_settings[$polyglot_settings];
$comment_date = $comment->comment_date;
$time = mysql2date($d, $comment_date);
}
return $time;
}function polyglot_the_date($the_date, $d = », $before = », $after = »){
global $post,$polyglot_settings;if( isset($polyglot_settings[$polyglot_settings]) && $d== » && $the_date!= » ){
$d = $polyglot_settings[$polyglot_settings];
$the_date = $post->post_date;
$the_date = $before.mysql2date($d, $the_date).$after;
}
return $the_date;
}//
function polyglot_get_lang(){
global $polyglot_settings;return $polyglot_settings;
}function get_trans($lang){
global $polyglot_settings;if(IsSet($polyglot_settings[$lang]))
return $polyglot_settings[$lang];
else
return $lang;
}function polyglot_wp_head(){
global $polyglot_settings;
if($polyglot_settings){
echo « »;
}
}function polyglot_filter_htmlentities($content, $category = null){
$content = preg_replace(« /<(/){0,1}lang_(..)>/i », « », $content);
return polyglot_filter($content);
}
/**
Very simple test if the $lang version is present in the text.
*/
function polyglot_lang_exists($lang, $content){
return ( !(strpos($content, « ») === false) || !(strpos($content, « [lang_$lang] ») === false) );
}function polyglot_list_langs($flags=false){
global $polyglot_settings,$wp_query;
$clean_uri = polyglot_uri_cleaner($_SERVER);if(!$polyglot_settings){
$uri_helper = »;
}
else {
$uri_helper = « {$polyglot_settings}/ »;
}foreach($polyglot_settings as $value){
if ( $value==$polyglot_settings ) {
$highlight = « language_item current_language_item »;
} else {
$highlight = « language_item »;
}
echo «- <a href="";
if( $polyglot_settings ){
if(strpos(get_settings(‘permalink_structure’),’index.php’) === FALSE){
echo polyglot_trailingslashit($clean_uri). »{$uri_helper}{$value}/ »;
}
else {
$qm_pos = strpos($clean_uri,’?’);
if(strpos($clean_uri,’index.php’) === FALSE){
if( ($qm_pos) === FALSE){
echo polyglot_trailingslashit($clean_uri). »index.php/{$uri_helper}{$value}/ »;
}
else {
echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos)). »index.php/{$uri_helper}{$value}/ ».substr($clean_uri,$qm_pos);
}
}
else {if($qm_pos === FALSE){
echo polyglot_trailingslashit($clean_uri). »{$uri_helper}{$value}/ »;
}
else {
echo polyglot_trailingslashit(substr($clean_uri,0,$qm_pos)). »{$uri_helper}{$value}/ ».substr($clean_uri,strpos($clean_uri,’?’));
}
}}
}
else {//if( » != get_settings(‘permalink_structure’)){
echo $clean_uri.((strpos($clean_uri,’?’) === FALSE) ? ‘?’ : ‘&’ ). »lang_pref={$value} »;
//}}
echo « »> ». (($flags) ? « » : get_trans($value)) . »« ;
}
}/*
Original function in WP doesn’t work properly:(
*/
function polyglot_trailingslashit($uri){
if($uri{strlen($uri)-1} != ‘/’)
return $uri.’/’;
else
return $uri;
}/**
The core function of the plugin. Selects only one language version from the passed text.
*/
function polyglot_filter($text, $lang = ») {
global $polyglot_settings;if($lang == »){$lang = $polyglot_settings;}
$text = preg_replace(« /[(/){0,1}lang_(..)]/i », « », $text);//fix for [lang_xx]
$text = preg_replace (‘/()
/i’, »$1″,$text);//fix for
$text = preg_replace (‘/()/i’, »\1″,$text);//adds lang_all to all other stuff that is not enclosed in lang_xx tags
$text = preg_replace (‘/()/i’, »\1″,$text);
$text = ».$text. »;if (preg_match_all ( ‘//’, $text , $match, PREG_PATTERN_ORDER)) {
if (isset($polyglot_settings) && polyglot_lang_exists($polyglot_settings,$text)){
//lets try to get proper language version
$text=str_replace(« », » »,$text);//we don’t want just lang_pref parts but also lang_all parts
$text=str_replace(« », » »,$text);$find = « /(?s)(.*?)/ »;
preg_match_all ( $find, $text , $match, PREG_PATTERN_ORDER);
$text = implode( »,$match[1]);}
elseif(polyglot_lang_exists($polyglot_settings,$text)){
//or at least the default language
$text=str_replace(« », » »,$text);
$text=str_replace(« », » »,$text);
$find = « /(?s)(.*?)/ »;
preg_match_all ( $find, $text , $match, PREG_PATTERN_ORDER);
$text = implode( »,$match[1]);
}else {
//all untranslated stuff
$text=str_replace(« », » »,$text);
$text=str_replace(« », » »,$text);
$find = « /(?s)(.*?)/ »;
$replace = « »;
$text = preg_replace($find,$replace,$text);
}
}return str_replace(array(« », » »),array( », »),$text);
}/**
Handy shortcuts of polyglot_filter function for direct use in the templates
*/
function p__($text){
return polyglot_filter($text);
}function p__e($text){
echo polyglot_filter($text);
}/**
Does the same as polyglot_filter but shows the message that informs visitor that selected language version is not available
*/
function polyglot_filter_with_message($text){
global $polyglot_settings;
$text = trim(polyglot_filter($text));
if($text == »){
$text = polyglot_filter($polyglot_settings);
}
return $text;
}/*function safe_link(){
global $post;$permalink = get_settings(‘home’) . ‘/’ . get_settings(‘blogfilename’) . ‘?’;
if ($post->post_status == ‘static’)
$permalink .= ‘page_id’;
else
$permalink .= ‘p’;$permalink .= ‘=’.$post->ID;
return $permalink;
}*//**
Prints out the list of other language versions contained in the current post.
*/
function polyglot_other_langs($none=’none’, $before=’- ‘, $after=’
‘, $pre=’
- (‘, $afters=’)
‘){
global $polyglot_settings, $post;if(!$polyglot_settings){
$uri_helper = »;
}
else {
$uri_helper = « {$polyglot_settings}/ »;
}$content = $post->post_content;//fred
$before = polyglot_filter($before);
$after = polyglot_filter($after);
$pre = polyglot_filter($pre);
$afters = polyglot_filter($afters);
$other_langs = polyglot_filter($none);if (preg_match_all ( ‘/[|]]/’, $content , $match, PREG_PATTERN_ORDER)) {
$match = array_unique($match[1]);
$other_langs = $before;foreach ($match as $lang){
if ($polyglot_settings != $lang) {$foo = ($polyglot_settings ) ? « » : get_trans($lang);
$other_langs .= « $pre<a href='".get_permalink();
if ($polyglot_settings) {
if($polyglot_settings || strpos(get_permalink(),’?’) === false){
$other_langs .= « {$uri_helper}{$lang}/ »;
}
else {
$other_langs .= « &lang_view=$lang' »;
}
} else {
if(strpos(get_permalink(),’?’) === false){
$other_langs .= « ?lang_view=$lang' »;
}
else {
$other_langs .= « &lang_view=$lang' »;
}}
$other_langs .= « ‘ rel= »alternate » hreflang= »{$lang} »>{$foo}$afters »;
}
}
if($other_langs != $before)//to avoid empty$other_langs .= $after;
else
$other_langs = $none;
}
echo $other_langs;
}/**
Prepares text for slug
*/
function polyglot_sanitize_title($text){
global $polyglot_settings;$text = polyglot_filter($text, $polyglot_settings);
return $text;
}//
code from ‘translate categories’ plugin
function polyglot_translate_callback($matches){return $matches[1].__($matches[2]).$matches[3];
}
/**
Not very nice way how to tranlate category name:(
It uses standard gettex function __ and works only when we have the category name in the .mo file!
*/
function polyglot_translate_the_category($text){return preg_replace_callback(‘/(]*>)(.*?)()/i’,’polyglot_translate_callback’,$text);
}//
function polyglot_get_users_pref_lang(){
GLOBAL $polyglot_settings;
$deflang = $polyglot_settings;# An advanced PHP Language Detection Script
# by Fibergeek (fibergeek @ codegurus.be)
#
# This script is a modification to a script I found via google
#
# 2003-12-18 – Version 1 (I added…)
# – you can now also specify the country code in the $knowlangs array
# – extraction of the country code ($country)
# – I fully documented the code
#
# 2004-01-07 – Version 2 (I added…)
# – you can now make $knowlangs NULL (the script will set to array to all known languages (ISO-639))
#
# NOTE : for those using Brion’s script, I renamed $lastquality to $quality
#
# Found at URL : http://mail.wikipedia.org/pipermail/wikitech-l/2002-October/001068.html
# Assumed creator : Brion VIBBER (wikitech-l@wikipedia.org)
# HTTP reference : RFC 2616 – ftp://ftp.isi.edu/in-notes/rfc2616.txt# ==================================================================================================
# TODO
# You need to add the 2 lines to your source code, and change the content of them of course 😉
# ==================================================================================================
#$polyglot_settings = NULL; // default to all known languages (ISO-639)
#$deflang = NULL; // there is no default language
#
#$polyglot_settings = array(‘en-us’, ‘en-uk’, ‘en’, ‘nl’); // We know : English (US & UK) and Dutch
#$deflang = ‘en-uk’; // In case of an error, we default to English UK# ==================================================================================================
# INFORMATION
# The following variables are returned by this program
# $lclist : the full list with the languages accepted by the client’s browser
# $lctag : the tag we are supporting (includes the country code if any)
# $quality : the quality
# $lang : the language code
# $country : the country code (if any)
#
# The following variables are used by this program (and may be overwritten if you use them also!)
# $langtag
# $qvalue
# $eachbit
# $tmppos
# $tmplclist
# $tmplctag
# $tmptagarray
# ==================================================================================================# ==================================================================================================
# THE SCRIPT
# ==================================================================================================# Check that $knowlangs is an array!
# NOTE : the list is taken from this URL : http://www.w3.org/WAI/ER/IG/ert/iso639.htm
if(!is_array($polyglot_settings))
{
if(is_string($polyglot_settings) || is_object($polyglot_settings) || $polyglot_settings != NULL)
die(« Fibergeek’s PHP Language Detection Script : You need define $polyglot_settings as an array or as NULL!
n »);
$polyglot_settings = 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’);
}# Initalisation of the default variables
if(isset($HTTP_SERVER_VARS))
$lclist = trim($HTTP_SERVER_VARS); # PHP running from a server
else
$lclist = trim($_SERVER); # PHP 5.0 when the old server variables disabled
$lctag = $deflang;
$tmppos = strpos($lctag, ‘-‘);
$quality = 0.0;
if($tmppos == FALSE or $tmppos == NULL)
{
$lang = $deflang;
if($deflang == NULL)
$country = NULL;
else
$country = »;
}
else
{
$lang = substr($lctag, 0, $tmppos);
$country = substr($lctag, $tmppos + 1);
echo « lang sub = $lang »;
}#
$langtag = ‘((?:[a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*)’;
$qvalue ='(0(?.[0-9]{1,3})?|1(?.0{1,3}))’;
$eachbit = ‘^’ . $langtag . ‘(?:;q=’ . $qvalue . ‘)?(?:,s*)?(.*)$’;#
$tmplclist = $lclist;# The loop
while(strlen($tmplclist))
{
if(preg_match(« /$eachbit/ », $tmplclist, $tmptagarray)) # requires 3.0.9
{
# Extract data from the tag list
$tmplctag = $tmptagarray[1];
$tmpquality = $tmptagarray[2];
if(strlen($tmpquality) == 0)
$tmpquality = 1;
$tmplclist = $tmptagarray[3];# Find the tag in our $polyglot_settings array (this search includes the country code if set)
if(in_array($tmplctag, $polyglot_settings) and $tmpquality > $quality)
{
# Extract the language & quality
$lctag = $tmplctag;
$lang = $tmplctag;
$country = »;
$quality = $tmpquality;
}
else
{
# Not found, does the tag include a country code?
$tmppos = strpos($tmplctag, ‘-‘);
if($tmppos FALSE)
{
# OK, the tag includes a country code but it’s not in the $polyglot_settings array, let’s extract the language and look it up
if(in_array(substr($tmplctag, 0, $tmppos), $polyglot_settings) and $tmpquality > $quality)
{
# Extract the language, country & quality
$lctag = $tmplctag;
$lang = substr($tmplctag, 0, $tmppos);
$country = substr($tmplctag, $tmppos + 1);
$quality = $tmpquality;
}
}
}
}
else
{
# There was an error, abort the loop
break;
}
}
return $lang;
}//get_users_pref_lang()//=========================== WIDGET CODE============================
function widget_polyglot_init() {
if ( !function_exists(‘register_sidebar_widget’) )
return;function widget_polyglot($args) {
extract($args);
$options = get_option(‘widget_polyglot’);
$title = $options;
$listtype = $options ? true : false ;echo $before_widget . $before_title . polyglot_filter($title) . $after_title . ‘
- ‘;
echo polyglot_list_langs($listtype) . ‘‘;
echo $after_widget;
}function widget_polyglot_control() {
// Get our options and see if we’re handling a form submission.
$options = get_option(‘widget_polyglot’);
if ( !is_array($options) )
$options = array(‘title’=>__(‘Language’), ‘listtype’=> »);
if ( $_POST ) {// Remember to sanitize and format user input appropriately.
$options = strip_tags(stripslashes($_POST));
$options = $_POST;
update_option(‘widget_polyglot’, $options);
}// Be sure you format your options to be valid HTML attributes.
$title = htmlspecialchars($options, ENT_QUOTES);
$listtype = $options;echo ‘
‘;
echo ‘Display as: <input type="radio" id="polyListtypeText" name="polyglot-listtype" value=""';
if ( » == $listtype) echo ‘checked= »checked » ‘;
echo ‘/>
<input type="radio" id="polyListtypeFlags" name="polyglot-listtype" value="true"' ;
if (‘true’ == $listtype) echo ‘checked= »checked » ‘;
echo ‘/>‘;
echo »;
}function widget_polyglot_style() {
?>
li#polyglot ul li:before, .language_item li{list-style-type:none;display:inline !important;padding: 2px !important;margin: 0 !important;}
<?php
}register_sidebar_widget(‘Polyglot’, ‘widget_polyglot’);
register_widget_control(‘Polyglot’, ‘widget_polyglot_control’, 300, 90);
if ( is_active_widget(‘widget_polyglot’) )
add_action(‘wp_head’, ‘widget_polyglot_style’);
}// Run our code later in case this loads prior to any required plugins.
add_action(‘plugins_loaded’, ‘widget_polyglot_init’);// ABP: filter if not back-end
if(strpos($_SERVER, ‘wp-admin’) === false){
add_filter(‘option_widget_text’, ‘polyglot_filter_array’, 10, 1);
}// Function for array filtering
/**
* ABP: filter array values
*/
function &polyglot_filter_array(&$ar){
foreach($ar as $k => $v){
if(is_array($v)){
$ar[$k] = polyglot_filter_array($v);
} else {
$ar[$k] = polyglot_filter($v);
}
}
return $ar;
}//get_the_tags – processor
function polyglot_get_the_tags(&$tags)
{if(!empty($tags))
{
foreach($tags as $tag)
{
$tag->name = polyglot_filter($tag->name);
}
}return $tags;
}//get_bookmarks – processor
function polyglot_get_bookmarks(&$bookmarks)
{
foreach($bookmarks as $bookmark)
{
$bookmark->link_name = polyglot_filter($bookmark->link_name);
$bookmark->link_description = polyglot_filter($bookmark->link_description);
}return $bookmarks;
}//returns proper $locale string (cs->cs_CZ)
function polyglot_get_locale($par)
{ GLOBAL $polyglot_settings;
return isset($polyglot_settings[$polyglot_settings]) ? $polyglot_settings[$polyglot_settings] : $par;
}//================================Backward Compatibility=============================
function lang_picker_respect_more($text){return polyglot_filter($text);}
function lang_picker($text) {return polyglot_filter($text);}
function lp_other_langs($none=’none’, $before=’- ‘, $after=’
‘, $pre=’
- (‘, $afters=’)
‘){return polyglot_other_langs($none, $before, $after, $pre, $afters);}
?>2) J’ai ajouté le code suivant dans header.php:
<?php if (function_exists('polyglot_list_langs'))
polyglot_list_langs(true); ?>Tout a été uploadé et activé…
J’ai, sur la page d’Accueil qui correspond à mon premier et seul article, un contenu suivant:[lang_fr]
FR
[/lang_fr]
[lang_en]EN
[/lang_en]
[lang_en]NL
[/lang_en]
Ya t il un code supplémentaire à ajouter?
J’ai lu le code suivant. Ou faut il le mettre???
J avoue que je ne comprends pas tout ce que je fais.
Merci d’avance pour votre aide!
29 juin 2013 à 14 h 24 min #580198salut
je cherche un tres bon module twitter qui peux faire apparaitre tous les tweets émis par des une communate sur mon site wordpress .27 septembre 2014 à 15 h 14 min #580199Salut,
J’ai quelques petits soucis avec le plugin Polyglot. Est-il possible de traduire les textes dans des sliders ? Voici le site sur lequel je travaille : http://auditculinaire.com/
Je peux traduire le menu, les articles, mais pas les gros titres sur la home page… La question a peut être déjà été posée mais je n’ai pas trouvé. Est-ce que quelqu’un aurait une solution ?
Car pour modifier les slider etc, je passe par l’interface theme option que le créateur du thème a fait…Merci !
7 octobre 2014 à 16 h 16 min #580200bonjour,
je me presente jessica du site associationnoahbaroni.fr
je me retrouve coincée, car apres avoir mis a jour wordpress version4.0, mon site a planté.
J’ai pu remettre le site en ligne, cependant je ne peux plus rien faire dans mon admin.
Je ne charger des photos, il me manque toutes mes extensions, witgets, etc…..
J ai bachup dropbox, je ne sais pas si je peux me servir de ca pour remettre mon admin, je n y connais rien.
mais je cherche desesperement a remettre tout en place.
Quelqu un peut m aider svp.Merci d avance
7 octobre 2014 à 16 h 17 min #580201association noah baroni wrote:bonjour,
je me presente jessica du site associationnoahbaroni.fr
je me retrouve coincée, car apres avoir mis a jour wordpress version4.0, mon site a planté.
J’ai pu remettre le site en ligne, cependant je ne peux plus rien faire dans mon admin.
Je ne charger des photos, il me manque toutes mes extensions, witgets, etc…..
J ai bachup dropbox, je ne sais pas si je peux me servir de ca pour remettre mon admin, je n y connais rien.
mais je cherche desesperement a remettre tout en place.
Quelqu un peut m aider svp.j ai aussi : Fatal error: Call to undefined function wp_dropdown_languages() in/home/associatz/www/wp-admin/options-general.php on line 322
Merci d avance
13 décembre 2014 à 16 h 16 min #580202Bonjour,
merci cela a vraiment aidé. again thanks.5 janvier 2015 à 14 h 11 min #580203bonjour j’aurais voulu installer {IRC}knochennet Webchat sur mon site mais je sais pas trop comment faire hors mis il est bien installer dans mes extentions
- <a href="";
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.