3
3
* License: MS-RSL – see LICENSE.md for details
4
4
*/
5
5
6
+ import { defineMessage , useIntl } from "react-intl" ;
7
+
6
8
import { Checkbox } from "@cocalc/frontend/antd-bootstrap" ;
7
- import { Component , Rendered } from "@cocalc/frontend/app-framework" ;
8
- import { capitalize , is_different , keys } from "@cocalc/util/misc" ;
9
- import { JUPYTER_CLASSIC_MODERN } from "@cocalc/util/theme" ;
9
+ import { Rendered } from "@cocalc/frontend/app-framework" ;
10
10
import { A } from "@cocalc/frontend/components" ;
11
+ import { IntlMessage , isIntlMessage } from "@cocalc/frontend/i18n" ;
12
+ import { capitalize , keys } from "@cocalc/util/misc" ;
13
+ import { JUPYTER_CLASSIC_MODERN } from "@cocalc/util/theme" ;
11
14
12
- const EDITOR_SETTINGS_CHECKBOXES : { [ setting : string ] : string | Rendered } = {
13
- extra_button_bar :
14
- "customizable button bar below menu bar with shortcuts to menu items" ,
15
- line_wrapping : "wrap long lines" ,
16
- line_numbers : "show line numbers" ,
17
- jupyter_line_numbers : "show line numbers in Jupyter notebooks" ,
18
- code_folding : "fold code using control+Q" ,
19
- smart_indent : "context sensitive indentation" ,
20
- electric_chars : "sometimes reindent current line" ,
21
- match_brackets : "highlight matching brackets near cursor" ,
22
- auto_close_brackets : "automatically close brackets" ,
23
- match_xml_tags : "automatically match XML tags" ,
24
- auto_close_xml_tags : "automatically close XML tags" ,
25
- auto_close_latex : "automatically close LaTeX environments" ,
26
- strip_trailing_whitespace : "remove whenever file is saved" ,
27
- show_trailing_whitespace : "show spaces at ends of lines" ,
28
- spaces_instead_of_tabs : "send spaces when the tab key is pressed" ,
29
- build_on_save : "build LaTex/Rmd files whenever it is saved to disk" ,
30
- show_exec_warning : "warn that certain files are not directly executable" ,
31
- ask_jupyter_kernel : "ask which kernel to use for a new Jupyter Notebook" ,
32
- disable_jupyter_virtualization :
33
- "render entire notebook instead of just visible part (slower and not recommended)" ,
15
+ const EDITOR_SETTINGS_CHECKBOXES : {
16
+ [ setting : string ] : IntlMessage | Rendered ;
17
+ } = {
18
+ extra_button_bar : defineMessage ( {
19
+ id : "account.editor-setting.checkbox.extra_button_bar" ,
20
+ defaultMessage :
21
+ "customizable button bar below menu bar with shortcuts to menu items" ,
22
+ } ) ,
23
+ line_wrapping : defineMessage ( {
24
+ id : "account.editor-setting.checkbox.line_wrapping" ,
25
+ defaultMessage : "wrap long lines" ,
26
+ } ) ,
27
+ line_numbers : defineMessage ( {
28
+ id : "account.editor-setting.checkbox.line_numbers" ,
29
+ defaultMessage : "show line numbers" ,
30
+ } ) ,
31
+ jupyter_line_numbers : defineMessage ( {
32
+ id : "account.editor-setting.checkbox.jupyter_line_numbers" ,
33
+ defaultMessage : "show line numbers in Jupyter Notebooks" ,
34
+ } ) ,
35
+ code_folding : defineMessage ( {
36
+ id : "account.editor-setting.checkbox.code_folding" ,
37
+ defaultMessage : "fold code using control+Q" ,
38
+ } ) ,
39
+ smart_indent : defineMessage ( {
40
+ id : "account.editor-setting.checkbox.smart_indent" ,
41
+ defaultMessage : "context sensitive indentation" ,
42
+ } ) ,
43
+ electric_chars : defineMessage ( {
44
+ id : "account.editor-setting.checkbox.electric_chars" ,
45
+ defaultMessage : "sometimes reindent current line" ,
46
+ } ) ,
47
+ match_brackets : defineMessage ( {
48
+ id : "account.editor-setting.checkbox.match_brackets" ,
49
+ defaultMessage : "highlight matching brackets near cursor" ,
50
+ } ) ,
51
+ auto_close_brackets : defineMessage ( {
52
+ id : "account.editor-setting.checkbox.auto_close_brackets" ,
53
+ defaultMessage : "automatically close brackets" ,
54
+ } ) ,
55
+ match_xml_tags : defineMessage ( {
56
+ id : "account.editor-setting.checkbox.match_xml_tags" ,
57
+ defaultMessage : "automatically match XML tags" ,
58
+ } ) ,
59
+ auto_close_xml_tags : defineMessage ( {
60
+ id : "account.editor-setting.checkbox.auto_close_xml_tags" ,
61
+ defaultMessage : "automatically close XML tags" ,
62
+ } ) ,
63
+ auto_close_latex : defineMessage ( {
64
+ id : "account.editor-setting.checkbox.auto_close_latex" ,
65
+ defaultMessage : "automatically close LaTeX environments" ,
66
+ } ) ,
67
+ strip_trailing_whitespace : defineMessage ( {
68
+ id : "account.editor-setting.checkbox.strip_trailing_whitespace" ,
69
+ defaultMessage : "remove whenever file is saved" ,
70
+ } ) ,
71
+ show_trailing_whitespace : defineMessage ( {
72
+ id : "account.editor-setting.checkbox.show_trailing_whitespace" ,
73
+ defaultMessage : "show spaces at ends of lines" ,
74
+ } ) ,
75
+ spaces_instead_of_tabs : defineMessage ( {
76
+ id : "account.editor-setting.checkbox.spaces_instead_of_tabs" ,
77
+ defaultMessage : "send spaces when the tab key is pressed" ,
78
+ } ) ,
79
+ build_on_save : defineMessage ( {
80
+ id : "account.editor-setting.checkbox.build_on_save" ,
81
+ defaultMessage : "build LaTex/Rmd files whenever it is saved to disk" ,
82
+ } ) ,
83
+ show_exec_warning : defineMessage ( {
84
+ id : "account.editor-setting.checkbox.show_exec_warning" ,
85
+ defaultMessage : "warn that certain files are not directly executable" ,
86
+ } ) ,
87
+ ask_jupyter_kernel : defineMessage ( {
88
+ id : "account.editor-setting.checkbox.ask_jupyter_kernel" ,
89
+ defaultMessage : "ask which kernel to use for a new Jupyter Notebook" ,
90
+ } ) ,
91
+ disable_jupyter_virtualization : defineMessage ( {
92
+ id : "account.editor-setting.checkbox.disable_jupyter_virtualization" ,
93
+ defaultMessage :
94
+ "render entire Jupyter Notebook instead of just visible part (slower and not recommended)" ,
95
+ } ) ,
34
96
jupyter_classic : (
35
97
< span >
36
98
< A href = "https://github.com/sagemathinc/cocalc/issues/7706" >
@@ -50,15 +112,13 @@ interface Props {
50
112
on_change : Function ;
51
113
}
52
114
53
- export class EditorSettingsCheckboxes extends Component < Props > {
54
- public shouldComponentUpdate ( props ) : boolean {
55
- return is_different ( this . props , props , [
56
- "editor_settings" ,
57
- "email_address" ,
58
- ] ) ;
59
- }
115
+ export function EditorSettingsCheckboxes ( props : Props ) {
116
+ const intl = useIntl ( ) ;
60
117
61
- private label_checkbox ( name : string , desc : string | Rendered ) : Rendered {
118
+ function label_checkbox (
119
+ name : string ,
120
+ desc : IntlMessage | Rendered ,
121
+ ) : Rendered {
62
122
return (
63
123
< span >
64
124
{ capitalize (
@@ -68,37 +128,38 @@ export class EditorSettingsCheckboxes extends Component<Props> {
68
128
. replace ( "xml" , "XML" )
69
129
. replace ( "latex" , "LaTeX" ) ,
70
130
) + ": " }
71
- { desc }
131
+ { isIntlMessage ( desc ) ? intl . formatMessage ( desc ) : desc }
72
132
</ span >
73
133
) ;
74
134
}
75
135
76
- private render_checkbox ( name : string , desc : string | Rendered ) : Rendered {
136
+ function render_checkbox (
137
+ name : string ,
138
+ desc : IntlMessage | Rendered ,
139
+ ) : Rendered {
77
140
if (
78
- this . props . email_address ?. indexOf ( "minervaproject.com" ) != - 1 &&
141
+ props . email_address ?. indexOf ( "minervaproject.com" ) != - 1 &&
79
142
name === "jupyter_classic"
80
143
) {
81
144
// Special case -- minerva doesn't get the jupyter classic option, to avoid student confusion.
82
145
return ;
83
146
}
84
147
return (
85
148
< Checkbox
86
- checked = { ! ! this . props . editor_settings . get ( name ) }
149
+ checked = { ! ! props . editor_settings . get ( name ) }
87
150
key = { name }
88
- onChange = { ( e ) => this . props . on_change ( name , e . target . checked ) }
151
+ onChange = { ( e ) => props . on_change ( name , e . target . checked ) }
89
152
>
90
- { this . label_checkbox ( name , desc ) }
153
+ { label_checkbox ( name , desc ) }
91
154
</ Checkbox >
92
155
) ;
93
156
}
94
157
95
- public render ( ) : JSX . Element {
96
- return (
97
- < span >
98
- { keys ( EDITOR_SETTINGS_CHECKBOXES ) . map ( ( name ) =>
99
- this . render_checkbox ( name , EDITOR_SETTINGS_CHECKBOXES [ name ] ) ,
100
- ) }
101
- </ span >
102
- ) ;
103
- }
158
+ return (
159
+ < span >
160
+ { keys ( EDITOR_SETTINGS_CHECKBOXES ) . map ( ( name ) =>
161
+ render_checkbox ( name , EDITOR_SETTINGS_CHECKBOXES [ name ] ) ,
162
+ ) }
163
+ </ span >
164
+ ) ;
104
165
}
0 commit comments