From ccd9ecd230cab507b638b5af3aa92a3d7f3e744a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 19 Jan 2010 05:19:19 +0000 Subject: [PATCH] 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 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 --- core/control/ContentController.php | 33 ++++++++++++++++++++++++++---- core/model/SiteTree.php | 6 +----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/core/control/ContentController.php b/core/control/ContentController.php index 0913e8c03..22fbb1f58 100755 --- a/core/control/ContentController.php +++ b/core/control/ContentController.php @@ -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 diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 90b957fa8..70d07b49c 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -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 .= "\n"; - + $this->extend('MetaTags', $tags); return $tags;