mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Using ss.i18n in all sapphire form fields with clientside language strings
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63567 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7c0b69ea34
commit
6bd34d3e53
@ -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) {
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -23,6 +23,7 @@ class UniqueTextField extends TextField {
|
||||
}
|
||||
|
||||
function Field() {
|
||||
Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js");
|
||||
Requirements::javascript(SAPPHIRE_DIR . "/javascript/UniqueFields.js");
|
||||
|
||||
/*
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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 : '';
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
@ -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 ) {
|
||||
|
@ -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;
|
||||
|
||||
|
7
javascript/lang/de_DE.js
Normal file
7
javascript/lang/de_DE.js
Normal file
@ -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',
|
||||
});
|
||||
}
|
15
javascript/lang/en_US.js
Normal file
15
javascript/lang/en_US.js
Normal file
@ -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'
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user