ENHANCEMENT Added i18n::get_lang_from_locale() and i18n::convert_rfc1766()

ENHANCEMENT Using IETF/HTTP compatible "long" language code in SiteTree->MetaTags(). This means the default <meta type="content-language..."> value will be "en-US" instead of "en". The locale can be either set through the Translatable content language, or through i18n::set_locale()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@72367 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-03-02 22:13:30 +00:00
parent 30cef24822
commit 7f4f57c307
2 changed files with 38 additions and 1 deletions

View File

@ -961,6 +961,40 @@ class i18n extends Object {
return $translatableModules;
}
/**
* Returns the "short" language name from a locale,
* e.g. "en_US" would return "en". This conversion
* is determined internally by the {@link $tinymce_lang}
* lookup table. If no match can be found in this lookup,
* the characters before the underscore ("_") are returned.
*
* @todo More generic lookup table, don't rely on tinymce specific conversion
*
* @param string $locale E.g. "en_US"
* @return string Short language code, e.g. "en"
*/
static function get_lang_from_locale($locale) {
if(isset(self::$tinymce_lang[$locale])) {
return self::$tinymce_lang[$locale];
} else {
return preg_replace('/(_|-).*/', '', $locale);
}
}
/**
* Gets a RFC 1766 compatible language code,
* e.g. "en-US".
*
* @see http://www.ietf.org/rfc/rfc1766.txt
* @see http://tools.ietf.org/html/rfc2616#section-3.10
*
* @param string $locale
* @return string
*/
static function convert_rfc1766($locale) {
return str_replace('_','-', $locale);
}
/**
* Given a file name (a php class name, without the .php ext, or a template name, including the .ss extension)
* this helper function determines the module where this file is located

View File

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