Make the cli help translatable

This commit is contained in:
Marek Roszko 2022-11-14 07:25:33 -05:00
parent f51db4e093
commit daa6e84d74
14 changed files with 87 additions and 69 deletions

View File

@ -24,6 +24,8 @@
#include <argparse/argparse.hpp>
#include <kiway.h>
#define UTF8STDSTR( s ) ( std::string( s.utf8_str() ) )
namespace CLI
{

View File

@ -32,9 +32,9 @@ CLI::EXPORT_PCB_BASE_COMMAND::EXPORT_PCB_BASE_COMMAND( std::string aName ) : COM
{
m_argParser.add_argument( "-o", ARG_OUTPUT )
.default_value( std::string() )
.help( "output file name" );
.help( UTF8STDSTR( _( "Output file name" ) ) );
m_argParser.add_argument( ARG_INPUT ).help( "input file" );
m_argParser.add_argument( ARG_INPUT ).help( UTF8STDSTR( _( "Input file" ) ) );
for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
{
@ -87,8 +87,9 @@ void CLI::EXPORT_PCB_BASE_COMMAND::addLayerArg( bool aRequire )
{
m_argParser.add_argument( "-l", ARG_LAYERS )
.default_value( std::string() )
.help( "comma separated list of untranslated layer names to include such as "
"F.Cu,B.Cu" );
.help( UTF8STDSTR(
_( "Comma separated list of untranslated layer names to include such as "
"F.Cu,B.Cu" ) ) );
m_requireLayers = aRequire;
}

View File

@ -44,51 +44,51 @@ CLI::EXPORT_PCB_DRILL_COMMAND::EXPORT_PCB_DRILL_COMMAND() : EXPORT_PCB_BASE_COMM
{
m_argParser.add_argument( ARG_FORMAT )
.default_value( std::string( "excellon" ) )
.help( "valid options are either excellon or gerber" );
.help( UTF8STDSTR( _( "Valid options excellon, gerber." ) ) );
m_argParser.add_argument( ARG_EXCELLON_ZEROS_FORMAT )
.default_value( std::string( "decimal" ) )
.help( "valid options are: decimal,supressleading,surpresstrailing,keep" );
.help( UTF8STDSTR( _( "Valid options are: decimal,supressleading,surpresstrailing,keep." ) ) );
m_argParser.add_argument( ARG_DRILL_ORIGIN )
.default_value( std::string( "absolute" ) )
.help( "valid options are: absolute,plot" );
.help( UTF8STDSTR( _( "Valid options are: absolute,plot" ) ) );
m_argParser.add_argument( "-u", ARG_UNITS )
.default_value( std::string( "in" ) )
.help( "output units, valid options are in or mm" );
.help( UTF8STDSTR( _( "Output units, valid options:in,mm" ) ) );
m_argParser.add_argument( ARG_EXCELLON_MIRRORY )
.help( "Mirror Y axis" )
.help( UTF8STDSTR( _( "Mirror Y axis" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_EXCELLON_MINIMALHEAD )
.help( "Minimal header" )
.help( UTF8STDSTR( _( "Minimal header" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_EXCELLON_SEPARATE_TH )
.help( "PTH and NPTH in separate files file" )
.help( UTF8STDSTR( _( "PTH and NPTH in separate files file" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_GENERATE_MAP )
.help( "Generate map / summary of drill hits" )
.help( UTF8STDSTR( _( "Generate map / summary of drill hits" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_MAP_FORMAT )
.default_value( std::string( "pdf" ) )
.help( "valid options are: pdf,gerberx2,ps,dxf,svg" );
.help( UTF8STDSTR( _( "Valid options: pdf,gerberx2,ps,dxf,svg" ) ) );
m_argParser.add_argument( ARG_SEPARATE_FILES )
.help( "Generate independent files for NPTH and PTH holes" )
.help( UTF8STDSTR( _( "Generate independent files for NPTH and PTH holes" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_GERBER_PRECISION )
.help( "Precision of gerber coordinates (5 or 6)" )
.help( UTF8STDSTR( _( "Precision of gerber coordinates (5 or 6)" ) ) )
.default_value( 5 );
}

View File

@ -41,23 +41,23 @@ CLI::EXPORT_PCB_DXF_COMMAND::EXPORT_PCB_DXF_COMMAND() : EXPORT_PCB_BASE_COMMAND(
addLayerArg( true );
m_argParser.add_argument( "-ird", ARG_INCLUDE_REFDES )
.help( "Include the reference designator text" )
.help( UTF8STDSTR( _( "Include the reference designator text" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-iv", ARG_INCLUDE_VALUE )
.help( "Include the value text" )
.help( UTF8STDSTR( _( "Include the value text" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-uc", ARG_USE_CONTOURS )
.help( "Plot graphic items using their contours" )
.help( UTF8STDSTR( _( "Plot graphic items using their contours" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-ou", ARG_OUTPUT_UNITS )
.default_value( std::string( "in" ) )
.help( "output file name" );
.help( UTF8STDSTR( _( "Output units, valid options: mm, in" ) ) );
}

View File

@ -41,42 +41,43 @@ CLI::EXPORT_PCB_GERBER_COMMAND::EXPORT_PCB_GERBER_COMMAND() : EXPORT_PCB_BASE_CO
addLayerArg( true );
m_argParser.add_argument( "-ird", ARG_INCLUDE_REFDES )
.help( "Include the reference designator text" )
.help( UTF8STDSTR( _( "Include the reference designator text" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-iv", ARG_INCLUDE_VALUE )
.help( "Include the value text" )
.help( UTF8STDSTR( _( "Include the value text" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-ibt", ARG_INCLUDE_BORDER_TITLE )
.help( "Include the border and title block" )
.help( UTF8STDSTR( _( "Include the border and title block" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_NO_X2 )
.help( "Do not use the extended X2 format" )
.help( UTF8STDSTR( _( "Do not use the extended X2 format" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_NO_NETLIST )
.help( "Do not generate netlist attributes" )
.help( UTF8STDSTR( _( "Do not generate netlist attributes" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_SUBTRACT_SOLDERMASK )
.help( "Subtract soldermask from silkscreen" )
.help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_DISABLE_APERTURE_MACROS )
.help( "Disable aperature macros" )
.help( UTF8STDSTR( _( "Disable aperature macros" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_PRECISION )
.help( "Precision of gerber coordinates (5 or 6)" )
.help( UTF8STDSTR(
_( "Precision of gerber coordinates, valid options: 5 or 6" ) ) )
.default_value( 6 );
}

View File

@ -36,28 +36,29 @@ CLI::EXPORT_PCB_PDF_COMMAND::EXPORT_PCB_PDF_COMMAND() : EXPORT_PCB_BASE_COMMAND(
addLayerArg( true );
m_argParser.add_argument( "-ird", ARG_INCLUDE_REFDES )
.help( "Include the reference designator text" )
.help( UTF8STDSTR( _( "Include the reference designator text" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-iv", ARG_INCLUDE_VALUE )
.help( "Include the value text" )
.help( UTF8STDSTR( _( "Include the value text" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-ibt", ARG_INCLUDE_BORDER_TITLE )
.help( "Include the border and title block" )
.help( UTF8STDSTR( _( "Include the border and title block" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_BLACKANDWHITE )
.help( "Black and white only" )
.help( UTF8STDSTR( _( "Black and white only" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-t", ARG_THEME )
.default_value( std::string() )
.help( "Color theme to use (will default to pcbnew settings)" );
.help( std::string(
_( "Color theme to use (will default to pcbnew settings)" ).ToUTF8() ) );
}

View File

@ -43,38 +43,41 @@ CLI::EXPORT_PCB_POS_COMMAND::EXPORT_PCB_POS_COMMAND() : EXPORT_PCB_BASE_COMMAND(
{
m_argParser.add_argument( ARG_SIDE )
.default_value( std::string( "both" ) )
.help( "valid options: front,back,both" );
.help( UTF8STDSTR( _(
"Valid options: front,back,both. Gerber format only supports \"both\"." ) ) );
m_argParser.add_argument( ARG_FORMAT )
.default_value( std::string( "ascii" ) )
.help( "valid options: ascii,csv,gerber" );
.help( UTF8STDSTR( _( "Valid options: ascii,csv,gerber" ) ) );
m_argParser.add_argument( ARG_UNITS )
.default_value( std::string( "in" ) )
.help( "output units, valid options are in or mm (ascii or csv only)" );
.help( UTF8STDSTR( _( "Output units; ascii or csv format only; valid options: in,mm" ) ) );
m_argParser.add_argument( ARG_NEGATE_BOTTOM_X )
.help( "Use negative X coordinates for footprints on bottom layer (ascii or csv only)" )
.help( UTF8STDSTR( _( "Use negative X coordinates for footprints on bottom layer "
"(ascii or csv formats only)" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_USE_DRILL_FILE_ORIGIN )
.help( "Use drill/place file origin (ascii or csv only)" )
.help( UTF8STDSTR( _( "Use drill/place file origin (ascii or csv only)" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_SMD_ONLY )
.help( "Include only SMD footprints (ascii or csv only)" )
.help( UTF8STDSTR( _( "Include only SMD footprints (ascii or csv only)" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_EXCLUDE_FOOTPRINTS_TH )
.help( "Exclue all footprints with through-hole pads (ascii or csv only)" )
.help( UTF8STDSTR(
_( "Exclude all footprints with through-hole pads (ascii or csv only)" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_GERBER_BOARD_EDGE )
.help( "Include board edge layer (gerber only)" )
.help( UTF8STDSTR( _( "Include board edge layer (gerber only)" ) ) )
.implicit_value( true )
.default_value( false );
}

View File

@ -44,48 +44,48 @@
CLI::EXPORT_PCB_STEP_COMMAND::EXPORT_PCB_STEP_COMMAND() : COMMAND( "step" )
{
m_argParser.add_argument( ARG_DRILL_ORIGIN )
.help( "Use Drill Origin for output origin" )
.help( UTF8STDSTR( _( "Use Drill Origin for output origin" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_GRID_ORIGIN )
.help( "Use Grid Origin for output origin" )
.help( UTF8STDSTR( _( "Use Grid Origin for output origin" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_NO_VIRTUAL )
.help( "Exclude 3D models for components with 'virtual' attribute" )
.help( UTF8STDSTR( _( "Exclude 3D models for components with 'virtual' attribute" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "--subst-models" )
.help( "Substitute STEP or IGS models with the same name in place of VRML models" )
.help( UTF8STDSTR( _( "Substitute STEP or IGS models with the same name in place of VRML models" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_FORCE, "-f" )
.help( "overwrite output file" )
.help( UTF8STDSTR( _( "Overwrite output file" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_BOARD_ONLY )
.help( "only generate a board with no components" )
.help( UTF8STDSTR( _( "Only generate a board with no components" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_MIN_DISTANCE )
.default_value( std::string() )
.help( "Minimum distance between points to treat them as separate ones (default 0.01mm)" );
.default_value( std::string( "0.01mm" ) )
.help( UTF8STDSTR( _( "Minimum distance between points to treat them as separate ones" ) ) );
m_argParser.add_argument( ARG_USER_ORIGIN )
.default_value( std::string() )
.help( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default mm)" );
.help( UTF8STDSTR( _( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default unit mm)" ) ) );
m_argParser.add_argument( "-o", ARG_OUTPUT )
.default_value( std::string() )
.help( "output file name" );
.help( UTF8STDSTR( _( "Output file name" ) ) );
m_argParser.add_argument( ARG_INPUT ).help( "input file" );
m_argParser.add_argument( ARG_INPUT ).help( UTF8STDSTR( _( "Input file" ) ) );
}
int CLI::EXPORT_PCB_STEP_COMMAND::Perform( KIWAY& aKiway )

View File

@ -39,21 +39,22 @@ CLI::EXPORT_PCB_SVG_COMMAND::EXPORT_PCB_SVG_COMMAND() : EXPORT_PCB_BASE_COMMAND(
addLayerArg( true );
m_argParser.add_argument( "-m", ARG_MIRROR )
.help( "Mirror the board (useful for trying to show bottom layers)" )
.help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "-t", ARG_THEME )
.default_value( std::string() )
.help( "Color theme to use (will default to pcbnew settings)" );
.help( UTF8STDSTR( _( "Color theme to use (will default to pcbnew settings)" ) ) );
m_argParser.add_argument( ARG_BLACKANDWHITE )
.help( "Black and white only" )
.help( UTF8STDSTR( _( "Black and white only" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_PAGE_SIZE )
.help( "Set page sizing mode (0 = page with frame and title block, 1 = current page size, 2 = board area only)" )
.help( UTF8STDSTR( _( "Set page sizing mode (0 = page with frame and title block, 1 = "
"current page size, 2 = board area only)" ) ) )
.default_value( 0 );
}

View File

@ -33,7 +33,7 @@ CLI::EXPORT_SCH_BOM_COMMAND::EXPORT_SCH_BOM_COMMAND() : EXPORT_PCB_BASE_COMMAND(
{
m_argParser.add_argument( ARG_FORMAT )
.default_value( std::string( "xml" ) )
.help( "Bom output format, valid options: xml" );
.help( UTF8STDSTR( _( "Bom output format, valid options: xml" ) ) );
}

View File

@ -33,7 +33,7 @@ CLI::EXPORT_SCH_NETLIST_COMMAND::EXPORT_SCH_NETLIST_COMMAND() : EXPORT_PCB_BASE_
{
m_argParser.add_argument( ARG_FORMAT )
.default_value( std::string( "kicadsexpr" ) )
.help( "Netlist output format, valid options: kicadsexpr, kicadxml, cadstar, orcadpcb2, spice, spicemodel" );
.help( UTF8STDSTR( _( "Netlist output format, valid options: kicadsexpr, kicadxml, cadstar, orcadpcb2, spice, spicemodel" ) ) );
}

View File

@ -35,20 +35,20 @@ CLI::EXPORT_SCH_PDF_COMMAND::EXPORT_SCH_PDF_COMMAND() : EXPORT_PCB_BASE_COMMAND(
{
m_argParser.add_argument( "-t", ARG_THEME )
.default_value( std::string() )
.help( "Color theme to use (will default to pcbnew settings)" );
.help( UTF8STDSTR( _( "Color theme to use (will default to pcbnew settings)" ) ) );
m_argParser.add_argument( ARG_BLACKANDWHITE )
.help( "Black and white only" )
.help( UTF8STDSTR( _( "Black and white only" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_EXCLUDE_DRAWING_SHEET )
.help( "No drawing sheet" )
.help( UTF8STDSTR( _( "No drawing sheet" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_NO_BACKGROUND_COLOR )
.help( "Avoid setting a background color (regardless of theme)" )
.help( UTF8STDSTR( _( "Avoid setting a background color (regardless of theme)" ) ) )
.implicit_value( true )
.default_value( false );
}

View File

@ -35,20 +35,20 @@ CLI::EXPORT_SCH_SVG_COMMAND::EXPORT_SCH_SVG_COMMAND() : EXPORT_PCB_BASE_COMMAND(
{
m_argParser.add_argument( "-t", ARG_THEME )
.default_value( std::string() )
.help( "Color theme to use (will default to pcbnew settings)" );
.help( UTF8STDSTR( _( "Color theme to use (will default to pcbnew settings)" ) ) );
m_argParser.add_argument( ARG_BLACKANDWHITE )
.help( "Black and white only" )
.help( UTF8STDSTR( _( "Black and white only" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_EXCLUDE_DRAWING_SHEET )
.help( "No drawing sheet" )
.help( UTF8STDSTR( _( "No drawing sheet" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_NO_BACKGROUND_COLOR )
.help( "Avoid setting a background color (regardless of theme)" )
.help( UTF8STDSTR( _( "Avoid setting a background color (regardless of theme)" ) ) )
.implicit_value( true )
.default_value( false );
}

View File

@ -232,7 +232,7 @@ int PGM_KICAD::OnPgmRun()
}
catch( const std::runtime_error& err )
{
std::cout << err.what() << std::endl;
wxPrintf( "%s\n", err.what() );
// find the correct argparser object to output the command usage info
COMMAND_ENTRY* cliCmd = nullptr;
@ -244,10 +244,16 @@ int PGM_KICAD::OnPgmRun()
}
}
// arg parser uses a stream overload for printing the help
// we want to intercept so we can wxString the utf8 contents
// because on windows our terminal codepage might not be utf8
std::stringstream ss;
if( cliCmd )
std::cout << cliCmd->handler->GetArgParser();
ss << cliCmd->handler->GetArgParser();
else
std::cout << argParser;
ss << argParser;
wxPrintf( FROM_UTF8( ss.str().c_str() ) );
return CLI::EXIT_CODES::ERR_ARGS;
}
@ -276,7 +282,10 @@ int PGM_KICAD::OnPgmRun()
}
else
{
std::cout << argParser;
std::stringstream ss;
ss << argParser;
wxPrintf( FROM_UTF8( ss.str().c_str() ) );
return CLI::EXIT_CODES::ERR_ARGS;
}
}