• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item5537: Wrong TWiki variable used in twiki.pattern.tmpl

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Engine Templates Urgent Closed   patch 4.2.1

Edit Form Data

Reported By:
Applies To:
Current State:
Waiting For:
Target Release:
Released In:


twiki.pattern.tmpl has:
%TMPL:DEF{"htmldoctype"}%<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%LANG%" lang="%LANG%">%TMPL:END%

This is wrong; there is no TWiki variable called 'LANG' (en). You need 'LANGUAGE' (en) instead.

-- TWiki:Main/CrawfordCurrie - 14 Apr 2008

This is the same in twiki.tmpl.

-- TWiki:Main.ArthurClemens - 14 Apr 2008

.... which is also wrong wink

-- TWiki:Main.CrawfordCurrie - 14 Apr 2008

I guess it disappeared when I removed the configure option LANG.

Instead of re-instating this it should be derived from the locale setting so we do not force the user to think about this. And then it also needs to get documented. I missed it because it was not documented.

Let me give a try to fix this in the TWiki code. I know where I removed it.

-- TWiki:Main.KennethLavrsen - 14 Apr 2008

That would explain it. 'LANG' was presumably the locale? Becuase if it was just the language part of the local, that appears to be what LANGUAGE provides.

Might be better to work out a way of deriving {Site}{CharSet} (and therefore %CHARSET) from the locale, because at the moment if the locale is set but {Site}{CharSet} is not, %CHARSET is always iso-8859-1 even if a charset is defined in the locale (e.g. en_GB.utf8)

CHARSET = iso-8859-1 here

-- TWiki:Main.CrawfordCurrie - 14 Apr 2008

For the immediate fix for missing LANG I have a couple of perl related questions.

Why are the $functionTags statements in TWiki.pm defined as subs and not just simple assignments of a value? I would like to understand the reason for this.

The 2nd questions is more a clarification. I think this little code sniplet is correct. Can someone confirm? Yes it works when tested but I want to clarify that I have understood the perl detail correctly.

$functionTags{LANG} = sub { $TWiki::cfg{Site}{Locale} =~ m/^([a-z]+_[a-z]+)/i ; $1 || 'en_US'; };

The sniplet calculates LANG based on Locale and is supposed to default to "en_US" in case the locale does not match the regex.

Before I check in this fix I also want to add some docu of %LANG somewhere. I am not sure we should document this as a Var topic but somewhere in the template documentation where we also have documented some other "semi-secret" twiki vars. Also %CHARSET needs to be docu'ed.

If we can derive CHARSET from Locale (and always assume we can do that) then it would be one less config option to worry about. But can we always assume that the CHARSET is the suffic of Locale? locale -a gives many strange locales such as it_IT.iso885915@euro but I am not sure the iso885915@euro would be understood as valid Charset. For now I will leave the {Site}{Charset} (though the help text could need further improvement in configure).

-- TWiki:Main.KennethLavrsen - 15 Apr 2008

Did a small test setting Locale to "C" and then my $1 || 'en_US'; fails naturally because I cannot predict what is in $1 if the regex does not match so I have to rewrite that part. But my questions above are still open. Why the subs? (just want to understand).

-- TWiki:Main.KennethLavrsen - 15 Apr 2008

Changed the code to this

$functionTags{LANG} = sub { $TWiki::cfg{Site}{Locale} =~ m/^([a-z]+_[a-z]+)/i ? $1 : 'en_US'; };

Now it works as I intended.

And I am pretty sure the code as such is OK. Just the question about "why subs" is open.

Will not check in until tonight when I have have written a little docu

-- TWiki:Main.KennethLavrsen - 15 Apr 2008

Following info from email to twiki-dev mailing list from Crawford Currie - very nice info Crawford

Kenneth, this appears to me to be adding to the confusion, not clarifying it. Right now we have:

%LANGUAGE% - language code e.g. 'en', 'jp', 'dk', taken from the i18n module UNLESS it is defined by the user as a TWiki variable. %LANG% - language code e.g. 'en', 'jp', 'dk', taken from the {Site}{Locale}. Undocumented. %CHARSET% - character set, taken from {Site}{CharSet}.

Here's the logic of all this, as far as I can make sense of it. If nothing else, this may help your documentation efforts.

TWiki gets set up in configure.

* Admin sets {Site}{Locale}. This is used to set the language and charset used by perl via setLocale. * Admin may set {Site}{CharSet}. If set, this is used to set the charset used by CGI and I18N (but not the charset used by perl). * Admin enables one or more languages.

Now, user makes an HTTP request. Let's assume the initial request comes into TWiki with no locale information in it.

* perl assumes the charset set by the value of {Site}{Locale} or defaults to the charset set on the server * CGI is told to use the charset set by {Site}{CharSet} unless it is iso-8859-1, in which case it defaults back to the charset set in perl by the value of {Site}{Locale} (even if that is not iso-8859-1) * TWiki's UTF-8-to-site charset convertors are told to target the charset set by {Site}{CharSet} if it is set, or are no-ops if it is not (different charset converters follow different rules here) * perl assumes the language set by {Site}{Locale} or defaults to the language set on the server * I18N assumes the language set by en or the language set in perl * %LANGUAGE% is either the language set by the user or defaults to the language set in perl * %LANG% is parsed out of the {Site}{Locale} or defaults to 'en_US' (ignoring the language set in perl) * %CHARSET% assumes the charset set by {Site}{CharSet} or defaults to 'iso-8859-1' (ignoring the charset set in perl)

TWiki responds with a view page, which carries locale information in it in the form of the language code (en since your change) and charset iso-8859-1. User then generates a new reuqest based on this page (e.g. they hit the edit button). When TWiki receives this request, these settings are wierd:

* TWiki (and therefore perl and CGI) ignores the charset specified in the request * I18N assumes the language specified in the request (en from the previous request) * %LANGUAGE% is now the language set in the request

Convoluted, or what? I'm amazed that people who use non- iso-8859-1 charsets aren't even more confused by all this. Switching to UTF-8 is the obvious solution, but without that, someone needs to try and make sense of all this and rationalise it.

Note: I just discovered that the I18N module declares a function 'toSiteCharset', which duplicates TWiki::UTF82SiteCharset. More confusion.

end of email from Crawford

-- TWiki:Main.KennethLavrsen - 16 Apr 2008

The whole I18N is complicated.

I restored the LANG to have the same function as before my reduction of config options from 4 to 2 but so it is derived from Locale. With respect to documentation this variable is one of many undocumented variables that are related to skins/templates. I'd rather do an analysis and review that all the missing gets added. I will open a different bug item for this effort and close this one which was the one that needed closing for 4.2.1

-- TWiki:Main.KennethLavrsen - 16 Apr 2008

Cleaned "WaitingFor" field.

-- TWiki:Main.GilmarSantosJr - 10 Aug 2008

Summary Wrong TWiki variable used in twiki.pattern.tmpl
ReportedBy TWiki:Main.CrawfordCurrie

SVN Range TWiki-5.0.0, Sun, 13 Apr 2008, build 16659
AppliesTo Engine
Component Templates
Priority Urgent
CurrentState Closed

Checkins TWikirev:16676 TWikirev:16677
TargetRelease patch
ReleasedIn 4.2.1
Edit | Attach | Watch | Print version | History: r10 < r9 < r8 < r7 < r6 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r10 - 2008-08-10 - GilmarSantosJr
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback