@@ -302,7 +302,12 @@ const addI18n = (location: string, str?: string): string|undefined => {
302302 i18n . set ( key , { ...add , first, [ i18nLang ] : str , locations} ) ;
303303 return first ;
304304} ;
305- const normComment = ( location : string , str ?: string ) => str && addI18n ( location , str . replace ( / @ / g, 'at' ) . replaceAll ( '**' , '^' ) ) ;
305+ const normComment = ( location : string , str ?: string ) => {
306+ if ( ! str || commentI18nIgnore && commentI18nIgnore . test ( str ) ) {
307+ return str ;
308+ }
309+ return addI18n ( location , str . replace ( / @ / g, 'at' ) . replaceAll ( '**' , '^' ) ) ;
310+ } ;
306311const templateTrans : Trans < TemplateLine > = ( location , line , header , additions ) : OptStrs => {
307312 if ( header ) return templateHeader ;
308313 if ( header === false ) {
@@ -346,7 +351,12 @@ const templateTrans: Trans<TemplateLine> = (location, line, header, additions):
346351 ]
347352}
348353const knownManufacturers = new Map < string , [ number , string ] > ( [
354+ [ 'tem' , [ 0x10 , 'TEM' ] ] ,
355+ [ 'wolf' , [ 0x19 , 'Wolf' ] ] , // actually under kromschroeder below
356+ [ 'encon' , [ 0x40 , 'ENCON' ] ] ,
357+ [ 'kromschroeder' , [ 0x50 , 'Kromschröder' ] ] ,
349358 [ 'vaillant' , [ 0xb5 , 'Vaillant' ] ] ,
359+ [ 'weishaupt' , [ 0xc5 , 'Weishaupt' ] ] ,
350360] )
351361const setSubdirManuf = ( subdir : string ) : string | undefined => {
352362 const [ id , name ] = knownManufacturers . get ( subdir ) || [ ] ;
@@ -466,7 +476,7 @@ const isSimpleField = (line: FieldOfLine, singleField?: string): {comm?: string,
466476 }
467477 return { comm : line [ 5 ] , typ} ;
468478}
469- const fieldTrans = ( location : string , line : FieldOfLine | undefined , seen : Map < string , number > , additions : Additions , singleField ?: string ) : OptStrs => {
479+ const fieldTrans = ( location : string , line : FieldOfLine | undefined , seen : Map < string , number > , additions : Additions , singleField ?: string , optional ?: true ) : OptStrs => {
470480 if ( ! line ) return ;
471481 const { id, typ, typLen, comm, divisor, values, constValue}
472482 = divisorValues ( line [ 0 ] , line [ 2 ] , line [ 3 ] , line [ 5 ] , singleField ) ;
@@ -495,7 +505,7 @@ const fieldTrans = (location: string, line: FieldOfLine|undefined, seen: Map<str
495505 divisor || values ,
496506 typLen ,
497507 constValue !== undefined ? `@constValue(${ constValue } )` : '' ,
498- `${ suffName } : ${ typ } ,` ,
508+ `${ suffName } ${ optional ? '?' : '' } : ${ typ } ,` ,
499509 ]
500510} ;
501511const messageHeader = [
@@ -557,7 +567,7 @@ const namespaceWithZz = (header: string, additions: Additions) => {
557567 // // drop component index suffix
558568 // parts.splice(parts.length-1, 1);
559569 // }
560- circuit = parts . map ( p => normId ( p ) ) . map ( p => ( p [ 0 ] >= '0' && p [ 0 ] <= '9' ?'_' + p :pascalCase ( p ) ) ) . join ( '.' ) ;
570+ circuit = parts . filter ( p => ! ! p ) . map ( p => normId ( p ) ) . map ( p => ( p [ 0 ] >= '0' && p [ 0 ] <= '9' ?'_' + p :pascalCase ( p ) ) ) . join ( '.' ) ;
561571 return [
562572 zz ,
563573 `namespace ${ circuit } {` ,
@@ -803,7 +813,14 @@ const messageTrans: Trans<MessageLine> = (location, wholeLine, header, additions
803813 }
804814 if ( ! model ) {
805815 const fields : OptStrs = [ ] ;
806- fieldLines . forEach ( fieldLine => fields . push ( ...fieldTrans ( location , fieldLine , seenFields , additions , fieldLines . length === 1 ?modelName :'' ) || [ ] ) ) ;
816+ let optional : undefined | true = undefined ;
817+ fieldLines . forEach ( fieldLine => {
818+ if ( fieldLine [ 0 ] ?. startsWith ( '?' ) ) {
819+ fieldLine [ 0 ] = fieldLine [ 0 ] . substring ( 1 ) ;
820+ optional = true ;
821+ }
822+ fields . push ( ...fieldTrans ( location , fieldLine , seenFields , additions , fieldLines . length === 1 ?modelName :'' , optional ) || [ ] ) ;
823+ } ) ;
807824 model = [
808825 ( line [ 3 ] || isDefault ) && `/** ${ normComment ( location , line [ 3 ] ) || isDefault } */` ,
809826 single
@@ -868,6 +885,7 @@ const helpTxt = [
868885 ' -p mapfile the file name of a previously generated multi-language mapping to read for seeding the i18n normalization' ,
869886 ' -s i18ndir the directory in which to store i18n file(s) per language ("<lang>.yaml")' ,
870887 ' -i regex pattern for file names (including relative dir) to ignore' ,
888+ ' -I regex pattern for comment strings to ignore for i18n' ,
871889 ' -n add extra namespace for explicitly named circuit' ,
872890 ' csvfile the csv file(s) to transform (unless to traverse the whole basedir)'
873891] ;
@@ -879,6 +897,7 @@ let i18nLang: keyof Omit<I18n, 'locations'> = 'en';
879897let warnI18n = false ;
880898let i18nMap : Map < string , [ string , Partial < I18n > ] > ; // map from message/field/template key to i18n key and language+text
881899let i18nMapRev : Map < string , string > ; // map from non-en language to en from previous mapping
900+ let commentI18nIgnore : RegExp | undefined ;
882901export const csv2tsp = async ( args : string [ ] = [ ] ) => {
883902 let indir = 'latest/en' ;
884903 let outdir = 'outtsp' ;
@@ -930,6 +949,9 @@ export const csv2tsp = async (args: string[] = []) => {
930949 case '-i' :
931950 ignorePattern = new RegExp ( args [ ++ i ] ) ;
932951 break ;
952+ case '-I' :
953+ commentI18nIgnore = new RegExp ( args [ ++ i ] ) ;
954+ break ;
933955 case '-n' :
934956 namespacePerCircuit = true ;
935957 break ;
0 commit comments