diff --git a/forms/HasManyComplexTableField.php b/forms/HasManyComplexTableField.php index 10927eb7e..e2380c317 100644 --- a/forms/HasManyComplexTableField.php +++ b/forms/HasManyComplexTableField.php @@ -27,6 +27,9 @@ class HasManyComplexTableField extends ComplexTableField { $this->Markable = true; $this->joinField = $this->getParentIdName($this->controller->ClassName, $this->sourceClass); + + Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js"); + Requirements::javascript(SAPPHIRE_DIR . "/javascript/HasManyFileField.js"); } function getQuery($limitClause = null) { diff --git a/forms/TableField.php b/forms/TableField.php index 2a9da2080..3b6779814 100644 --- a/forms/TableField.php +++ b/forms/TableField.php @@ -114,6 +114,7 @@ class TableField extends TableListField { } parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin); + Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js"); Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableField.js'); } diff --git a/forms/TableListField.php b/forms/TableListField.php index 0d88729a1..b16a96896 100755 --- a/forms/TableListField.php +++ b/forms/TableListField.php @@ -243,6 +243,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::javascript(SAPPHIRE_DIR . '/javascript/TableListField.js'); Requirements::css(SAPPHIRE_DIR . '/css/TableListField.css'); } diff --git a/forms/TreeSelectorField.php b/forms/TreeSelectorField.php index 7bc4f63af..becf70a25 100755 --- a/forms/TreeSelectorField.php +++ b/forms/TreeSelectorField.php @@ -13,6 +13,7 @@ class TreeSelectorField extends FormField { } function Field() { + Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js"); Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js"); $fieldName = $this->name; diff --git a/forms/UniqueTextField.php b/forms/UniqueTextField.php index 8b097be12..118f0c4ed 100755 --- a/forms/UniqueTextField.php +++ b/forms/UniqueTextField.php @@ -23,6 +23,7 @@ class UniqueTextField extends TextField { } function Field() { + Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js"); Requirements::javascript(SAPPHIRE_DIR . "/javascript/UniqueFields.js"); /* diff --git a/forms/Validator.php b/forms/Validator.php index bea105241..2e1cdb225 100755 --- a/forms/Validator.php +++ b/forms/Validator.php @@ -113,6 +113,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::javascript(SAPPHIRE_DIR . "/javascript/i18n.js"); Requirements::javascript(SAPPHIRE_DIR . "/javascript/Validator.js"); $code = $this->javascript(); diff --git a/javascript/HasManyFileField.js b/javascript/HasManyFileField.js index aba58d145..b8b223fae 100644 --- a/javascript/HasManyFileField.js +++ b/javascript/HasManyFileField.js @@ -82,12 +82,20 @@ HasManyFileFieldUploadButton.prototype = { this.upload.browse(); }, - uploadFileQueuedCallback: function(file,queueLength) { - this.parentNode.parentNode.uploadMessage.innerHTML = "Uploading..." + this.upload.getFilesToUpload(); + uploadFileQueuedCallback: function(file,queueLength) { + var message = ss.i18n.sprintf( + ss.i18n._t('HASMANYFILEFIELD.UPLOADING'), + this.upload.getFilesToUpload() + ); + this.parentNode.parentNode.uploadMessage.innerHTML = message; }, uploadFileCompleteCallback: function(file,serverData) { - this.parentNode.parentNode.uploadMessage.innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload(); + var message = ss.i18n.sprintf( + ss.i18n._t('HASMANYFILEFIELD.UPLOADING'), + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload() + ); + this.parentNode.parentNode.uploadMessage.innerHTML = message; idregex = /\/\* IDs: ([0-9,]+) \*\//; ids = serverData.match(idregex); fileid = ids[1]; @@ -123,7 +131,7 @@ HasManyFileFieldUploadButton.prototype = { li.appendChild(removelink); list.appendChild(li); - HasManyFileFieldRemoveButton.applyTo(removelink); + HasManyFileFieldRemoveButton.applyTo(removelink); }, uploadQueueCompleteCallback: function() { diff --git a/javascript/TableField.js b/javascript/TableField.js index 13f5d27a4..30d546534 100755 --- a/javascript/TableField.js +++ b/javascript/TableField.js @@ -20,7 +20,6 @@ Effect.FadeOut = function(element,callback) { TableField = Class.create(); Object.extend(TableField.prototype,{ - deleteConfirmMessage: "Are you sure you want to delete this record?", newRowID: 1, /** @@ -77,7 +76,7 @@ Object.extend(TableField.prototype,{ } // TODO ajaxErrorHandler and loading-image are dependent on cms, but formfield is in sapphire - var confirmed = (this.deleteConfirmMessage != undefined) ? confirm(this.deleteConfirmMessage) : true; + var confirmed = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE')); if(confirmed){ img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work new Ajax.Request( diff --git a/javascript/TableListField.js b/javascript/TableListField.js index 38208ce34..4be78a361 100755 --- a/javascript/TableListField.js +++ b/javascript/TableListField.js @@ -1,8 +1,6 @@ TableListField = Class.create(); TableListField.prototype = { - deleteConfirmMessage: "Are you sure you want to delete this record?", - errorMessage: "Error talking to server", initialize: function() { @@ -81,7 +79,7 @@ TableListField.prototype = { var row = Event.findElement(e,"tr"); // TODO ajaxErrorHandler and loading-image are dependent on cms, but formfield is in sapphire - var confirmed = (this.deleteConfirmMessage != undefined) ? confirm(this.deleteConfirmMessage) : true; + var confirmed = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE')); if(confirmed) { img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work diff --git a/javascript/TreeSelectorField.js b/javascript/TreeSelectorField.js index 0ec79d640..dce02f6f8 100755 --- a/javascript/TreeSelectorField.js +++ b/javascript/TreeSelectorField.js @@ -58,7 +58,7 @@ TreeDropdownField.prototype = { } this.itemTree.className = 'tree_holder'; - this.itemTree.innerHTML = "loading..."; + this.itemTree.innerHTML = ss.i18n._t('LOADING'); this.appendChild(this.itemTree); } }, @@ -177,7 +177,7 @@ TreeDropdownField.prototype = { ajaxExpansion: function() { this.addNodeClass('loading'); var ul = this.treeNodeHolder(); - ul.innerHTML = 'loading...'; + ul.innerHTML = ss.i18n._t('LOADING'); var ajaxURL = this.options.dropdownField.helperURLBase() + 'getsubtree?&SubtreeRootID=' + this.getIdx(); ajaxURL += $('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''; diff --git a/javascript/UniqueFields.js b/javascript/UniqueFields.js index 7649a3a29..ea7cec083 100755 --- a/javascript/UniqueFields.js +++ b/javascript/UniqueFields.js @@ -6,7 +6,11 @@ UniqueFormField.prototype = { if( this.restrictedValues[suggested] || suggested == null ) { suggested = this.suggestNewValue(); - statusMessage("Changed value to " + suggested + ". " + this.restrictedMessage); + statusMessage(ss.i18n.sprintf( + ss.i18n._t('UNIQUEFIELD.SUGGESTED'), + suggested, + this.restrictedMessage + )); this.value = suggested; } }, @@ -108,16 +112,20 @@ UniqueRestrictedTextField.prototype = { if( suggested == null || suggested.length == 0 || suggestedValue || suggested.match( this.charRegex ) ) { var message; if( suggested == null ) - message = 'You will need to enter a new value for this field'; + message = ss.i18n._t('UNIQUEFIELD.ENTERNEWVALUE'); else if( suggested.length == 0 ) - message = 'This field cannot be left empty'; + message = ss.i18n._t('UNIQUEFIELD.CANNOTLEAVEEMPTY'); else if( suggestedValue ) message = this.restrictedMessage; else message = this.charMessage; suggested = this.suggestNewValue(); - statusMessage("Changed value to " + suggested + ". " + message); + statusMessage(ss.i18n.sprintf( + ss.i18n._t('UNIQUEFIELD.SUGGESTED'), + suggested, + message + )); } this.value = suggested; @@ -143,7 +151,10 @@ RestrictedTextField.prototype = { for( var index = 0; index < this.restrictedChars.length; index++ ) { if( lastChar == this.restrictedChars.charAt(index) ) { - alert( "The character '" + lastChar + "' cannot be used in this field" ); + alert(ss.i18n.sprintf( + ss.i18n._t('RESTRICTEDTEXTFIELD.CHARCANTBEUSED'), + lastChar + )); this.value = this.value.substring( 0, this.value.length - 1 ); } } diff --git a/javascript/UpdateURL.js b/javascript/UpdateURL.js index 8c069b25b..40c03f0da 100755 --- a/javascript/UpdateURL.js +++ b/javascript/UpdateURL.js @@ -10,9 +10,19 @@ Behaviour.register({ var urlSegmentField = $('Form_EditForm_URLSegment'); var newSuggestion = urlSegmentField.suggestNewValue( this.value.toLowerCase() ); var isNew = urlSegmentField.value.indexOf("new") == 0; + var confirmMessage = ss.i18n.sprintf( + ss.i18n._t('UPDATEURL.CONFIRM'), + newSuggestion, + urlSegmentField.value + ); - if( newSuggestion == urlSegmentField.value || isNew || confirm( 'Would you like me to change the URL to:\n\n' + newSuggestion + '/\n\nClick Ok to change the URL, click Cancel to leave it as:\n\n' + urlSegmentField.value ) ) + if( + newSuggestion == urlSegmentField.value + || isNew + || confirm(confirmMessage) + ) { urlSegmentField.value = newSuggestion; + } // If you type in Page name, the Navigation Label and Meta Title should automatically update the first time // @todo: Change file name from UpdateURL to something more geneneric since we now do more than update the URL. if($('Form_EditForm_MetaTitle') && $('Form_EditForm_MenuTitle').value.indexOf("New") == 0 ) { diff --git a/javascript/Validator.js b/javascript/Validator.js index bdc887a8f..51664c971 100755 --- a/javascript/Validator.js +++ b/javascript/Validator.js @@ -146,7 +146,7 @@ function require(fieldName,cachedError) { fieldlabel = "this field"; } - var errorMessage = "Please fill out \"$FieldLabel\", it is required." + var errorMessage = ss.i18n.printf(ss.i18n._t('VALIDATOR.FIELDREQUIRED'), fieldLabel); if(baseEl.requiredErrorMsg) errorMessage = baseEl.requiredErrorMsg; else if(_CURRENT_FORM.requiredErrorMsg) errorMessage = _CURRENT_FORM.requiredErrorMsg; diff --git a/javascript/lang/de_DE.js b/javascript/lang/de_DE.js new file mode 100644 index 000000000..0d076f800 --- /dev/null +++ b/javascript/lang/de_DE.js @@ -0,0 +1,7 @@ +if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') { + console.error('Class ss.i18n not defined'); +} else { + ss.i18n.addDictionary('de_DE', { + 'VALIDATOR.FIELDREQUIRED': '"%s" wird benötigt', + }); +} \ No newline at end of file diff --git a/javascript/lang/en_US.js b/javascript/lang/en_US.js new file mode 100644 index 000000000..f476e229a --- /dev/null +++ b/javascript/lang/en_US.js @@ -0,0 +1,15 @@ +if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') { + console.error('Class ss.i18n not defined'); +} else { + ss.i18n.addDictionary('en_US', { + 'VALIDATOR.FIELDREQUIRED': 'Please fill out "%s", it is required.', + 'HASMANYFILEFIELD.UPLOADING': 'Uploading... %s', + 'TABLEFIELD.DELETECONFIRMMESSAGE': 'Are you sure you want to delete this record?', + 'LOADING': 'loading...', + 'UNIQUEFIELD.SUGGESTED': '"Changed value to %s %s', + 'UNIQUEFIELD.ENTERNEWVALUE': 'You will need to enter a new value for this field', + 'UNIQUEFIELD.CANNOTLEAVEEMPTY': 'This field cannot be left empty', + 'RESTRICTEDTEXTFIELD.CHARCANTBEUSED': "The character '%s' cannot be used in this field", + 'UPDATEURL.CONFIRM': 'Would you like me to change the URL to:\n\n%s/\n\nClick Ok to change the URL, click Cancel to leave it as:\n\n%s' + }); +} \ No newline at end of file