aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm13
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm7
-rw-r--r--perllib/FixMyStreet/DB/Schema.pm3
-rw-r--r--perllib/FixMyStreet/Roles/Translatable.pm39
7 files changed, 71 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index c1628d010..2365118ea 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -168,6 +168,9 @@ template paths, maps, languages etc, etc.
sub setup_request {
my $c = shift;
+ # Set the Catalyst model schema to the same as the DB schema
+ $c->model("DB")->schema( FixMyStreet::DB->schema );
+
$c->setup_dev_overrides();
my $cobrand = $c->cobrand;
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index bd9e80dc7..561a6c2e3 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -196,8 +196,8 @@ sub display_location : Private {
my @pins;
unless ($c->get_param('no_pins')) {
@pins = map {
- # Here we might have a DB::Problem or a DB::Nearby, we always want the problem.
- my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_;
+ # Here we might have a DB::Problem or a DB::Result::Nearby, we always want the problem.
+ my $p = (ref $_ eq 'FixMyStreet::DB::Result::Nearby') ? $_->problem : $_;
$p->pin_data($c, 'around');
} @$on_map_all, @$nearby;
}
@@ -311,8 +311,8 @@ sub ajax : Path('/ajax') {
# create a list of all the pins
my @pins = map {
- # Here we might have a DB::Problem or a DB::Nearby, we always want the problem.
- my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_;
+ # Here we might have a DB::Problem or a DB::Result::Nearby, we always want the problem.
+ my $p = (ref $_ eq 'FixMyStreet::DB::Result::Nearby') ? $_->problem : $_;
my $colour = $c->cobrand->pin_colour( $p, 'around' );
my $title = $c->cobrand->call_hook(pin_hover_title => $p, $p->title_safe) || $p->title_safe;
[ $p->latitude, $p->longitude,
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 8f068f0ec..c3616eed0 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -318,6 +318,19 @@ sub body_check : Private {
}
}
+ my @translations = $c->model('DB::Translation')->search( {
+ tbl => 'body',
+ col => 'name',
+ msgstr => $q_body
+ } )->all;
+
+ if (@translations == 1) {
+ if ( my $body = $c->model('DB::Body')->find( { id => $translations[0]->object_id } ) ) {
+ $c->stash->{body} = $body;
+ return;
+ }
+ }
+
# No result, bad body name.
$c->detach( 'redirect_index' );
}
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 4a886204c..1a0bbb0c8 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -269,6 +269,8 @@ sub set_lang_and_domain {
DateTime->DefaultLocale( 'en_US' );
}
+ FixMyStreet::DB->schema->lang($set_lang);
+
return $set_lang;
}
sub languages { FixMyStreet->config('LANGUAGES') || [] }
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 9a64d1608..db7777053 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -121,12 +121,19 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BOJANVwg3kR/1VjDq0LykA
+use Moo;
+use namespace::clean;
+
+with 'FixMyStreet::Roles::Translatable';
+
sub url {
my ( $self, $c, $args ) = @_;
# XXX $areas_info was used here for Norway parent - needs body parents, I guess
return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ), $args || {} );
}
+around name => \&translate_around;
+
sub areas {
my $self = shift;
my %ids = map { $_->area_id => 1 } $self->body_areas->all;
diff --git a/perllib/FixMyStreet/DB/Schema.pm b/perllib/FixMyStreet/DB/Schema.pm
index 7833ee68c..45d731c33 100644
--- a/perllib/FixMyStreet/DB/Schema.pm
+++ b/perllib/FixMyStreet/DB/Schema.pm
@@ -18,8 +18,11 @@ __PACKAGE__->load_namespaces(
# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-07-13 14:15:09
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UpH30RXb6SbCqRv2FPmpkg
+use Moo;
use FixMyStreet;
__PACKAGE__->connection(FixMyStreet->dbic_connect_info);
+has lang => ( is => 'rw' );
+
1;
diff --git a/perllib/FixMyStreet/Roles/Translatable.pm b/perllib/FixMyStreet/Roles/Translatable.pm
new file mode 100644
index 000000000..43cb063d1
--- /dev/null
+++ b/perllib/FixMyStreet/Roles/Translatable.pm
@@ -0,0 +1,39 @@
+package FixMyStreet::Roles::Translatable;
+
+use Moo::Role;
+
+sub translate_around {
+ my ($orig, $self) = (shift, shift);
+ my $fallback = $self->$orig(@_);
+ (my $col = (caller(2))[3]) =~ s/.*:://;
+ $self->_translate($col, $fallback);
+}
+
+sub translate {
+ my ($self, $col) = (shift, shift);
+ my $fallback = $self->$col(@_);
+ $self->_translate($col, $fallback);
+}
+
+sub _translate {
+ my ($self, $col, $fallback) = @_;
+
+ my $schema = $self->result_source->schema;
+ my $table = lc $self->result_source->source_name;
+ my $id = $self->id;
+
+ if (ref $schema) {
+ my $translation = $schema->resultset('Translation')->find({
+ lang => $schema->lang,
+ tbl => $table,
+ object_id => $id,
+ col => $col
+ });
+ return $translation->msgstr if $translation;
+ } else {
+ warn "Can't use translation on this call to $table.$col";
+ }
+ return $fallback;
+};
+
+1;