archive_me1Add my vote for this tag create new tag
, view all tags

Proposed: Per web charset selection

For sites that maintain content in more then one language it is useful to have a per-web selection of the charset. This is for the meta http-equiv setting, for example:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

This was suggested by ColasNahaboo in Support.DonotChangeMyLanguageScript

Proposed change in TWiki::writeHeaderFull:

sub writeHeaderFull
    my( $query, $pageType, $contentType, $contentLength ) = @_;

    # Handle Edit pages - future versions will extend to caching
    # of other types of page, with expiry time driven by page type.
    my( $pluginHeaders, $coreHeaders );

    my $charSet = TWiki::Prefs::getPreferencesValue( "CHARSET" ) || $siteCharset;
    $contentType .= "; charset=$charSet";

    if ($pageType eq 'edit') {
        # Get time now in HTTP header format
        my $lastModifiedString = formatTime(time, '\$http', "gmtime");

Above code is not tested. Potential issues/questions:

  • Does content length change? That is, $contentLength needs to be adjusted?
  • Colas' patch attached to Support.DonotChangeMyLanguageScript changes the global $siteCharset in the writeHeaderFull function. Is that what is needed, or do we need a temporary setting indicated above?
  • TWiki allows a per page setting of variables. Does charset work also?

-- PeterThoeny - 19 Jul 2004

It's worth noting that per-web or even per-page site charsets are a dangerous idea in general, and should only be used as patches for sites that really need this, not in the TWiki core - what happens if someone renames a topic from one web to another? It's not possible in general to transcode one character encoding into another one (e.g. EUC-JP into ISO-8859-2). It's better to just make UTF-8 work and use it as the one character encoding for all webs. See also my comments near top of InternationalisationEnhancements.

Incidentally, CHARSET can be defined within the TWiki.cfg as part of $siteLocale, and even overridden specifically if the locale charset doesn't match what the browser supports - see the comments in the beta release TWiki.cfg. Setting this within environment variables is not necessary and will be system specific.

Also, the META header is overridden by the HTTP header, so it's important to set both of these. The current code does do this.

-- RichardDonkin - 21 Jul 2004

Good points Richard. KISS

-- PeterThoeny - 22 Jul 2004

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2004-07-22 - PeterThoeny
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.