OSDN Git Service

Added LoveLetter's attribute 'language'.
authorTaku Amano <taku@toi-planning.net>
Tue, 5 May 2009 16:54:02 +0000 (01:54 +0900)
committerTaku Amano <taku@toi-planning.net>
Tue, 5 May 2009 16:54:02 +0000 (01:54 +0900)
config.yaml
lib/Lovers/App/LoveLetter.pm
lib/Lovers/LoveLetter.pm

index 7efd319..86830b6 100644 (file)
@@ -33,7 +33,7 @@ doc_link: http://mt-acme.sourceforge.jp/lovers/
 l10n_class: Lovers::L10N
 
 # objects
-schema_version: 2
+schema_version: 3
 object_types:
     love_letter: Lovers::LoveLetter
 
index de113a4..f88df08 100644 (file)
@@ -77,6 +77,7 @@ sub _hdlr_love_letter {
                author_id => $entry ? $entry->author_id : $tmpl->modified_by,
                from => $args->{'from'} || '',
                to => $args->{'to'} || '',
+               language => $args->{'language'} || '',
        });
 
        if ((! $obj->sent_on || $obj->sent_on =~ m/^0/) && $obj->to) {
@@ -101,6 +102,13 @@ sub _hdlr_love_letter {
                        $param->{'permalink'} =~ s/#.*//;
                        $param->{'permalink'} .= '#password'
                }
+
+               my $current_language = undef;
+               if (my $lang = $param->{'language'}) {
+                       $current_language = MT->current_language;
+                       MT->set_language($lang);
+               }
+
                my $tmpl = $plugin->load_tmpl('mail_love_letter.tmpl');
                my $body = MT->translate_templatized(
                        $tmpl->output($param)
@@ -116,6 +124,10 @@ sub _hdlr_love_letter {
                my $charset = $cfg->MailEncoding || $cfg->PublishCharset;
                $head{'Content-Type'} = qq(text/plain; charset="$charset");
 
+               if ($current_language) {
+                       MT->set_language($current_language);
+               }
+
                require MT::Mail;
                MT::Mail->send( \%head, $body )
                        or return $app->error( MT::Mail->errstr() );
@@ -133,6 +145,12 @@ sub _hdlr_love_letter {
     my $builder = $ctx->stash('builder');
     my $tokens = $ctx->stash('tokens');
 
+       my $current_language = undef;
+       if (my $lang = $args->{'language'}) {
+               $current_language = MT->current_language;
+               MT->set_language($lang);
+       }
+
     defined($res = $builder->build($ctx, $tokens, $cond))
         or return $ctx->error( $builder->errstr );
 
@@ -358,6 +376,10 @@ $res
 </form>
 __EOF__
 
+       if ($current_language) {
+               MT->set_language($current_language);
+       }
+
     $res;
 }
 
@@ -428,6 +450,12 @@ __MSG__
        $param->{'message'} = $app->param('response') || '';
        $param->{'ok'} = $app->param('ok') ? 1 : 0;
 
+       my $current_language = undef;
+       if (my $lang = $param->{'language'}) {
+               $current_language = MT->current_language;
+               MT->set_language($lang);
+       }
+
        my $tmpl = $plugin->load_tmpl('mail_response.tmpl');
        my $body = MT->translate_templatized(
                $tmpl->output($param)
@@ -443,6 +471,10 @@ __MSG__
        my $charset = $cfg->MailEncoding || $cfg->PublishCharset;
        $head{'Content-Type'} = qq(text/plain; charset="$charset");
 
+       if ($current_language) {
+               MT->set_language($current_language);
+       }
+
        require MT::Mail;
        MT::Mail->send( \%head, $body )
                or return $app->error( MT::Mail->errstr() );
index f6007b1..f31fb99 100644 (file)
@@ -35,6 +35,7 @@ __PACKAGE__->install_properties({
 
         'from' => 'string(255)',
         'to' => 'string(255)',
+        'language' => 'string(10)',
 
         'sent_on' => 'datetime',
     },