Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2007-12-12 16:08:00

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

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.

  1. register_callback("prad_switch_lang", "admin","",1);
  2. function prad_switch_lang() : select and change the language
  3. function xxx() capture the buffer with ob_start()
  4. function yyy() built the HTML and return

I’ll give you this plugin to test it soon ;-)


françois

Offline

#26 2007-12-12 19:12:33

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

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)

  1. 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.
  2. 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

#28 2007-12-13 02:07:18

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

#29 2007-12-13 06:06:49

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

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.

  1. I don’t know how to test and break if “If any error occurs”.
  2. 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

#31 2007-12-13 06:41:52

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

Re: Switch language menu for all users

OK : I will apply your improvment for the ps().

Many thanks _Steve ;-)


françois

Offline

#32 2007-12-13 08:19:17

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

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

#33 2007-12-13 08:31:34

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

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

#34 2007-12-13 09:13:20

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

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

#35 2007-12-13 13:55:14

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

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

#36 2007-12-17 07:50:36

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

Re: Switch language menu for all users

Now in the plugin author support.


françois

Offline

Board footer

Powered by FluxBB