Re: [Catalyst] I18N with variables

2010-08-04 Thread Ton Voon


On 2 Aug 2010, at 06:08, Julien Sobrier wrote:


Hello,
I've started to translate my website using Catalyst::Plugin::I18N. It
works fine for static text. Bu I can't make it work for variables. For
example, I need to a translation for [% foo %] where for can take a
set of values defined in a database.

I'm sot sure what is the best way to translate such variables, and
what is possible:
* add a msgid for each possible value in messages.po = those gets
removed every time I run xgettext.pl
* Make the translation in my Database layer = unfortunately I use the
old Class::DBI, and could not find a plugin for it
* any other option?


What I do is use the variable to work out the dynamic name, and then  
in a dummy template file, have the possible options. Eg:


[% menu_name=Configuration; c.loc(menu_name) %]

Then in a dummy template file, have:

[% c.loc(Configuration) %]

This way xgettext.pl will always find it to put into messages.po. It  
means having to write in the dummy template all the possibilities, but  
it would have to be captured somewhere, so it might as well be in  
something that xgettext.pl can process.


Ton


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Trapping exceptions in Catalyst.pm

2010-08-04 Thread Ton Voon


On 2 Aug 2010, at 07:49, Bill Moseley wrote:


In execute() there's this code:

eval { $c-state( $code-execute( $class, $c, @{ $c-req- 
args } ) || 0 ) };


$c-_stats_finish_execute( $stats_info ) if $c-use_stats and  
$stats_info;


my $last = pop( @{ $c-stack } );

if ( my $error = $@ ) {

The problem is that it's possible for the eval to fail but $@ is not  
set.  An example is where Locale::Maketext localizes $@ so that  
exceptions come back with $@ undefined (for some odd reason).


In general, it's better to test the return value from eval directly  
instead of depend on $...@.  Something like:


my $has_exception;
eval { $c-state( $code-execute( $class, $c, @{ $c-req-args } )  
|| 0 ); 1; } || $has_exception++;

...
if ( $has_exception ) {

Or use the eval {; 1 } || do { my $msg = $@; ...}; style.


I did a bit of work in DBIx::Class where I changed all the eval  
statements to using Try::Tiny instead. Not sure if it got into trunk  
yet. A similar conversion here would work.


Ton


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Trapping exceptions in Catalyst.pm

2010-08-04 Thread Tomas Doran


On 4 Aug 2010, at 10:06, Ton Voon wrote:
In general, it's better to test the return value from eval directly  
instead of depend on $...@.  Something like:


my $has_exception;
eval { $c-state( $code-execute( $class, $c, @{ $c-req-args } )  
|| 0 ); 1; } || $has_exception++;

...
if ( $has_exception ) {

Or use the eval {; 1 } || do { my $msg = $@; ...}; style.


I did a bit of work in DBIx::Class where I changed all the eval  
statements to using Try::Tiny instead. Not sure if it got into trunk  
yet. A similar conversion here would work.


Branch to do that (Try::Tiny) entirely welcome, we already depend on  
it (via Moose).


Cheers
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Cross-link: How do I turn Moose objects into JSON for use in Catalyst?

2010-08-04 Thread Tomas Doran


On 3 Aug 2010, at 17:31, Evan Carroll wrote:


I've posted a question and a few possible fixes. Does anyone have
anything to add here? How do you go about dumping Moose to JSON in
Cat?


I use MooseX::Storage, as per perigrin's comment on the stack overflow  
post.


Cheers
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] I18N with variables

2010-08-04 Thread Nicholas Wehr
Check out Catalyst::Plugin::Localize::Simple

http://search.cpan.org/~wehr/Catalyst-Plugin-Localize-Simple-1.1/lib/Catalyst/Plugin/Localize/Simple.pm

I made it to overcome the learning curve of i18n, and it works very well.
Used it to translate English to Spanish, French, Japanese, Italian,
Portuguese, and Chinese Simplified. I provided a CMS for the translation
team to create and modify these translation files. Very simple and straight
forward. Let me know if you have questions on usage.

-nw


On Wed, Aug 4, 2010 at 1:04 AM, Ton Voon ton.v...@opsera.com wrote:


 On 2 Aug 2010, at 06:08, Julien Sobrier wrote:

  Hello,
 I've started to translate my website using Catalyst::Plugin::I18N. It
 works fine for static text. Bu I can't make it work for variables. For
 example, I need to a translation for [% foo %] where for can take a
 set of values defined in a database.

 I'm sot sure what is the best way to translate such variables, and
 what is possible:
 * add a msgid for each possible value in messages.po = those gets
 removed every time I run xgettext.pl
 * Make the translation in my Database layer = unfortunately I use the
 old Class::DBI, and could not find a plugin for it
 * any other option?


 What I do is use the variable to work out the dynamic name, and then in a
 dummy template file, have the possible options. Eg:

 [% menu_name=Configuration; c.loc(menu_name) %]

 Then in a dummy template file, have:

 [% c.loc(Configuration) %]

 This way xgettext.pl will always find it to put into messages.po. It means
 having to write in the dummy template all the possibilities, but it would
 have to be captured somewhere, so it might as well be in something that
 xgettext.pl can process.

 Ton



 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive:
 http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] process a restored request

2010-08-04 Thread Steve
Original post: 
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg01222.html


My apologies for rehashing this old post, but this is such a *nice* 
thing to do for users that
I'm sort of surprised the solution hasn't been implemented as a plugin 
or something, at least

so far as I can tell...

I'm trying to implement this elegant solution, but am getting stuck with the

'just dump any POST data back out into
hidden fields in the login form, don't change the URL, and have the login
form processed in a forward() from auto or similar rather than doing a
detach' part.

My questions are as follows:
What hidden field or fields are in the login form?

Where in the code sample are the items stashed? (or are they stored
elsewhere?)

Where in the code sample do we pick up after successful
authentication in order to (forward, detach, redirect - pick one or supply 
alt.)?



Full post:


 Hi,
 in my application, if a client issues a request after say 30 minutes of
 inactivity, I want to answer his request only after successfull
 authentication.

 Ideally, I would simply serialize $c-request in the session, ask for
 authentication, then if successfull restore the stored request to $c and call
 $c-dispatch. But after playing around a bit, it appears not to be that
 simple (the context is stored in the request as '_context', the body seems
 fetched only on-demand, dispatch seems to need some prepare_* methods to be
 called).

 I searched the list and only found this proposition for a similar mechanism:
 http://lists.scsys.co.uk/pipermail/catalyst/2007-February/012256.html

 Am I missing an easier way of doiing this?


Yes.

Don't try and serialize $c-req, just dump any POST data back out into
hidden fields in the login form, don't change the URL, and have the login
form processed in a forward() from auto or similar rather than doing a
detach. This is how I handle user needs to log in to continue across the
board and it makes life much simpler.

i.e. something like

sub auto :Private {
  my ($self, $c) = @_;
  unless ($c-user_exists) {
unless ($c-forward('try_login')) {
  $c-detach('show_login_form');
  return 0;
}
  }
  return 1;
}

sub try_login :Private {
  my ($self, $c) = @_;
  my $b = $c-req-body_parameters;
  return 0 unless $b-{__username};
  return $c-authenticate({
   username =  $b-{__username}
   password =  $b-{__password}
 });
}





___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst::Test local_request(), Test::WWW::Mechanize::Catalyst, and base href=...

2010-08-04 Thread Ronald J Kimball
On Mon, Aug 2, 2010 at 5:56 PM, Tomas Doran bobtf...@bobtfish.net wrote:

 On 29 Jul 2010, at 21:40, Ronald J Kimball wrote:

 The only reference I found to this issue is a post to this mailing list
 from 2007, which no one answered.  Has anyone else experienced this problem?
  Would a patch that cribs some code from LWP::UserAgent and puts it in
 Catalyst::Test local_request() be accepted?

 Yes.

 Please hop onto irc, grab a commit bit and make a branch!

I've created the Catalyst-Test-base-href branch and commited my
changes.  I'm ready for feedback.  Any particular next step I need to
take?

Ronald

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] process a restored request

2010-08-04 Thread Bill Moseley
On Wed, Aug 4, 2010 at 11:22 AM, Steve st...@matsch.com wrote:

 Original post:
 http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg01222.html

 My apologies for rehashing this old post, but this is such a *nice* thing
 to do for users that
 I'm sort of surprised the solution hasn't been implemented as a plugin or
 something, at least
 so far as I can tell...

 I'm trying to implement this elegant solution, but am getting stuck with
 the

 'just dump any POST data back out into
 hidden fields in the login form, don't change the URL, and have the login
 form processed in a forward() from auto or similar rather than doing a
 detach' part.


I think the suggestion was in auto always check if authenticated.  If not
authenticated, then attempt to authenticate with existing form data (e.g. if
a username and password have been posted).  if that succeeds then just
continue on to the requested action.

If cannot authenticate then display a login form but also include all other
parameters that were posted in hidden fields.  Set the action to post back
to the original action.

Repeat.

You probably want to track the original request method (GET POST PUT DELETE)
so that when the form is submitted (and finally authenticated) your action
sees the original request method.

If there's upload data then you would need to handle that additionally.




 My questions are as follows:
 What hidden field or fields are in the login form?


One for each posted parameter.



 Where in the code sample are the items stashed? (or are they stored
 elsewhere?)


When rendering the form.  You are using the client as a store.



 Where in the code sample do we pick up after successful
 authentication in order to (forward, detach, redirect - pick one or supply
 alt.)?


You don't.  if the original post was to /user (e.g. to create a new user)
then the login form looks just like your normal login form, but the action
is a POST to /user.



-- 
Bill Moseley
mose...@hank.org
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] process a restored request

2010-08-04 Thread Steve
Thanks so much!  I'm surprised this hasn't come up more often, as it 
seems such a common thing
for an application to allow for.  FWIW, I think this would make an 
excellent tutorial, perhaps for

next advent calendar, or even the next Catalyst book! :-)

On 8/4/2010 3:09 PM, Bill Moseley wrote:



On Wed, Aug 4, 2010 at 11:22 AM, Steve st...@matsch.com 
mailto:st...@matsch.com wrote:


Original post:
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg01222.html

My apologies for rehashing this old post, but this is such a
*nice* thing to do for users that
I'm sort of surprised the solution hasn't been implemented as a
plugin or something, at least
so far as I can tell...

I'm trying to implement this elegant solution, but am getting
stuck with the

'just dump any POST data back out into
hidden fields in the login form, don't change the URL, and have
the login
form processed in a forward() from auto or similar rather than doing a
detach' part.


I think the suggestion was in auto always check if authenticated.  If 
not authenticated, then attempt to authenticate with existing form 
data (e.g. if a username and password have been posted).  if that 
succeeds then just continue on to the requested action.


If cannot authenticate then display a login form but also include all 
other parameters that were posted in hidden fields.  Set the action to 
post back to the original action.


Repeat.

You probably want to track the original request method (GET POST PUT 
DELETE) so that when the form is submitted (and finally authenticated) 
your action sees the original request method.


If there's upload data then you would need to handle that additionally.


My questions are as follows:
What hidden field or fields are in the login form?


One for each posted parameter.

Where in the code sample are the items stashed? (or are they stored
elsewhere?)


When rendering the form.  You are using the client as a store.

Where in the code sample do we pick up after successful
authentication in order to (forward, detach, redirect - pick one
or supply alt.)?


You don't.  if the original post was to /user (e.g. to create a new 
user) then the login form looks just like your normal login form, 
but the action is a POST to /user.



--
Bill Moseley
mose...@hank.org mailto:mose...@hank.org


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
   




No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3050 - Release Date: 08/04/10 
00:45:00

   


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/