@@ -10,6 +10,10 @@ const S: InternalState = { adapters: {} };
1010
1111export const loadCopydeck = ( deck : CopyDeck ) => ( S . copy = deck ) ;
1212
13+ const getUiString = ( key : keyof NonNullable < CopyDeck [ "ui" ] > , fallback : string ) : string => {
14+ return S . copy ?. ui ?. [ key ] || fallback ;
15+ } ;
16+
1317export const registerAdapter = ( name : string , fn : ( raw : string , code ?: string ) => Trace | null ) =>
1418 ( S . adapters [ name ] = fn ) ;
1519
@@ -56,10 +60,13 @@ const pickVariant = (trace: Trace, code: string | undefined, audience: string) =
5660 return true ;
5761 } ;
5862
63+ const lineStr = getUiString ( "line" , "line" ) ;
64+ const inStr = getUiString ( "in" , "in" ) ;
65+ const thisFileStr = getUiString ( "thisFile" , "this file" ) ;
5966 const loc =
60- trace . line && trace . file ? `line ${ trace . line } in ${ trace . file } ` :
61- trace . line ? `line ${ trace . line } ` :
62- trace . file || "this file" ;
67+ trace . line && trace . file ? `${ lineStr } ${ trace . line } ${ inStr } ${ trace . file } ` :
68+ trace . line ? `${ lineStr } ${ trace . line } ` :
69+ trace . file || thisFileStr ;
6370
6471 const vars = {
6572 loc,
@@ -95,8 +102,8 @@ const pickVariant = (trace: Trace, code: string | undefined, audience: string) =
95102 why ? `<div class="pfem__why">${ why } </div>` : "" ,
96103 steps ?. length ? `<ul class="pfem__steps">${ steps . map ( ( s ) => `<li>${ s } </li>` ) . join ( "" ) } </ul>` : "" ,
97104 patch ? `<pre class="pfem__patch">${ escapeHtml ( patch ) } </pre>` : "" ,
98- `<details class="pfem__details"><summary>Error details</summary><pre>${ escapeHtml (
99- ( trace . type || " Error") + ": " + trace . message
105+ `<details class="pfem__details"><summary>${ escapeHtml ( getUiString ( "errorDetails" , " Error details" ) ) } </summary><pre>${ escapeHtml (
106+ ( trace . type || getUiString ( "error" , " Error") ) + ": " + trace . message
100107 ) } </pre></details>`
101108 ] . filter ( Boolean ) . join ( "\n" ) ;
102109
@@ -131,15 +138,15 @@ export const friendlyExplain = (opts: ExplainOptions): ExplainResult => {
131138 return {
132139 trace,
133140 variantId : "Other/variants/0" ,
134- title : " Python error",
135- summary : " Start with the last line of the message and the highlighted code line.",
136- why : " The last line of the traceback tells you the error type and main cause.",
137- steps : [ " Fix one small thing and run again."] ,
141+ title : getUiString ( "pythonError" , " Python error") ,
142+ summary : getUiString ( "fallbackSummary" , " Start with the last line of the message and the highlighted code line.") ,
143+ why : getUiString ( "fallbackWhy" , " The last line of the traceback tells you the error type and main cause.") ,
144+ steps : [ getUiString ( "fallbackStep" , " Fix one small thing and run again.") ] ,
138145 html : undefined
139146 } ;
140147 }
141148
142- // not convinced by this implementation, and may decide to drop the verbosity option...
149+ // not convinced by this implementation, and may decide to drop the verbosity option entirely ...
143150 if ( verbosity === "brief" ) {
144151 chosen . why = undefined ;
145152 chosen . steps = chosen . steps ?. slice ( 0 , 1 ) ;
0 commit comments