ChooseTemplateByUserLang: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
(No difference)

Latest revision as of 16:03, 6 April 2016

Original ML message:

Ok, so what I needed was to use different template depending on the uesr's
language. So I modified lib/RT/Action/SendEmail.pm slightly.
First it checks the language from user's profile. If, for example, it's
Japanese, then it replaces current template with the template which name has
" (ja)" at the end. So, instead of, for example, "Autoreply" template, it
will try to find template "Autoreply (ja)".

--Dimitry Faynerman

Next code is [=RT/Action/SendEmail_Local.pm] which do same in a more clear way:

sub TemplateObj
{
  my $self = shift;
  my $obj = $self->SUPER::TemplateObj;
  return unless( $obj );

  # Use lang template (if exists) according to user's language
  my $UserObj = RT::User->new( $RT::SystemUser );
  $UserObj->Load( $self->TicketObj->Requestors->UserMembersObj->First->Id );

  if( $UserObj->Lang && $UserObj->Lang ne 'en' ) {
    my $oldTmplId = $obj->Id;
    $obj->Load( $obj->Name . " (" . $UserObj->Lang . ")" );
    unless( $obj->Id ) {
      $obj->Load( $oldTmplId );
    }
  }

  return $obj;
}

1;

Wish, idea and orginal code by DimitryFaynerman. Code refactoring RuslanZakirov.

See also: ForkTemplate and CleanlyCustomizeRT