Not a developer? Go to MovableType.com

Documentation

Everything UTF8

In Movable Type 5, all internal character strings are processed with utf8. Usually, MT performs the appropriate Encode/Decode for users’ input or database input/output, so there is no need to consider this on the plugin.

MT performs automatic Encode/Decode in the following circumstances:

  • When saving/loading data saved to MT::Object.
  • Database queries.
  • File input/output with MT::FileMgr except for upload mode.( Including blog republishing with MT::WeblogPublisher)
  • When running Serialize/unserialize with MT::Serialize.
    Note: In MT5, you cannot serialize data construction that includes binary values.
  • Dynamic output with MT::App::print.

However, in the following cases, you must explicitly process the appropriate Encode/Decode:

  • When communicating with an external network.
  • File input/output without MT::FileMgr
  • When saving values to columns declared in MT::Object blob format.

Also, if utf8 character strings are in L10N dictionary or similar source codes, please specify a utf8 pragma and all other necessary settings. In order to maintain backward plugin compatibility, Movable Type 5.0 runs a compulsory Decode for L10N*.pm files. But this process might be ceased in the future.

Code Examples

MT Tag handler

You can rely on Movable Type 5 to handle encoding its output.

sub _hdlr_my_tag {
   my ( $ctx, $args ) = @_;
   my $obj = MT::Entry->load(
       $args->{id});
   my $data = $obj->text;

   # do something...

   # MT does encode based on the PublishCharset
   return $data;
}

You needed to encode by yourself at Movable Type 4.x.

 return MT::I18N::encode_text( $data, 'utf-8' );

Receiving data from web services

sub _hdlr_my_tag {
   my ( $ctx, $args ) = @_;
   my $data;

   # When to receive data from web services,
   # plugin should decode as UTF-8-flagged
   return Encode::decode_utf8( $data );
}

Writing data to the external file without MT::FileMgr.

sub _hdlr_output_file {
   my ( $entry ) = @_;

   # Plugin should encode
   my $charset = 'utf-8';
   my $title = Encode::encode($charset, $entry->title);

   my $fh;
   open $fh ">output.txt" or die;
   print $fh <<EOT;
<?xml version="1.0" ?>
<entry>$title</entry>
EOT
   close $fh;
   return 1;
}
Back

1 Comment

Carl

Carl on August 30, 2012, 4:38 a.m. Reply

So, with the new version of Moveable type I will not do this line - return MT::I18N::encode_text( $data, ‘utf-8’ );

Leave a Comment