Character set support

pierre-vigier edited this page Sep 8, 2016 · 4 revisions

Character Set Support

Generally, it is good that you always use UTF-8 as character set, but you can change character set by Mojolicious::Plugin::Charset.

    plugin charset => {charset => 'Shift-JIS'};

String in request parameter is converted from specified character set to Perl internal string.

    #  String in request parameter
    Shift-JIS -> "Perl internal string"

In HTTP responce, Content-Type header contains specified character set.

    Content-Type: text/html; charset=Shift-JIS

You remember to write "http-equiv" in HTML file and save it as specified character set

        <meta http-equiv="Content-Type" content="text/html; charset=Shift-JIS" />

Mojolicious version 7 onwards

From Mojolicious version 6 onwards, the Mojolicious::Plugin::Charset plugin has been removed. Instead of the plugin, you can setup charset manually, in a Mojolicious Lite application:

    app->types->type(html => 'text/html;charset=Shift_JIS');
      before_dispatch => sub {