API CHANGE Deprecated ContentController->LangAttributes(). Use ContentLocale() instead and write attribute names suitable to XHTML/HTML templates directly in the template.

ENHANCEMENT Added ContentController->ContentLocale() to allow XHTML/HTML specific lang= attribute settings in custom template code (see #4858). Removed <meta http-equiv="Content-Language"...> tag in SiteTree->MetaTags().
ENHANCEMENT Updated blackcandy theme to use new $ContentLocale attribute to set the locale of the current page (in Page.ss)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97207 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-01-19 05:19:19 +00:00 committed by Sam Minnee
parent 3b9eaa88fe
commit ccd9ecd230
2 changed files with 30 additions and 9 deletions

View File

@ -406,13 +406,38 @@ HTML;
}
/**
* Returns the xml:lang and lang attributes
* Returns the xml:lang and lang attributes.
*
* @deprecated 2.5 Use ContentLocale() instead and write attribute names suitable to XHTML/HTML
* templates directly in the template.
*/
function LangAttributes() {
$lang = Translatable::get_current_locale();
return "xml:lang=\"$lang\" lang=\"$lang\"";
$locale = $this->ContentLocale();
return "xml:lang=\"$locale\" lang=\"$locale\"";
}
/**
* Returns an RFC1766 compliant locale string, e.g. 'fr-CA'.
* Inspects the associated {@link dataRecord} for a {@link SiteTree->Locale} value if present,
* and falls back to {@link Translatable::get_current_locale()} or {@link i18n::default_locale()},
* depending if Translatable is enabled.
*
* Suitable for insertion into lang= and xml:lang=
* attributes in HTML or XHTML output.
*
* @return string
*/
function ContentLocale() {
if($this->dataRecord && $this->dataRecord->hasExtension('Translatable')) {
$locale = $this->dataRecord->Locale;
} elseif(Object::has_extension('SiteTree', 'Translatable')) {
$locale = Translatable::get_current_locale();
} else {
$locale = i18n::default_locale();
}
return i18n::convert_rfc1766($locale);
}
/**
* This action is called by the installation system

View File

@ -1177,11 +1177,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($this->ExtraMeta) {
$tags .= $this->ExtraMeta . "\n";
}
// get the "long" lang name suitable for the HTTP content-language flag (with hyphens instead of underscores)
$currentLang = ($this->hasExtension('Translatable')) ? Translatable::get_current_locale() : i18n::get_locale();
$tags .= "<meta http-equiv=\"Content-Language\" content=\"". i18n::convert_rfc1766($currentLang) ."\"/>\n";
$this->extend('MetaTags', $tags);
return $tags;