Skip to content

Commit

Permalink
Item12482: correct generation of lang and xml:lang attributes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16681 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed May 1, 2013
1 parent 8daaf7f commit 8970f98
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
7 changes: 3 additions & 4 deletions core/data/System/VarLANG.txt
@@ -1,11 +1,10 @@
%META:TOPICINFO{author="ProjectContributor" date="1284886057" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
#VarLANG
---+++ LANG -- the =lang= attribute of generated HTML pages
---+++ LANG -- the language specified by the server locale
This macro is used to generate the =lang= (and =xml:lang=) attribute in generated HTML pages. If ={UseLocale}= is enabled, it is calculated from the [[%SCRIPTURLPATH{"configure"}%#Locale$Internationalisation][configure]] setting of ={Site}{Locale}=. Otherwise it defaults to =en= (English).
* In templates the =lang= attribute is defined like this:
<verbatim class="tml"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%LANG%" lang="%LANG%"></verbatim>
* The value is read from [[%SCRIPTURLPATH{"configure"}%#Locale$Internationalisation][configure]] setting ={Site}{Locale}=
<verbatim><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%LANG%" lang="%LANG%"></verbatim>
* Do not confuse =LANG= with [[VarLANGUAGE][LANGUAGE]]
* Syntax: =%<nop>LANG%=
* Expands to: =%LANG%=
<!--%JQREQUIRE{"chili"}%-->
13 changes: 8 additions & 5 deletions core/data/System/VarLANGUAGE.txt
@@ -1,10 +1,13 @@
%META:TOPICINFO{author="ProjectContributor" date="1231367690" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
#VarLANGUAGE
---+++ LANGUAGE -- current user's language
* Returns the language code for the language used as the current user. This is the language actually used by Foswiki (e.g. in user interface).
* The language is detected from the user's browser, unless some site/web/user/session-defined setting overrides it:
* If the =LANGUAGE= preference is set, it's used as user's language instead of any language detected from the browser.
* Avoid defining =LANGUAGE= at a non per-user way, so each user can choose his/her preferred language.
---+++ LANGUAGE -- language code for the current user
* Returns the language code for the current user. This is the language used by Foswiki to generate the user interface.
* The language is detected from the user's browser, unless some site/web/user/session-defined preference setting overrides it:
* If a =LANGUAGE= preference is explicitly set, this will be used as the user language instead of any language detected from the browser.
* %X% Avoid defining =LANGUAGE= in a non- per-user way, otherwise users will not be able to choose their preferred language.
* Do not confuse =LANGUAGE= with [[VarLANG][LANG]]
* Syntax: =%<nop>LANGUAGE%=
* Expands to: %LANGUAGE%
* Related: [[%IF{"'%INCLUDINGTOPIC%'='Macros'" then="#"}%VarLANGUAGES][LANGUAGES]]

11 changes: 10 additions & 1 deletion core/lib/Foswiki.pm
Expand Up @@ -403,7 +403,16 @@ BEGIN {
};

$macros{LANG} = sub {
$Foswiki::cfg{Site}{Locale} =~ m/^([a-z]+_[a-z]+)/i ? $1 : 'en_US';
my $lang = 'en'; # the default
if ( $Foswiki::cfg{UseLocale}
&& $Foswiki::cfg{Site}{Locale} =~ m/^([a-z]+)(?:_([a-z]+))?/i )
{

# Locale identifiers use _ as the separator in the language, but a minus sign is required
# for HTML (see http://www.ietf.org/rfc/rfc1766.txt)
$lang = $1 . ( $2 ? "-$2" : '' );
}
return $lang;
};

# Set up pre-compiled regexes for use in rendering. All regexes with
Expand Down
14 changes: 7 additions & 7 deletions core/lib/Foswiki.spec
Expand Up @@ -1172,12 +1172,12 @@ $Foswiki::cfg{LanguageFileCompression} = $FALSE;
# international character sets.</p>
# **BOOLEAN**
# Enable the used of {Site}{Locale}
# Enable the use of {Site}{Locale}.
$Foswiki::cfg{UseLocale} = $FALSE;
# **STRING 50 DISPLAY_IF {UseLocale}**
# Site-wide locale - used by Foswiki and external programs such as grep, and to
# specify the character set in which content must be presented for the user's
# specify the character set and language in which content must be presented for the user's
# web browser.
# <br/>
# Note that {Site}{Locale} is ignored unless {UseLocale} is set.
Expand All @@ -1194,14 +1194,14 @@ $Foswiki::cfg{UseLocale} = $FALSE;
# characters.
# <br />
# Examples:<br />
# <code>en_US.ISO-8859-1</code> - Standard US ISO-8859-1 (default)<br />
# <code>en.utf8</code> - English encoded using UTF8<br />
# <code>en_US.ISO-8859-1</code> - US english with ISO-8859-1 encoding<br />
# <code>de_AT.ISO-8859-15</code> - Austria with ISO-8859-15 for Euro<br />
# <code>ru_RU.KOI8-R</code> - Russia<br />
# <code>ru_RU.KOI8-R</code> - Russian encoded using KOI8-R<br />
# <code>ja_JP.eucjp</code> - Japan <br />
# <code>C</code> - English only; no I18N features regarding character
# encodings and external programs.<br />
# UTF-8 locale like en_US.utf8 is still considered experimental
$Foswiki::cfg{Site}{Locale} = 'en_US.ISO-8859-1';
$Foswiki::cfg{Site}{Locale} = 'en.utf8';
# **STRING 50 **
# Set this to match your site locale (from 'locale -a')
Expand All @@ -1217,7 +1217,7 @@ $Foswiki::cfg{Site}{Locale} = 'en_US.ISO-8859-1';
# all internal storage is still in GMT). May be gmtime or servertimeA
# <p>This item is also used by configure to test if your perl supports early dates.
# Foswiki will still work fine on older versions of perl, but wiki applications that use
# dates somewhere prior to 1970 might encounter issues. Configure tests if 1901-01-01
# dates somewhere prior to 1970 might encounter issues. 'configure' tests if 1901-01-01
# is handled by the perl localtime function.
$Foswiki::cfg{DisplayTimeValues} = 'gmtime';
Expand Down

0 comments on commit 8970f98

Please sign in to comment.