SPUG: My two perl gizmos (CPAN module paralysis)

Jonathan Gardner jgardn at alumni.washington.edu
Thu Dec 19 11:08:20 CST 2002

On Thursday 19 December 2002 06:17 am, Fred Morris wrote:
> Very briefly, here are short synopses of the two modules which I have
> contemplated submitting to CPAN. I know that left to my own devices, that
> will never happen.
> Both of these modules are utilized in a working application which gets
> daily use.
> Maybe this'll encourage others to share theirs, and we can get together and
> at least get the peer review issue out of the way (there are a number of
> impediments standing between me and CPAN, peer review is only one). Or,
> maybe somebody will be interested enough to say "hey, I could use that!".
> Be aware, neither of them is packaged for distribution at the moment
> although anyone who's competent with Perl should have no problem getting
> them to work; they do have POD.
> Problem:
> Generally speaking, localization. This means for languages, but also for
> different parts of an application, or different applications of reusable
> parts.
> Utility:
> I find it useful, but mostly I just think it's cool. The overhead for this
> might be somewhat large in a occasionally-used Perl script, but with
> mod_perl a persistent hash is constructed of particular fully-qualified
> names which have already been resolved.
> Synopsis:
> The constants are all retrieved with a function call which takes as a
> parameter a key which will resolve to a constant (or filter, I lied).
> So, you define something like
>   Success => { 'string', 'Done!' }
> You reference it in different places as
>   $cliches->cliche( 'SomeModule.Frotzify.Success' )
>   $cliches->cliche( 'ThisModule.Frappe.Success' )
> You may decide that when you Frappe you want a different message or when
> you Stir in SomeModule the same thing is needed, and so you define
> overloads (overrides?):
>   Frappe.Success => { 'string', 'Cheers!' }
>   SomeModule.Stir.Success => { 'string', 'Mixed!' }

The only thing weird about what I see is that you might as well define 
"$Success" and let namespaces do the rest for you. For instance, you can do:

$main::Success = "Done!";
$Frappe::Success = "Cheers!";
$SomeModule::Stir::Success = "Mixed!";

And just use "$Success" in the appropriate place.

As far as a way to do translations efficiently and well...  Qt is a C++ widget 
library for Windows and X. It is probably the best platform to program for 
localization and translation.

Qt uses a function called tr() (which unfortunately is a builtin in perl). You 
pass in the string, and then define localization later. If we changed the 
name to trn():


Later on, you can ask the module that defined trn() what string were used in 
your program. With a list of all of your strings, you can translate it to a 
different language or localization, put that into a file, and tell the module 
to use that localization.

The problem is that you want to use a finite number of strings. For instance:

trn("Hello, $first_name")

is never going to get translated except for a finite number of $first_name.

The way to work around that is to do something like:

sprintf(trn("Hello, \%s!"), $first_name)

or something more ingenious, which probably exists in perl already.

Anyway, it's a couple of pennies, if that.

Jonathan Gardner
jgardn at alumni.washington.edu

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org

More information about the spug-list mailing list