@@ -4,13 +4,19 @@ import {
44} from '@jupyterlab/application' ;
55import { ICellModel } from '@jupyterlab/cells' ;
66import { INotebookTracker , NotebookPanel } from '@jupyterlab/notebook' ;
7+ import { ITranslator , nullTranslator } from '@jupyterlab/translation' ;
78import { ICellFooterTracker } from 'jupyterlab-cell-input-footer' ;
89
910import { requestAPI } from './handler' ;
1011import { IDiffWidgetOptions } from './widget' ;
1112import { createNBDimeDiffWidget } from './diff/nbdime' ;
1213import { createCodeMirrorDiffWidget } from './diff/codemirror' ;
1314
15+ /**
16+ * The translation namespace for the plugin.
17+ */
18+ const TRANSLATION_NAMESPACE = 'jupyterlab-cell-diff' ;
19+
1420/**
1521 * Find a notebook by path using the notebook tracker
1622 */
@@ -56,43 +62,50 @@ const codeMirrorPlugin: JupyterFrontEndPlugin<void> = {
5662 id : 'jupyterlab-cell-diff:codemirror-plugin' ,
5763 description : 'Expose a command to show cell diffs using CodeMirror' ,
5864 requires : [ ICellFooterTracker , INotebookTracker ] ,
65+ optional : [ ITranslator ] ,
5966 autoStart : true ,
6067 activate : async (
6168 app : JupyterFrontEnd ,
6269 cellFooterTracker : ICellFooterTracker ,
63- notebookTracker : INotebookTracker
70+ notebookTracker : INotebookTracker ,
71+ translator : ITranslator | null
6472 ) => {
6573 const { commands } = app ;
74+ const trans = ( translator ?? nullTranslator ) . load ( TRANSLATION_NAMESPACE ) ;
6675
6776 commands . addCommand ( 'jupyterlab-cell-diff:show-codemirror' , {
68- label : 'Show Cell Diff (CodeMirror)' ,
77+ label : trans . __ ( 'Show Cell Diff (CodeMirror)' ) ,
6978 describedBy : {
7079 args : {
7180 type : 'object' ,
7281 properties : {
7382 cellId : {
7483 type : 'string' ,
75- description : 'ID of the cell to show diff for'
84+ description : trans . __ ( 'ID of the cell to show diff for' )
7685 } ,
7786 originalSource : {
7887 type : 'string' ,
79- description : 'Original source code to compare against'
88+ description : trans . __ ( 'Original source code to compare against' )
8089 } ,
8190 newSource : {
8291 type : 'string' ,
83- description : 'New source code to compare with'
92+ description : trans . __ ( 'New source code to compare with' )
8493 } ,
8594 showActionButtons : {
8695 type : 'boolean' ,
87- description : 'Whether to show action buttons in the diff widget'
96+ description : trans . __ (
97+ 'Whether to show action buttons in the diff widget'
98+ )
8899 } ,
89100 notebookPath : {
90101 type : 'string' ,
91- description : 'Path to the notebook containing the cell'
102+ description : trans . __ ( 'Path to the notebook containing the cell' )
92103 } ,
93104 openDiff : {
94105 type : 'boolean' ,
95- description : 'Whether to open the diff widget automatically'
106+ description : trans . __ (
107+ 'Whether to open the diff widget automatically'
108+ )
96109 }
97110 }
98111 }
@@ -115,14 +128,16 @@ const codeMirrorPlugin: JupyterFrontEndPlugin<void> = {
115128 const cell = findCell ( currentNotebook , cellId ) ;
116129 if ( ! cell ) {
117130 console . error (
118- 'Missing required arguments: cellId (or no active cell found)'
131+ trans . __ (
132+ 'Missing required arguments: cellId (or no active cell found)'
133+ )
119134 ) ;
120135 return ;
121136 }
122137
123138 const footer = cellFooterTracker . getFooter ( cell . id ) ;
124139 if ( ! footer ) {
125- console . error ( ` Footer not found for cell ${ cell . id } ` ) ;
140+ console . error ( trans . __ ( ' Footer not found for cell %1' , cell . id ) ) ;
126141 return ;
127142 }
128143
@@ -133,12 +148,13 @@ const codeMirrorPlugin: JupyterFrontEndPlugin<void> = {
133148 originalSource,
134149 newSource,
135150 showActionButtons,
136- openDiff
151+ openDiff,
152+ trans
137153 } ;
138154
139155 await createCodeMirrorDiffWidget ( options ) ;
140156 } catch ( error ) {
141- console . error ( 'Failed to create diff widget:' , error ) ;
157+ console . error ( trans . __ ( 'Failed to create diff widget: %1' ) , error ) ;
142158 }
143159 }
144160 } ) ;
@@ -152,43 +168,50 @@ const nbdimePlugin: JupyterFrontEndPlugin<void> = {
152168 id : 'jupyterlab-cell-diff:nbdime-plugin' ,
153169 description : 'Expose a command to show cell diffs using NBDime' ,
154170 requires : [ ICellFooterTracker , INotebookTracker ] ,
171+ optional : [ ITranslator ] ,
155172 autoStart : true ,
156173 activate : async (
157174 app : JupyterFrontEnd ,
158175 cellFooterTracker : ICellFooterTracker ,
159- notebookTracker : INotebookTracker
176+ notebookTracker : INotebookTracker ,
177+ translator : ITranslator | null
160178 ) => {
161179 const { commands } = app ;
180+ const trans = ( translator ?? nullTranslator ) . load ( TRANSLATION_NAMESPACE ) ;
162181
163182 commands . addCommand ( 'jupyterlab-cell-diff:show-nbdime' , {
164- label : 'Show Cell Diff (NBDime)' ,
183+ label : trans . __ ( 'Show Cell Diff (NBDime)' ) ,
165184 describedBy : {
166185 args : {
167186 type : 'object' ,
168187 properties : {
169188 cellId : {
170189 type : 'string' ,
171- description : 'ID of the cell to show diff for'
190+ description : trans . __ ( 'ID of the cell to show diff for' )
172191 } ,
173192 originalSource : {
174193 type : 'string' ,
175- description : 'Original source code to compare against'
194+ description : trans . __ ( 'Original source code to compare against' )
176195 } ,
177196 newSource : {
178197 type : 'string' ,
179- description : 'New source code to compare with'
198+ description : trans . __ ( 'New source code to compare with' )
180199 } ,
181200 showActionButtons : {
182201 type : 'boolean' ,
183- description : 'Whether to show action buttons in the diff widget'
202+ description : trans . __ (
203+ 'Whether to show action buttons in the diff widget'
204+ )
184205 } ,
185206 notebookPath : {
186207 type : 'string' ,
187- description : 'Path to the notebook containing the cell'
208+ description : trans . __ ( 'Path to the notebook containing the cell' )
188209 } ,
189210 openDiff : {
190211 type : 'boolean' ,
191- description : 'Whether to open the diff widget automatically'
212+ description : trans . __ (
213+ 'Whether to open the diff widget automatically'
214+ )
192215 }
193216 }
194217 }
@@ -211,7 +234,9 @@ const nbdimePlugin: JupyterFrontEndPlugin<void> = {
211234 const cell = findCell ( currentNotebook , cellId ) ;
212235 if ( ! cell ) {
213236 console . error (
214- 'Missing required arguments: cellId (or no active cell found)'
237+ trans . __ (
238+ 'Missing required arguments: cellId (or no active cell found)'
239+ )
215240 ) ;
216241 return ;
217242 }
@@ -228,12 +253,15 @@ const nbdimePlugin: JupyterFrontEndPlugin<void> = {
228253 } ) ;
229254 diffData = ( response as any ) . diff ;
230255 } catch ( error ) {
231- console . warn ( 'Failed to fetch diff data from server:' , error ) ;
256+ console . warn (
257+ trans . __ ( 'Failed to fetch diff data from server: %1' ) ,
258+ error
259+ ) ;
232260 }
233261
234262 const footer = cellFooterTracker . getFooter ( cell . id ) ;
235263 if ( ! footer ) {
236- console . error ( ` Footer not found for cell ${ cell . id } ` ) ;
264+ console . error ( trans . __ ( ' Footer not found for cell %1' , cell . id ) ) ;
237265 return ;
238266 }
239267
@@ -246,12 +274,13 @@ const nbdimePlugin: JupyterFrontEndPlugin<void> = {
246274 diffData : diffData ? { diff : diffData } : undefined ,
247275 cellId : cell . id ,
248276 showActionButtons,
249- openDiff
277+ openDiff,
278+ trans
250279 } ;
251280
252281 await createNBDimeDiffWidget ( options ) ;
253282 } catch ( error ) {
254- console . error ( 'Failed to create diff widget:' , error ) ;
283+ console . error ( trans . __ ( 'Failed to create diff widget: %1' ) , error ) ;
255284 }
256285 }
257286 } ) ;
0 commit comments