Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Switch language menu for all users
ruud a écrit:
The language choice can be done like that (
0
as last parameter in register_callback), but once the language is chosen, you use a callback to change the language before the page begins rendering (1
as last parameter). So you need 2 register_callbacks.
Thanks ruud, but with only one register_callback
and the last parameter at 1
I made it work.
register_callback("prad_switch_lang", "admin","",1);
function prad_switch_lang()
: select and change the languagefunction xxx()
capture the buffer withob_start()
function yyy()
built the HTML andreturn
I’ll give you this plugin to test it soon ;-)
françois
Offline
Re: Switch language menu for all users
prad_switch_lang is born.
Just have a look here .
Compatibility with 4.0.2 > 4.0.5
Last edited by fpradignac (2007-12-12 20:10:17)
françois
Offline
#27 2007-12-13 01:00:53
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Switch language menu for all users
françois
Congratulations!!! I just pulled it and tried it, and it seems to work fine for me. Thank you for the credits too.
I notice you do this in prad_switch_lang()
…
if (!$message && ps('step')=='list_languages' && ps('language'))
{
$locale = doSlash(getlocale(ps('language')));
safe_update("txp_prefs","val='".doSlash(ps('language'))."'", "name='language'");
safe_update("txp_prefs","val='". $locale ."'", "name='locale'");
$textarray = load_lang(doSlash(ps('language')));
$locale = setlocale(LC_ALL, $locale);
$message = gTxt('preferences_saved');
}
But you could try…
$language = ps('language');
if (!$message && ps('step')=='list_languages' && $language)
{
$locale = doSlash(getlocale($language));
safe_update("txp_prefs","val='".doSlash($language)."'", "name='language'");
safe_update("txp_prefs","val='". $locale ."'", "name='locale'");
$textarray = load_lang(doSlash($language));
$locale = setlocale(LC_ALL, $locale);
$message = gTxt('preferences_saved');
}
for a little more efficiency.
Finally, a couple of things I’ve found out (the hard way) about using output buffer processing routines like prad_switch_langHTML($buffer)
…
- If any error occurs at all in them, you’ll get a blank page as a result. So if you ever see a totally blank
admin > user
tab, it’s probably an error in your routine. - If you ever need to access an object that was created before the output buffer processing started then you’ll find that the object is already destroyed by the time your routine is called if you are using php5 — but on php4 it will still be in existence.
— Steve
Offline
Re: Switch language menu for all users
fpradignac,
It’s really nice that you sorted it out and produced a plugin too :)
But to notice that prad_
shoud be a three lettered prefix , not a four, as the quideline says.
Cheers!
Offline
Re: Switch language menu for all users
Gocom a écrit:
But to notice that
prad_
shoud be a three lettered prefix , not a four, as the quideline says.
Yes, but I’m still recorded in his list with my four letters prefix. I’ll look at this point : can I have 2 prefix ? prad_ for my older ones and prd_ for th new one ?
But please Gocom test it, I saw that you don’t downloaded it ;-))))
_Steve
Thanks for testing !!!
Has you can see in my hard code, I’m not a programmer, I’ve just hack a function of txp_prefs.php
, so your help is very important to make a «cleaner» code.
- I don’t know how to test and break if “If any error occurs”.
- I don’t understand the scope of your remark ? Should I have to improve this point ?
françois
Offline
#30 2007-12-13 06:13:36
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Switch language menu for all users
françois
No, no need to change anything — it works fine as it is — what I posted was just an optional ‘tweak’ that saves you calling the ps()
routine repeatedly.
Regarding the output buffer stuff: I was just sharing some hard-won experience. The MLP pack makes use of buffer processing quite a lot and its hard to debug code inside these processing routines.
— Steve
Offline
Re: Switch language menu for all users
OK : I will apply your improvment for the ps()
.
Many thanks _Steve ;-)
françois
Offline
Re: Switch language menu for all users
Hi François ;.)
You made a useful plugin, thanks lot.
Bravo François. Il sont peu nombreux les plugins “made in France” :)
Le défis est donc lancé : il va falloir que je m’y mette également :)
Cordialement,
Last edited by Pat64 (2007-12-13 08:22:01)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Switch language menu for all users
Thanks Patrick,
Fait-il bon à Bayonne ce matin ? (J’a vu passer dans mes stats quelqu’un du secteur de Bayonne, ce matin, en provenance de ce post : je suppose que c’est toi ;-). Concernant les plugins, tu as des idées de nouvelles fonctions ?
Cordialement,
françois
Offline
Re: Switch language menu for all users
Ah Ah!
La LiveBox change d’IP chaque jour mais c’est presque cela : je suis à Lescar près de Pau!
Ce forum est US si nous communiquons en français les modérateurs ne vont pas apprécier :)
S’agissant d’idée de plugin : oui, j’en ai une qui me trottine dans la tête depuis bien longtemps. Un style switcher par choix de dates/heures disponible dans un onglet du back-end et permettant, via des listes déroulantes, de sélectionner le stylesheet à appliquer puis de préciser sa date/heure d’application. Utile à divers usages : application d’une mise en forme pour un événement particulier (Noël, Pâques, Promo commerciale, etc…) ; modification de l’apparence globale d’un site lors de campagnes publicitaires, etc…
Je compte te contacter par mèl pour que tu me donnes des infos sur la création des plugins sous TXP, si tu es d’accord.
Tu peux me contacter à propos de cette idée, également.
A très bientôt.
Last edited by Pat64 (2007-12-13 09:20:17)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Switch language menu for all users
Pat64 a écrit:
… je compte te contacter par mèl pour que tu me donnes des infos sur la création des plugins sous TXP, si tu es d’accord.
For non-french people, we were talking about the weather in Pau (France) ;-)))
No problem to contact me Patrick.
To create your plugin you can use zem template on your server. And there’s a very usefull plugin ied_plugin_composer that let you work directly on you TXP admin interface.
françois
Offline
Offline