BUGFIX: Updated i18n javascript system so that the i18n javascript needs to be explicitly included, so that it doesn't poke its nose in where it's not wanted.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@72563 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-03-06 03:10:24 +00:00
parent 4e28b8d865
commit 8dc652aaa8
14 changed files with 36 additions and 45 deletions

View File

@ -192,12 +192,13 @@ class Requirements {
}
/**
* Automatically includes the necessary lang-files from the module.
* Add i18n files from the given javascript directory.
* @param $langDir The javascript lang directory, relative to the site root, e.g., 'sapphire/javascript/lang'
*
* See {@link Requirements_Backend::process_i18n_javascript()} for more info.
* See {@link Requirements_Backend::add_i18n_javascript()} for more information.
*/
protected static function process_i18n_javascript() {
return self::backend()->process_i18n_javascript();
public static function add_i18n_javascript($langDir) {
return self::backend()->add_i18n_javascript($langDir);
}
/**
@ -551,7 +552,6 @@ class Requirements_Backend {
$jsRequirements = '';
// Combine files - updates $this->javascript and $this->css
$this->process_i18n_javascript();
$this->process_combined_files();
foreach(array_diff_key($this->javascript,$this->blocked) as $file => $dummy) {
@ -638,41 +638,25 @@ class Requirements_Backend {
$response->addHeader('X-Include-CSS', implode(',', $cssRequirements));
}
/**
* Automatically includes the necessary lang-files from the module
* according to the locale set in {@link i18n::$current_locale}.
* Assumes that a subfolder /javascript exists relative to the included
* javascript file, with a file named after the locale -
* so usually <mymodule>/javascript/lang/en_US.js.
/**
* Add i18n files from the given javascript directory. Sapphire expects that the given directory
* will contain a number of java script files named by language: en_US.js, de_DE.js, etc.
* @param $langDir The javascript lang directory, relative to the site root, e.g., 'sapphire/javascript/lang'
*/
protected function process_i18n_javascript() {
// ensure to include the i18n base library
if(
count(array_diff_key($this->javascript,$this->blocked))
&& !isset($this->javascript[SAPPHIRE_DIR . '/javascript/i18n.js'])
) {
$this->javascript[THIRDPARTY_DIR . '/prototype.js'] = true;
$this->javascript[SAPPHIRE_DIR . '/javascript/i18n.js'] = true;
}
// include the specific locale and the master locale for each module
foreach(array_diff_key($this->javascript,$this->blocked) as $file => $dummy) {
if(preg_match('/^http[s]?/', $file)) continue;
$absolutePath = Director::baseFolder() . '/' . $file;
$absoluteLangPath = dirname($absolutePath) . '/lang/' . i18n::get_locale() . '.js';
$absoluteDefaultLangPath = dirname($absolutePath) . '/lang/' . i18n::default_locale() . '.js';
foreach(array($absoluteDefaultLangPath, $absoluteLangPath) as $path) {
if(Director::fileExists($path)) {
$langFile = Director::makeRelative($path);
// Remove rogue leading slashes from Director::makeRelative()
$langFile = preg_replace('/^\//', '', $langFile);
$this->javascript[$langFile] = true;
}
}
}
public function add_i18n_javascript($langDir) {
// Include i18n.js even if no languages are found. The fact that
// add_i18n_javascript() was called indicates that the methods in
// here are needed.
$this->javascript(SAPPHIRE_DIR . '/javascript/i18n.js');
}
if(substr($langDir,-1) != '/') $langDir .= '/';
$defaultLangPath = $langDir . i18n::default_locale() . '.js';
$langPath = $langDir . i18n::get_locale() . '.js';
foreach(array($defaultLangPath, $langPath) as $path) {
if(Director::fileExists($path)) $this->javascript($path);
}
}
/**
* Finds the path for specified file.

View File

@ -1102,6 +1102,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
function getCMSFields() {
require_once("forms/Form.php");
Requirements::javascript(CMS_DIR . "/javascript/SitetreeAccess.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/UpdateURL.js');
// Status / message

View File

@ -29,6 +29,7 @@ class AjaxUniqueTextField extends TextField {
}
function Field() {
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/UniqueFields.js");
$this->jsValidation();

View File

@ -200,6 +200,7 @@ class ComplexTableField extends TableListField {
Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js");
Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableListField.js');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/ComplexTableField.js");
Requirements::css(THIRDPARTY_DIR . "/greybox/greybox.css");
@ -960,6 +961,7 @@ class ComplexTableField_Popup extends Form {
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/scriptaculous.js");
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/controls.js");
Requirements::javascript(THIRDPARTY_DIR . "/layout_helpers.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain.js");
Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain_right.js");
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TableField.js");

View File

@ -23,7 +23,7 @@ class HasManyComplexTableField extends ComplexTableField {
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/HasManyFileField.js");
Requirements::javascript(SAPPHIRE_DIR . '/javascript/RelationComplexTableField.js');
Requirements::css(SAPPHIRE_DIR . '/css/HasManyFileField.css');

View File

@ -15,6 +15,7 @@ class RestrictedTextField extends TextField {
}
function Field() {
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript( SAPPHIRE_DIR . '/javascript/UniqueFields.js' );
if($this->maxLength){

View File

@ -32,6 +32,7 @@ class ScaffoldingComplexTableField_Popup extends Form {
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/scriptaculous.js");
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/controls.js");
Requirements::javascript(THIRDPARTY_DIR . "/layout_helpers.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain.js");
Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain_right.js");
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TableField.js");

View File

@ -114,7 +114,7 @@ class TableField extends TableListField {
}
parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableField.js');
}

View File

@ -247,7 +247,7 @@ class TableListField extends FormField {
Requirements::javascript(THIRDPARTY_DIR . '/behaviour.js');
Requirements::javascript(THIRDPARTY_DIR . '/prototype_improvements.js');
Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableListField.js');
Requirements::css(SAPPHIRE_DIR . '/css/TableListField.css');
}

View File

@ -37,6 +37,7 @@ class TreeDropdownField extends FormField {
Requirements::css(SAPPHIRE_DIR . '/css/TreeDropdownField.css');
Requirements::javascript(THIRDPARTY_DIR . "/tree/tree.js");
Requirements::css(THIRDPARTY_DIR . "/tree/tree.css");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");
if($this->value) {

View File

@ -29,6 +29,7 @@ class TreeMultiselectField extends TreeDropdownField {
function Field() {
$value = '';
$itemList = '';
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");
$items = $this->getItems();

View File

@ -13,7 +13,7 @@ class TreeSelectorField extends FormField {
}
function Field() {
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");
$fieldName = $this->name;

View File

@ -24,7 +24,7 @@ class UniqueTextField extends TextField {
}
function Field() {
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/UniqueFields.js");
/*

View File

@ -153,8 +153,7 @@ abstract class Validator extends Object {
Requirements::javascript(THIRDPARTY_DIR . "/prototype.js");
Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js");
//Requirements::add_i18n_javascript(SAPPHIRE_DIR);
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/Validator.js");
$code = $this->javascript();