Skip to content

Commit f4a792b

Browse files
committed
Fixed#287 and #302.
Added Unit tests for the recent Language Support implementation.
1 parent d48c105 commit f4a792b

File tree

8 files changed

+258
-6
lines changed

8 files changed

+258
-6
lines changed

src/main/java/gwt/material/design/addins/client/fileuploader/MaterialFileUploader.java

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import gwt.material.design.client.MaterialDesignBase;
3939
import gwt.material.design.client.base.JsLoader;
4040
import gwt.material.design.client.base.MaterialWidget;
41-
import gwt.material.design.client.base.mixin.WavesMixin;
4241
import gwt.material.design.client.constants.CssName;
4342
import gwt.material.design.client.constants.Display;
4443
import gwt.material.design.client.events.*;
@@ -503,6 +502,116 @@ public MaterialUploadPreview getUploadPreview() {
503502
return uploadPreview;
504503
}
505504

505+
public String getDictDefaultMessage() {
506+
return options.dictDefaultMessage;
507+
}
508+
509+
/**
510+
* Defaults to "Drop files here to upload"
511+
*/
512+
public void setDictDefaultMessage(String dictDefaultMessage) {
513+
options.dictDefaultMessage = dictDefaultMessage;
514+
}
515+
516+
public String getDictFallbackMessage() {
517+
return options.dictFallbackMessage;
518+
}
519+
520+
/**
521+
* Defaults to "Your browser does not support drag'n'drop file uploads."\
522+
*/
523+
public void setDictFallbackMessage(String dictFallbackMessage) {
524+
options.dictFallbackMessage = dictFallbackMessage;
525+
}
526+
527+
public String getDictFallbackText() {
528+
return options.dictFallbackText;
529+
}
530+
531+
/**
532+
* Defaults to "Please use the fallback form below to upload your files like in the olden days."
533+
*/
534+
public void setDictFallbackText(String dictFallbackText) {
535+
options.dictFallbackText = dictFallbackText;
536+
}
537+
538+
public String getDictFileTooBig() {
539+
return options.dictFileTooBig;
540+
}
541+
542+
/**
543+
* Defaults to "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB."
544+
*/
545+
public void setDictFileTooBig(String dictFileTooBig) {
546+
options.dictFileTooBig = dictFileTooBig;
547+
}
548+
549+
public String getDictInvalidFileType() {
550+
return options.dictInvalidFileType;
551+
}
552+
553+
/**
554+
* Defaults to "You can't upload files of this type."
555+
*/
556+
public void setDictInvalidFileType(String dictInvalidFileType) {
557+
options.dictInvalidFileType = dictInvalidFileType;
558+
}
559+
560+
public String getDictResponseError() {
561+
return options.dictResponseError;
562+
}
563+
564+
/**
565+
* Defaults to "Server responded with {{statusCode}} code."
566+
*/
567+
public void setDictResponseError(String dictResponseError) {
568+
options.dictResponseError = dictResponseError;
569+
}
570+
571+
public String getDictCancelUpload() {
572+
return options.dictCancelUpload;
573+
}
574+
575+
/**
576+
* Defaults to "Cancel upload"
577+
*/
578+
public void setDictCancelUpload(String dictCancelUpload) {
579+
options.dictCancelUpload = dictCancelUpload;
580+
}
581+
582+
public String getDictCancelUploadConfirmation() {
583+
return options.dictCancelUploadConfirmation;
584+
}
585+
586+
/**
587+
* Defaults to "Are you sure you want to cancel this upload?"
588+
*/
589+
public void setDictCancelUploadConfirmation(String dictCancelUploadConfirmation) {
590+
options.dictCancelUploadConfirmation = dictCancelUploadConfirmation;
591+
}
592+
593+
public String getDictRemoveFile() {
594+
return options.dictRemoveFile;
595+
}
596+
597+
/**
598+
* Defaults to "Remove file"
599+
*/
600+
public void setDictRemoveFile(String dictRemoveFile) {
601+
options.dictRemoveFile = dictRemoveFile;
602+
}
603+
604+
public String getDictMaxFilesExceeded() {
605+
return options.dictMaxFilesExceeded;
606+
}
607+
608+
/**
609+
* Defaults to "You can not upload any more files."
610+
*/
611+
public void setDictMaxFilesExceeded(String dictMaxFilesExceeded) {
612+
options.dictMaxFilesExceeded = dictMaxFilesExceeded;
613+
}
614+
506615
@Override
507616
public HandlerRegistration addAddedFileHandler(final AddedFileEvent.AddedFileHandler<UploadFile> handler) {
508617
return addHandler(new AddedFileEvent.AddedFileHandler<UploadFile>() {

src/main/java/gwt/material/design/addins/client/fileuploader/js/JsFileUploaderOptions.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,33 @@ public class JsFileUploaderOptions {
6464

6565
@JsProperty
6666
public boolean withCredentials;
67+
68+
@JsProperty
69+
public String dictDefaultMessage;
70+
71+
@JsProperty
72+
public String dictFallbackMessage;
73+
74+
@JsProperty
75+
public String dictFallbackText;
76+
77+
@JsProperty
78+
public String dictFileTooBig;
79+
80+
@JsProperty
81+
public String dictInvalidFileType;
82+
@JsProperty
83+
public String dictResponseError;
84+
85+
@JsProperty
86+
public String dictCancelUpload;
87+
88+
@JsProperty
89+
public String dictCancelUploadConfirmation;
90+
91+
@JsProperty
92+
public String dictRemoveFile;
93+
94+
@JsProperty
95+
public String dictMaxFilesExceeded;
6796
}

src/main/java/gwt/material/design/addins/client/timepicker/MaterialTimePicker.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,36 @@ public void setUniqueId(String uniqueId) {
304304
options.uniqueId = uniqueId;
305305
}
306306

307+
public String getCancelText() {
308+
return options.cancelText;
309+
}
310+
311+
/**
312+
* Set the "Cancel" text located on TimePicker's action buttons
313+
*/
314+
public void setCancelText(String cancelText) {
315+
options.cancelText = cancelText;
316+
317+
if (isAttached()) {
318+
reload();
319+
}
320+
}
321+
322+
public String getOkText() {
323+
return options.okText;
324+
}
325+
326+
/**
327+
* Set the "Ok" text located on TimePicker's action buttons
328+
*/
329+
public void setOkText(String okText) {
330+
options.okText = okText;
331+
332+
if (isAttached()) {
333+
reload();
334+
}
335+
}
336+
307337
@Override
308338
public MaterialIcon getIcon() {
309339
return icon;

src/main/java/gwt/material/design/addins/client/timepicker/js/JsTimePickerOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ public class JsTimePickerOptions {
5252

5353
@JsProperty
5454
public Functions.Func afterHide;
55+
56+
@JsProperty
57+
public String cancelText;
58+
59+
@JsProperty
60+
public String okText;
5561
}

src/main/resources/gwt/material/design/addins/client/timepicker/resources/js/timepicker.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
autoclose: false, // show Cancel/OK buttons
1515
vibrate: true, // vibrate the device when dragging clock hand
1616
hour24:false,
17-
orientation:"portrait"
17+
orientation:"portrait",
18+
cancelText: "CANCEL",
19+
okText: "OK"
1820
};
1921

2022
// Listen touch events in touch screen device, instead of mouse events in desktop.
@@ -137,10 +139,10 @@
137139
if (!options.autoclose) {
138140
this.popover.css('height', '380px');
139141
var $closeButtons = $('<div class="lolliclock-buttons"></div>').appendTo(main);
140-
$('<div class="lolliclock-button">Cancel</div>')
142+
$('<div class="lolliclock-button">' + options.cancelText + '</div>')
141143
.click($.proxy(this.hide, this))
142144
.appendTo($closeButtons);
143-
$('<div class="lolliclock-button">OK</div>')
145+
$('<div class="lolliclock-button">' + options.okText + '</div>')
144146
.click($.proxy(this.done, this))
145147
.appendTo($closeButtons);
146148
this.closeButtons = popover.find('.lolliclock-button');

src/main/resources/gwt/material/design/addins/client/timepicker/resources/js/timepicker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/java/gwt/material/design/addins/client/ui/MaterialFileUploaderTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,41 @@ protected void checkStructure(MaterialFileUploader fileUploader) {
506506
assertTrue(btnClear.getElement().hasAttribute("data-dz-remove"));
507507
assertTrue(btnClear.getElement().hasClassName(AddinsCssName.PH));
508508
}
509+
510+
public void testLanguage() {
511+
// Given
512+
final String DEFAULT_MESSAGE = "Mag-drop ng mga file dito upang mag-upload";
513+
final String FALLBACK_MESSAGE = "Hindi sinusuportahan ng iyong browser ang drag'n'drop upload file.";
514+
final String FALLBACK_TEXT = "Mangyaring gamitin ang form ng fallback sa ibaba upang i-upload ang iyong mga file tulad ng sa mga lumang araw.";
515+
final String FILE_TOO_BIG = "Ang file ay masyadong malaki ({{filesize}} MiB). Max filesize: {{maxFilesize}} MiB.";
516+
final String INVALID_FILE_TYPE = "Hindi ka maaaring mag-upload ng mga file ng ganitong uri.";
517+
final String RESPONSE_ERROR = "Tumugon ang server sa code na {{statusCode}}.";
518+
final String CANCEL_UPLOAD = "Kanselahin ang pag-upload";
519+
final String CANCEL_UPLOAD_CONFIRMATION = "Sigurado ka bang gusto mong kanselahin ang pag-upload na ito?";
520+
final String REMOVE_FILE = "Alisin ang file";
521+
final String MAX_FILES_EXCEEDED = "Hindi ka maaaring mag-upload ng higit pang mga file.";
522+
MaterialFileUploader uploader = getWidget();
523+
524+
// when / then
525+
uploader.setDictDefaultMessage(DEFAULT_MESSAGE);
526+
assertEquals(DEFAULT_MESSAGE, uploader.getDictDefaultMessage());
527+
uploader.setDictFallbackMessage(FALLBACK_MESSAGE);
528+
assertEquals(FALLBACK_MESSAGE, uploader.getDictFallbackMessage());
529+
uploader.setDictFallbackText(FALLBACK_TEXT);
530+
assertEquals(FALLBACK_TEXT, uploader.getDictFallbackText());
531+
uploader.setDictFileTooBig(FILE_TOO_BIG);
532+
assertEquals(FILE_TOO_BIG, uploader.getDictFileTooBig());
533+
uploader.setDictInvalidFileType(INVALID_FILE_TYPE);
534+
assertEquals(INVALID_FILE_TYPE, uploader.getDictInvalidFileType());
535+
uploader.setDictResponseError(RESPONSE_ERROR);
536+
assertEquals(RESPONSE_ERROR, uploader.getDictResponseError());
537+
uploader.setDictCancelUpload(CANCEL_UPLOAD);
538+
assertEquals(CANCEL_UPLOAD, uploader.getDictCancelUpload());
539+
uploader.setDictCancelUploadConfirmation(CANCEL_UPLOAD_CONFIRMATION);
540+
assertEquals(CANCEL_UPLOAD_CONFIRMATION, uploader.getDictCancelUploadConfirmation());
541+
uploader.setDictRemoveFile(REMOVE_FILE);
542+
assertEquals(REMOVE_FILE, uploader.getDictRemoveFile());
543+
uploader.setDictMaxFilesExceeded(MAX_FILES_EXCEEDED);
544+
assertEquals(MAX_FILES_EXCEEDED, uploader.getDictMaxFilesExceeded());
545+
}
509546
}

src/test/java/gwt/material/design/addins/client/ui/MaterialTimePickerTest.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020
package gwt.material.design.addins.client.ui;
2121

2222
import gwt.material.design.addins.client.timepicker.MaterialTimePicker;
23+
import gwt.material.design.addins.client.timepicker.js.JsTimePicker;
2324
import gwt.material.design.addins.client.ui.base.AbstractValueWidgetTest;
24-
import gwt.material.design.client.constants.*;
25+
import gwt.material.design.client.constants.Color;
26+
import gwt.material.design.client.constants.IconSize;
27+
import gwt.material.design.client.constants.IconType;
28+
import gwt.material.design.client.constants.Orientation;
2529
import gwt.material.design.client.ui.MaterialInput;
2630
import gwt.material.design.client.ui.MaterialLabel;
2731
import gwt.material.design.client.ui.MaterialPanel;
2832
import gwt.material.design.client.ui.html.Label;
33+
import gwt.material.design.jquery.client.api.JQueryElement;
2934

3035
import java.util.Date;
3136

@@ -184,4 +189,38 @@ public void testValue() {
184189
timePicker.reset();
185190
checkValueChangeEvent(timePicker, VALUE, SECOND_VALUE);
186191
}
192+
193+
public void testLanguage() {
194+
// Given
195+
MaterialTimePicker timePicker = getWidget();
196+
197+
// when / then
198+
checkOkCancelTextConfigs(timePicker);
199+
}
200+
201+
protected void checkOkCancelTextConfigs(MaterialTimePicker timePicker) {
202+
final String OK_TEXT = "Tapos Na";
203+
final String CANCEL_TEXT = "Kanselahin";
204+
205+
timePicker.setOkText(OK_TEXT);
206+
assertEquals(OK_TEXT, timePicker.getOkText());
207+
208+
timePicker.setCancelText(CANCEL_TEXT);
209+
assertEquals(CANCEL_TEXT, timePicker.getCancelText());
210+
211+
final boolean[] firedOpenHandler = {false};
212+
timePicker.addOpenHandler(openEvent -> {
213+
firedOpenHandler[0] = true;
214+
JQueryElement cancelButton = $(".lolliclock-buttons .lolliclock-button:nth-child(1)");
215+
assertNotNull(cancelButton);
216+
assertEquals(CANCEL_TEXT, cancelButton.text());
217+
218+
JQueryElement okButton = $(".lolliclock-buttons .lolliclock-button:nth-child(2)");
219+
assertNotNull(okButton);
220+
assertEquals(OK_TEXT, okButton.text());
221+
});
222+
223+
JsTimePicker.$(timePicker.getTimeInput().getElement()).lolliclock("show");
224+
assertTrue(firedOpenHandler[0]);
225+
}
187226
}

0 commit comments

Comments
 (0)