I apologize if the problem definition is a bit disjointed. We have been attacking this issue on many different vectors.
Basic description, we have a website we are trying to provide translations for using Locale::TextDomain
We have fastcgi scripts, that call our local library of perl modules. Fastcgi and translation is tricky (as we are using it) because the language is set at the launch of the script and persists.
So in our library of perl modules this works.
package SR::Locale;
our $LOCALE_NAMESPACE = 'es';
use Locale::TextDomain::UTF8 qw( $LOCALE_NAMESPACE );
our $word = __("football");
But we can't figure out a means to dynamically set the variable $LOCALE_NAMESPACE at startup. We'd like to set it based on the request_uri or the dir path of the script being executed or something like that. So we'd like to do something like, but we can't figure this out in a fast cgi setting:
package SR::Locale;
$ENV{REQUEST_URI} =~ m{example.com/(..)/}
our $LOCALE_NAMESPACE = $1;
use Locale::TextDomain::UTF8 qw( $LOCALE_NAMESPACE );
our $word = __("football");
in this example (for a fastcgi), $ENV{REQUEST_URI} is blank in the module at script start.
Any help would be much appreciated. I have not been able to find any references to translation and fastcgi working together in perl.
I don't know that much about translation in fastcgi environments, but I do know that
useis a compile-time statement, so theusestatement in your script would be the first thing that Perl would execute (even before$LOCALE_NAMESPACEis initialized).The run-time equivalent of
use MODULE ARGSisThis works sometimes to dynamically configure a module at run-time, though it also has many failure modes.