It's Alessio Placitelli's playground
Polyglot: how to show both language name and flag
So here we go with tip #2 for this great plugin. I wanted to show both the flag and the name of available languages on my wordpress sidebar. The function responsible for checking available languages is polyglot_list_langs, which I had to modify a little bit to suit my needs. Ok, let’s stop talking and start coding
- Enter WordPress Administration Area
- Edit Polyglot Plugin ( Plugins -> Polyglot -> Edit).
- Look for polyglot_list_langs function (~ line no. 487)
- Look for this line of code (near the end of the function, ~ line no. 544)
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>";
- Replace that line with the following code block (yeah, I know that’s not very elegant)
if($flags == 2) echo "\"><img src=\"".$polyglot_settings['path_to_flags'].$polyglot_settings['flags'][$value] ."\" alt=\"".get_trans($value)."\" title=\"".get_trans($value)."\" /> ".get_trans($value)."</a></li>"; else 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>";
- Ok, we’re almost done. Now you can simply call polyglot_list_langs(2) to make it show the flag and language name
To get it working in our wordpress sidebar we need to look for the function called in widget_polyglot (around line 911) and change its argument from $listtype (which wasn’t working for me) to 2.
We made it, now polyglot will please us with its flags and language names
Any feedback is apreciated (even cursing me for my italo-english
) !
| Print article | This entry was posted by Alessio Placitelli on 30 December 2007 at 13:15, and is filed under Tips and Tricks. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
English
about 2 years ago
You should probably make these known to the plugin author as well, if you haven’t already.
about 2 years ago
Already done some time ago
http://fredfred.net/skriker/index.php/polyglot
about 2 years ago
ciao ho una sola domanda da farti….come posso mettere una bandiera sotto l’altra?ho seguito la tua guida e ora vedo sia il testo che le bandiera, ma sono una dopo l’altra, io le vorrei una sotto l’altra….come faccio?
about 2 years ago
Ciao! Se il tema che usi non modifica il tag <li> le bandiere dovrebbero già essere una sotto l’altra. Se così non fosse, prova inserendo <br /> dopo </li> nelle righe che hai modificato seguendo questa guida
about 2 years ago
Ciao…intanto complimenti per il tutorial!! ^_^
La mia necessità è la seguente: inserire le due bandierine sulla barra di navigazione e non su quella laterale. Anche senza bandierine mi basta la scritta EN IT. Come posso fare? Mi basta richiamare la funzione “polyglot_list_langs(2)” nel punto in cui mi interessa?
grazie mille ciao!!!
about 2 years ago
Ciao! Grazie a te per i complimenti, abbiamo rischiato di incontrarci al BarCamp
Se hai seguito questo tutorial, usando polyglot_list_langs(2) mostrerai sia la bandierina che il nome della lingua. Per mostrare solo le bandierine, devi usare polyglot_list_langs(1), esattamente nel punto dove vuoi che queste vengano mostrate!
Potresti anche aver bisogno di modificare quella funzione un pochino per integrarla meglio nel tuo blog, in particolare nel foreach c’è <li class=”$highlight”> e chiamate simili..
about 2 years ago
Cacchio a saperlo prima…ci sarai a Milano per il WordCamp? Io credo proprio di si, magari ci si vede là.
Intanto grazie per i consigli che mi hai dato. Sono quasi riuscito a sistemare tutto, mi rimangono due problemini ancora, uno semplice: devo solo mettere le due bandiere una in fila all’altra. Il secondo un pò più complesso che è troppo lungo da spiegare ma dovrei risolvere pure quello.
A presto Dave
about 2 years ago
Purtroppo niente WordCamp
Va bene, sarà per la prossima
In ogni caso, per mettere le bandierine una di lato all’altra, puoi seguire questa semplicissima guida:
http://css.maxdesign.com.au/listamatic/horizontal01.htm
A presto!
about 2 years ago
Ma ho sistemato semplicemente con il css nulla di che…
Ho solo un dubbio, finora il sito ce l’ho in locale non ancora testato su server. Appena apro la prima pagina se clicco subito su inglese sembra che non trovi la pagina inglese e visualizza questo errore:
Not Found
The requested URL /molino/lang-pref/en/ was not found on this server.
Secondo te che problema c’è?Io non ho toccato nulla di codice…buh…magari una volta che metto online funziona bene
about 2 years ago
Anche io ho avuto il tuo stesso problema! Prova a cambiare questa variabile presente nel file polyglot.php, da true a false.
$polyglot_settings['lang_rewrite'] = true;