|
|
|||
| [ home about me music cv background involvements code community hosting metal log contact webmail ] | ||||
|
NAMEMasonX::Resolver::Polyglot - Component path resolver for easy internationalization
SYNOPSISIn your http.conf:
PerlInitHandler MasonX::Resolver::Polyglot
<Directory /var/www/html>
PerlSetVar PolyglotDefaultLang en
PerlSetVar PolyglotDefaultURILang en
PerlAddVar MasonDataDir "/var/www/mason"
PerlAddVar MasonCompRoot "/var/www/html"
<FilesMatch "^..$|\.html(\...)?$">
SetHandler perl-script
PerlSetVar MasonResolverClass MasonX::Resolver::Polyglot
PerlHandler HTML::Mason::ApacheHandler
</FilesMatch>
</Directory>
Or, in your Mason guts:
my $resolver = MasonX::Resolver::Polyglot->new( comp_root => '/var/www/mason' );
my $info = $resolver->get_info('/some/comp.html');
my $comp_root = $resolver->comp_root;
CONFIGURATION
DESCRIPTIONThis This allows a web designer to provide structure in language independant components, and confine language-centric HTML to other components that the top level pages use. Components are labeled by suffix. Examples:
index.html - language independant component. Either last try component (if no other languages are acceptable) or the default language (if There is nothing magic about the html suffix; these do not have to be top level components. Let us suppose that index.html has a component called ``menubar'' which has text or image buttons of the site map. We may write the following components: menubar - the English version (we have set PolyglotDefaultLang to ``en'') menubar.en-us - the American English version menubar.fr - the French version menubar.it - the Italian version The code in index.html just calls ``menubar'' normally, and the resolver will pick the ``right'' component, ultimately falling back on the unsuffixed version if it can't find a better match. There are really two pieces to Polyglot. The Mason resolver piece is a child of HTML::Mason::Resolver::File::ApacheHandler and compares the Language-Accept preferences a web client presents with what is available on the filesystem, and finds the best match. The other piece is the PerlInitHandler which scans (and potentially alters) the URL for a leading language code. The effect this has is to override all preferences. If, for some reason, you want to peek at the URI that actually was typed in before Polyglot ate the language code, it is stashed away in $r->pnotes('POLYGLOT_URI'). Like our aformentioned English/Spanish site, we have an English index.html, and a Spanish index.html.es. My site wants to provide the ability to choose the site language without mucking with the brower's language preference. In my index.html, I have a ``Spanish'' link which links to ``/es/index.html'', and an ``English'' link in my index.html.es that links to ``/index.html''. I make all other links in the site _relative_. The effect this has is to propagate the /es/ prefix, consistantly overriding the browser's language preference until the user clicks on an absolute URL. Polyglot now makes its language decision order array available through the Apache request
my @langs = @{$r->pnotes('POLYGLOT_LANGS')};
@langs will contain a ranked list of language preference. It makes the language decision it made available by:
my $lang = $r->pnotes('POLYGLOT_LANG');
And also, the original pre-language-stripped URI available like so:
my $origuri = $r->pnotes('POLYGLOT_URI')
METHODS
http://www.mydomain.com/colors/red.html - gives me an English page http://www.mydomain.com/es/colors/red.html - forces it to give me the Spanish page (if it exists)
SEE ALSO
CREDITThanks to Dorian Taylor <dorian@foobarsystems.com> for his nice Accept-Language code.
AUTHORBenjamin H Kram <ben@base16consulting.com>
All text and images ©2003-2008 Ben H Kram |