diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-15 08:52:47 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-15 15:19:21 +0100 |
commit | d522ef800a7c11547857597be092ae2b59f77f29 (patch) | |
tree | f5222e5c1923806b7499d2958874c41261533373 | |
parent | 310a46ece56eb8327a1b38a3afc011eb3911e8ac (diff) |
Remember translation lookup for request remainder.
-rw-r--r-- | perllib/FixMyStreet/Roles/Translatable.pm | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Roles/Translatable.pm b/perllib/FixMyStreet/Roles/Translatable.pm index 803cf7a1a..02be78a0e 100644 --- a/perllib/FixMyStreet/Roles/Translatable.pm +++ b/perllib/FixMyStreet/Roles/Translatable.pm @@ -2,6 +2,13 @@ package FixMyStreet::Roles::Translatable; use Moo::Role; +has _translated => (is => 'rw'); + +sub translated { + my $self = shift; + $self->_translated or $self->_translated({}); +} + sub translate_around { my ($orig, $self) = (shift, shift); my $fallback = $self->$orig(@_); @@ -21,6 +28,10 @@ sub _translate { my $schema = $self->result_source->schema; my $table = lc $self->result_source->source_name; my $id = $self->id; + my $lang = $schema->lang || ''; + + my $translated = $self->translated->{$col}{$lang}; + return $translated if $translated; # Deal with the fact problem table has denormalized copy of category string if ($table eq 'problem' && $col eq 'category') { @@ -37,15 +48,16 @@ sub _translate { if (ref $schema) { my $translation = $schema->resultset('Translation')->find({ - lang => $schema->lang, + lang => $lang, tbl => $table, object_id => $id, col => $col }); - return $translation->msgstr if $translation; + $fallback = $translation->msgstr if $translation; } else { warn "Can't use translation on this call to $table.$col"; } + $self->translated->{$col}{$lang} = $fallback; return $fallback; }; |