@@ -223,7 +223,8 @@ def make(self, field, value, error, title, placeholder="", readonly=False):
223223
224224
225225class FileUploadWidget :
226- def make (self , field , value , error , title , placeholder = "" , readonly = False ):
226+ def make (self , field , value , error , title , placeholder = "" , readonly = False , T = None ):
227+ T = T or (lambda s : s )
227228 field_id = to_id (field )
228229 control = DIV ()
229230 if value and not error :
@@ -232,11 +233,11 @@ def make(self, field, value, error, title, placeholder="", readonly=False):
232233 if not readonly :
233234 download_div .append (
234235 LABEL (
235- "Currently: " ,
236+ T ( "Currently: " ) ,
236237 )
237238 )
238239 url = getattr (field , "download_url" , lambda value : "#" )(value )
239- download_div .append (A (" download " , _href = url ))
240+ download_div .append (A (T ( " download " ) , _href = url ))
240241
241242 if not readonly :
242243 download_div .append (
@@ -247,13 +248,13 @@ def make(self, field, value, error, title, placeholder="", readonly=False):
247248 _title = title ,
248249 )
249250 )
250- download_div .append (" (check to remove)" )
251+ download_div .append (T ( " (check to remove)" ) )
251252
252253 control .append (download_div )
253254
254- control .append (LABEL ("Change: " ))
255+ control .append (LABEL (T ( "Change: " ) ))
255256 else :
256- control .append (LABEL ("Upload: " ))
257+ control .append (LABEL (T ( "Upload: " ) ))
257258 control .append (INPUT (_type = "file" , _id = field_id , _name = field .name ))
258259 return control
259260
@@ -300,8 +301,10 @@ def __call__(
300301 showreadonly ,
301302 show_id ,
302303 kwargs = None ,
304+ T = None ,
303305 ):
304306 kwargs = kwargs if kwargs else {}
307+ T = T or (lambda s : s )
305308
306309 kwargs ["_accept-charset" ] = "utf8"
307310 form_method = "POST"
@@ -388,8 +391,8 @@ def __call__(
388391 field_value = None
389392
390393 field_name = field .name
391- field_comment = field .comment if field .comment else ""
392- field_label = field .label
394+ field_comment = T ( field .comment ) if isinstance ( field .comment , str ) and field . comment else ( field . comment or "" )
395+ field_label = T ( field . label ) if isinstance ( field . label , str ) else field .label
393396 input_id = to_id (field )
394397 if is_virtual :
395398 value = None
@@ -451,7 +454,7 @@ def __call__(
451454 )
452455 # do we need the variables below?
453456 delete_field_attributes = dict ()
454- delete_field_attributes ["_label" ] = "Remove"
457+ delete_field_attributes ["_label" ] = T ( "Remove" )
455458 delete_field_attributes ["_value" ] = "ON"
456459 delete_field_attributes ["_type" ] = "checkbox"
457460 delete_field_attributes ["_name" ] = "_delete_" + field .name
@@ -466,7 +469,10 @@ def __call__(
466469 else :
467470 widget = Widget ()
468471
469- control = widget .make (field , value , error , title , placeholder )
472+ if isinstance (widget , FileUploadWidget ):
473+ control = widget .make (field , value , error , title , placeholder , T = T )
474+ else :
475+ control = widget .make (field , value , error , title , placeholder )
470476
471477 key = control .name .rstrip ("/" )
472478
@@ -515,13 +521,13 @@ def __call__(
515521 wrapped ,
516522 LABEL (
517523 " " ,
518- field . label ,
524+ field_label ,
519525 _for = input_id ,
520526 _class = class_label ,
521527 _style = "display: inline !important" ,
522528 ),
523529 P (error , _class = class_error ) if error else "" ,
524- P (field . comment or "" , _class = class_info ),
530+ P (field_comment , _class = class_info ),
525531 _class = class_outer ,
526532 )
527533 )
@@ -533,10 +539,10 @@ def __call__(
533539
534540 form .append (
535541 DIV (
536- LABEL (field . label , _for = input_id , _class = class_label ),
542+ LABEL (field_label , _for = input_id , _class = class_label ),
537543 wrapped ,
538544 P (error , _class = class_error ) if error else "" ,
539- P (field . comment or "" , _class = class_info ),
545+ P (field_comment , _class = class_info ),
540546 _class = class_outer ,
541547 )
542548 )
@@ -551,7 +557,7 @@ def __call__(
551557 deletable_field_type = "checkbox"
552558
553559 # Set the deletable json field attributes.
554- deletable_record_attributes ["_label" ] = " check to delete"
560+ deletable_record_attributes ["_label" ] = T ( " check to delete" )
555561 deletable_record_attributes ["_name" ] = deletable_field_name
556562 deletable_record_attributes ["_type" ] = deletable_field_type
557563 deletable_record_attributes ["_class" ] = self .classes ["input[type=checkbox]" ]
@@ -590,7 +596,7 @@ def __call__(
590596 submit_button_field_type = "submit"
591597
592598 # Set the deletable json field attributes.
593- submit_button_attributes ["_label" ] = "Submit"
599+ submit_button_attributes ["_label" ] = T ( "Submit" )
594600 submit_button_attributes ["_type" ] = submit_button_field_type
595601 submit_button_attributes ["_class" ] = self .classes ["input[type=submit]" ]
596602
@@ -599,7 +605,7 @@ def __call__(
599605
600606 controls ["submit" ] = INPUT (
601607 _type = submit_button_field_type ,
602- _value = "Submit" ,
608+ _value = T ( "Submit" ) ,
603609 _class = self .classes ["input[type=submit]" ],
604610 )
605611
@@ -769,11 +775,17 @@ def __init__(
769775 csrf_protection = True ,
770776 lifespan = None ,
771777 signing_info = None ,
772- submit_value = "Submit" ,
778+ submit_value = None ,
773779 show_id = False ,
774780 auto_process = True ,
781+ T = None ,
775782 ** kwargs ,
776783 ):
784+ self .T = T if T is not None else (lambda s : s )
785+ if submit_value is None :
786+ submit_value = self .T ("Submit" )
787+ elif isinstance (submit_value , str ):
788+ submit_value = self .T (submit_value )
777789 self .param = Param (
778790 formstyle = formstyle ,
779791 hidden = hidden ,
@@ -1027,6 +1039,7 @@ def helper(self):
10271039 self .showreadonly ,
10281040 show_id = self .show_id ,
10291041 kwargs = self .kwargs ,
1042+ T = self .T ,
10301043 )
10311044 for item in self .param .sidecar :
10321045 helper ["form" ][- 1 ][- 1 ].append (item )
0 commit comments