aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CatDap
diff options
context:
space:
mode:
authorBuchan Milne <buchan@mageia.org>2011-02-25 12:22:21 +0000
committerBuchan Milne <buchan@mageia.org>2011-02-25 12:22:21 +0000
commit5088706b61d93fbaf27bacb16745aba3cd5917a0 (patch)
tree05022fde1de6ba09941032e6325b73371fbffd1a /lib/CatDap
parent420e9a02a8a0f4a685457889e95e867c128a563c (diff)
downloadidentity-5088706b61d93fbaf27bacb16745aba3cd5917a0.tar
identity-5088706b61d93fbaf27bacb16745aba3cd5917a0.tar.gz
identity-5088706b61d93fbaf27bacb16745aba3cd5917a0.tar.bz2
identity-5088706b61d93fbaf27bacb16745aba3cd5917a0.tar.xz
identity-5088706b61d93fbaf27bacb16745aba3cd5917a0.zip
Try and do some correction of languages (e.g. it-it to it, i-default to en)
Diffstat (limited to 'lib/CatDap')
-rw-r--r--lib/CatDap/Controller/register.pm31
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/CatDap/Controller/register.pm b/lib/CatDap/Controller/register.pm
index 2038e2b..80dbbb9 100644
--- a/lib/CatDap/Controller/register.pm
+++ b/lib/CatDap/Controller/register.pm
@@ -25,8 +25,7 @@ Catalyst Controller.
sub index :Path :Args(0) : Form {
my ( $self, $c ) = @_;
- my $langs = join ',',@{$c->languages};
- $c->log->debug("Languages: $langs, default: " . $c->language . ", saving: " . ${$c->languages}[0]);
+ my $lang = choose_language($c);
#my $form = Catalyst::Controller::HTML::FormFu->form();
#$c->response->body('Matched CatDap::Controller::register in register.');
@@ -106,8 +105,8 @@ sub check : Local {
my $ug = Data::UUID->new;
my $password = $ug->create_str();
my $cn = $c->request->params->{gn} . " " . $c->request->params->{sn};
+ my $lang = choose_language($c);
$c->log->info("Creating account for user $username");
- $c->log->debug("Preferred language: " . ${$c->languages}[0]);
$mesg = $c->model('Proxy')->add($dn,
attr => [
objectclass => [ 'inetOrgPerson' ],
@@ -117,7 +116,7 @@ sub check : Local {
mail => $email,
pwdReset => 'TRUE',
userPassword => $password,
- preferredLanguage => ${$c->languages}[0],
+ preferredLanguage => $lang,
]
);
if ($mesg->code) {
@@ -155,7 +154,29 @@ sub captcha : Local {
return $c->create_captcha();
}
-
+sub choose_language : Private {
+ my $c = shift;
+ my $langs = join ',',@{$c->languages};
+ # FIXME heuristic for correcting languages, we may want a different strategy
+ # in future in conjunction with server-side constraints with slapo-constraint.
+ # E.g. we could have a languages container with mapping from browser locale
+ # codes (preferredLanguage, which is multi-valued), to a single value
+ # (e.g. mageiaselectedLanguage, or similar). Then use a uri-based constraint on
+ # with mageiaSelectedLanguage as the attribute
+ # Also to be considered, pushing all the languages to preferredLanguage, but
+ # then do we use ordering?
+ my $lang = ${$c->languages}[0];
+ if ($lang !~ /^\w\w\w?(-\w+)?$/) {
+ $lang = 'en';
+ }
+ # Partial list of lang-variant locales where localisation is different
+ if ($lang !~ /^(en-gb|en-us|pt-br|no-\w+|zh-\w+)$/) {
+ $lang =~ s/^(\w+)-\w+$/$1/;
+ }
+ $c->log->debug("Browser languages: $langs,using preferred language: $lang");
+ $c->log->debug("Selected language $lang not default " . $c->language) if $lang ne $c->language;
+ return $lang;
+}
=head1 AUTHOR