PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > smarty and GNU gettext
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
smarty and GNU gettext

Réponse
 
LinkBack Outils de la discussion
Vieux 30/05/2006, 13h11   #1 (permalink)
D_C
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut smarty and GNU gettext

hi list -

there is a great GNU library for dealing with localisation, that has a
php function gettext()
http://www.php.net/manual/en/function.gettext.php

many high-end PHP projects use this (wordpress, drupal).

I was wondering if there is a way to use this with smarty?

basically gettext is a php function, so if this is used in the middle
of a smarty template, it will make templates really ugly. I think!
Unless there is a clean way to inline php funcs inside smarty...

also, since a php funciton is being called in the middle of a
template, i imagine this stops smarty from being able to pre-compie/
cache the template itself?

So, any suggested approaches?

Can a modifier function work directly on a string? eg if i created a
localize() modifier that called gettext, then:

had a template like this:

{ "message list" | localize }

rather than puttig the english "message list" in a separate tag to be
passed to smarty:

{$messageListTag|localize}

this would require all the tags to be read in ahead of time, and
another level of indirection + probably reading lots of irrelevant
tags per page.

thanks for any as always!

/dc
--
_______________________________________________
David "DC" Collier

dc@pikkle.com
skype: callto://d3ntaku
http://www.pikkle.com
+81 (0)80 6521 9559

http://charajam.com$B!!!Z!z%-%c%i"v%8%c%`!z![(B
$B?M5$%-%c%i$H(BJ-POP$B:G?7%R%C%H6J$r<+J,$GAH$_9g$o$;$F(B
$BBT<u(BFlash$B$dCe(BFlash$B$r:n$C$A$c$*$&!* (B
_______________________________________________
  Réponse avec citation
Vieux 30/05/2006, 13h30   #2 (permalink)
Marcus Bointon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] smarty and GNU gettext

On 30 May 2006, at 13:11, D_C wrote:

> basically gettext is a php function, so if this is used in the middle
> of a smarty template, it will make templates really ugly. I think!
> Unless there is a clean way to inline php funcs inside smarty...


You really don't want to do that...

> also, since a php funciton is being called in the middle of a
> template, i imagine this stops smarty from being able to pre-compie/
> cache the template itself?
>
> So, any suggested approaches?


Yup. Wrap it up in a Smarty plugin. Many smarty plugins are no more
than this, so try looking at some. You might need a pair of plugins -
an initializer (e.g. to select and load an appropriate language file)
and a modifier to display a text item. The popup plugins work this way.

> Can a modifier function work directly on a string? eg if i created a
> localize() modifier that called gettext, then:
>
> had a template like this:
>
> { "message list" | localize }


Yes, you can use this syntax. Try for example {"hello world"|
escape:"url"} and it will render to 'hello%20world'.

There are several Smarty translation mechanisms around (including
some that use gettext) - try looking at the wiki: http://
smarty.incutio.com/

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk
  Réponse avec citation
Vieux 30/05/2006, 14h22   #3 (permalink)
Vicente Werner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] smarty and GNU gettext

You really don't want to use it, since the performance gains are negligible
from a custon made library getting the stuff from a DB -I've done and made
benchmarks and the results are similar with an edge going to custon made
libraries when you're using high ammounts of translated terms- .

For legibility reasons I implemented my system as block plugin:
{translate}text{/translate} and added some localization functions to deal
with numeric format etc..

On 5/30/06, Marcus Bointon <marcus@synchromedia.co.uk> wrote:
>
> On 30 May 2006, at 13:11, D_C wrote:
>
> > basically gettext is a php function, so if this is used in the middle
> > of a smarty template, it will make templates really ugly. I think!
> > Unless there is a clean way to inline php funcs inside smarty...

>
> You really don't want to do that...
>
> > also, since a php funciton is being called in the middle of a
> > template, i imagine this stops smarty from being able to pre-compie/
> > cache the template itself?
> >
> > So, any suggested approaches?

>
> Yup. Wrap it up in a Smarty plugin. Many smarty plugins are no more
> than this, so try looking at some. You might need a pair of plugins -
> an initializer (e.g. to select and load an appropriate language file)
> and a modifier to display a text item. The popup plugins work this way.
>
> > Can a modifier function work directly on a string? eg if i created a
> > localize() modifier that called gettext, then:
> >
> > had a template like this:
> >
> > { "message list" | localize }

>
> Yes, you can use this syntax. Try for example {"hello world"|
> escape:"url"} and it will render to 'hello%20world'.
>
> There are several Smarty translation mechanisms around (including
> some that use gettext) - try looking at the wiki: http://
> smarty.incutio.com/
>
> Marcus
> --
> Marcus Bointon
> Synchromedia Limited: Putting you in the picture
> marcus@synchromedia.co.uk | http://www.synchromedia.co.uk
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
Vicente Werner y Sánchez
  Réponse avec citation
Vieux 30/05/2006, 14h40   #4 (permalink)
Marcus Bointon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] smarty and GNU gettext

On 30 May 2006, at 14:22, Vicente Werner wrote:

> You really don't want to use it, since the performance gains are
> negligible from a custon made library getting the stuff from a DB -
> I've done and made benchmarks and the results are similar with an
> edge going to custon made libraries when you're using high ammounts
> of translated terms- .


Personally I think gettext is a clunky way of working anyway! I'm
using a DB-based one at present - it's nice to have a separate web
interface for translators to use independent of web apps.

> For legibility reasons I implemented my system as block plugin:
> {translate}text{/translate} and added some localization functions
> to deal with numeric format etc..


I've done it as both block and function - I find functions are tidier
for small things like field titles. I've yet to come up with a nice
way of handling embedded variables like gettext does, especially with
numbered params. Any ideas on that?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk
  Réponse avec citation
Vieux 30/05/2006, 14h53   #5 (permalink)
Vicente Werner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] smarty and GNU gettext

On 5/30/06, Marcus Bointon <marcus@synchromedia.co.uk> wrote:
>
> On 30 May 2006, at 14:22, Vicente Werner wrote:
>
> Personally I think gettext is a clunky way of working anyway! I'm
> using a DB-based one at present - it's nice to have a separate web
> interface for translators to use independent of web apps.



There're other issues I considered, as the need to reboot apache when you
change the .po files so they're loaded and the hit just for initilizing the
system.

I've done it as both block and function - I find functions are tidier
> for small things like field titles. I've yet to come up with a nice
> way of handling embedded variables like gettext does, especially with
> numbered params. Any ideas on that?




What I did was a modification of the block function so it could get a list
of vars that were substitued on the string.


Marcus
> --
> Marcus Bointon
> Synchromedia Limited: Putting you in the picture
> marcus@synchromedia.co.uk | http://www.synchromedia.co.uk
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
Vicente Werner y Sánchez
  Réponse avec citation
Vieux 30/05/2006, 15h50   #6 (permalink)
D_C
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] smarty and GNU gettext

thanks for all the comments. quite interesting what related issues a
question brings up :0

> There're other issues I considered, as the need to reboot apache when you
> change the .po files so they're loaded and the hit just for initilizing the
> system.


is this really the case? Wordpress and Drupal both use gettext and PO
files, and yet I cant imagine people in shared hosting restarting
apache...

in terms of performance, does the syntax suggested above:
{translate}some string{/translate}

mean that smarty cannot pre-compile the templates? (I'm not exactly
clear how all that works, so please bear with me! I think that the
template itself is converted to a php file, then each time a page is
displayed that uses it, things go a little quicker. but if there is an
area where possibly non-static content might be passing through a
function, this would mean the conversion to php also would happen
every time?)

also, for performance and clean templates, what about just using config files?

{#someString#}

of course, some kind of management GUI would be needed for building
the config files, but this isnt too big a deal.

tx,

/dc
  Réponse avec citation
Vieux 30/05/2006, 16h14   #7 (permalink)
Vicente Werner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] smarty and GNU gettext

On 5/30/06, D_C <lister@pikkle.com> wrote:
>
> is this really the case? Wordpress and Drupal both use gettext and PO
> files, and yet I cant imagine people in shared hosting restarting
> apache...



From the php manual:
winXP, PHP 4.3.5 as Apache1.3.29 module

Two hints for Windows users.

I found setting locale is neither sufficient nor nessecery. To get it work I
needed to set either LC_ALL or LANG enviroment variable to my locale. Anyway
this value must be proper for setlocale so it is good to test with it. In my
case it was bgr_BGR for bulgarian according to
http://www.unicode.org/onlinedat/countries.html

gettext checks for files once and keeps them in cashe. Especially it means
that if it doesn't find your files it won't search again, so restart Apache
after any directory changes!!

I know it's a windows specific issue, but I've seen similar issues on linux
machines.

mean that smarty cannot pre-compile the templates?


Not at all, my system just uses such marks to store the string for future
translation , which is done as a last step, after everything is rendered.

also, for performance and clean templates, what about just using config
> files?
>
> {#someString#}



They're clumsy and unmanageable when the ammount of translation items and
languages goes beyond a certain limit. A db is much more manageable.

of course, some kind of management GUI would be needed for building
> the config files, but this isnt too big a deal.
>


You can have a q&d web front end in less than an hour, adapted to your
needs.

--
Vicente Werner y Sánchez
  Réponse avec citation
Vieux 30/05/2006, 17h09   #8 (permalink)
Marcus Bointon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] smarty and GNU gettext

On 30 May 2006, at 15:50, D_C wrote:

> mean that smarty cannot pre-compile the templates? (I'm not exactly
> clear how all that works, so please bear with me! I think that the
> template itself is converted to a php file, then each time a page is
> displayed that uses it, things go a little quicker. but if there is an
> area where possibly non-static content might be passing through a
> function, this would mean the conversion to php also would happen
> every time?)


You are confusing compiled templates and cached output. Smarty does a
one-time conversion of your template syntax into straight PHP and
keeps it in ./templates_c. This 'compiled' template is just regular
PHP that gets run like any other script, and as such can have
whatever dynamic content you like. The next step is to cache output
(in ./cache) from the compiled script, which smarty does if you turn
caching on ($smarty->caching = 1). This output is of course
completely static, but it has almost zero overhead to deliver. Smarty
can mix cached and uncached elements within a page (by including sub-
templates that are cached within ones that are not, see $smarty-
>caching = 2 in the docs too), so just because one part of your page

is dynamic doesn't mean you have to lose out on caching altogether.

That clearer?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h19.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17269 seconds with 16 queries