aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Roles/Translatable.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-07-16 22:05:52 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-08-10 11:30:41 +0100
commitcc3e99fa9878bfb722e61d4a09d94839b152c5b7 (patch)
treeaa273efab59cb60c6c0edc37de9b7665aa49b27d /perllib/FixMyStreet/Roles/Translatable.pm
parentfe4153e367bcbb74eebed9c8ac0126d94709506c (diff)
Set up translatable category columns.
As category is used both for display and as a link between Problem and Contact tables, add `category_display` for use whenever a category is displayed.
Diffstat (limited to 'perllib/FixMyStreet/Roles/Translatable.pm')
-rw-r--r--perllib/FixMyStreet/Roles/Translatable.pm13
1 files changed, 13 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Roles/Translatable.pm b/perllib/FixMyStreet/Roles/Translatable.pm
index 43cb063d1..cc66f9621 100644
--- a/perllib/FixMyStreet/Roles/Translatable.pm
+++ b/perllib/FixMyStreet/Roles/Translatable.pm
@@ -22,6 +22,19 @@ sub _translate {
my $table = lc $self->result_source->source_name;
my $id = $self->id;
+ # Deal with the fact problem table has denormalized copy of category string
+ if ($table eq 'problem' && $col eq 'category') {
+ my $body_id = $self->bodies_str_ids->[0];
+ return $fallback unless $body_id && $body_id =~ /^[0-9]+$/;
+ my $contact = $schema->resultset("Contact")->find( {
+ body_id => $body_id,
+ category => $fallback,
+ } );
+ return $fallback unless $contact; # Shouldn't happen, but some tests
+ $table = 'contact';
+ $id = $contact->id;
+ }
+
if (ref $schema) {
my $translation = $schema->resultset('Translation')->find({
lang => $schema->lang,