From 20d1d0705e22429e40314a4219342238e133c035 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 12 May 2022 13:05:06 +0200 Subject: [PATCH] Fix a few issues related to field names and their translation. - Do not use translated field names outside strings displayed in dialogs. - fix code that does not work well with default locale. - fix some (not all) I18n issues in DIALOG_UPDATE_SYMBOL_FIELDS. --- common/template_fieldnames.cpp | 49 ++++--------------- eeschema/dialogs/dialog_change_symbols.cpp | 2 +- .../dialogs/dialog_symbol_fields_table.cpp | 4 ++ eeschema/dialogs/dialog_symbol_properties.cpp | 2 +- .../dialogs/dialog_update_symbol_fields.cpp | 2 +- eeschema/fields_grid_table.cpp | 2 +- eeschema/lib_field.cpp | 9 ++-- eeschema/lib_field.h | 2 +- eeschema/sch_field.h | 2 +- eeschema/sch_label.cpp | 21 ++------ eeschema/sch_sheet.cpp | 21 ++------ include/template_fieldnames.h | 10 ++-- 12 files changed, 37 insertions(+), 89 deletions(-) diff --git a/common/template_fieldnames.cpp b/common/template_fieldnames.cpp index 5c7c59bf1d..c4cee8eaa9 100644 --- a/common/template_fieldnames.cpp +++ b/common/template_fieldnames.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,18 +35,9 @@ using namespace TFIELD_T; #define FOOTPRINT_CANONICAL "Footprint" #define DATASHEET_CANONICAL "Datasheet" -static std::mutex s_defaultFieldMutex; - -const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx, bool aTranslate ) +const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx, bool aTranslateForHI ) { - static void* locale = nullptr; - static wxString referenceDefault; - static wxString valueDefault; - static wxString footprintDefault; - static wxString datasheetDefault; - static wxString fieldDefault; - - if( !aTranslate ) + if( !aTranslateForHI ) { switch( aFieldNdx ) { @@ -54,42 +45,20 @@ const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx, bool aTra case VALUE_FIELD: return VALUE_CANONICAL; // The symbol value case FOOTPRINT_FIELD: return FOOTPRINT_CANONICAL; // The footprint for use with Pcbnew case DATASHEET_FIELD: return DATASHEET_CANONICAL; // Link to a datasheet for symbol + default: return wxString::Format( wxT( "Field%d" ), aFieldNdx ); } } - // Mutex protection is needed so that multiple loader threads don't write to the static - // variables at once - std::lock_guard lock( s_defaultFieldMutex ); - - // Fetching translations can take a surprising amount of time when loading libraries, - // so only do it when necessary. - if( Pgm().GetLocale() != locale ) - { - referenceDefault = _( REFERENCE_CANONICAL ); - valueDefault = _( VALUE_CANONICAL ); - footprintDefault = _( FOOTPRINT_CANONICAL ); - datasheetDefault = _( DATASHEET_CANONICAL ); - fieldDefault = _( "Field%d" ); - locale = Pgm().GetLocale(); - } - - // Fixed values for the mandatory fields switch( aFieldNdx ) { - case REFERENCE_FIELD: return referenceDefault; // The symbol reference, R1, C1, etc. - case VALUE_FIELD: return valueDefault; // The symbol value - case FOOTPRINT_FIELD: return footprintDefault; // The footprint for use with Pcbnew - case DATASHEET_FIELD: return datasheetDefault; // Link to a datasheet for symbol - default: return wxString::Format( fieldDefault, aFieldNdx ); + case REFERENCE_FIELD: return _( REFERENCE_CANONICAL ); // The symbol reference, R1, C1, etc. + case VALUE_FIELD: return _( VALUE_CANONICAL ); // The symbol value + case FOOTPRINT_FIELD: return _( FOOTPRINT_CANONICAL ); // The footprint for use with Pcbnew + case DATASHEET_FIELD: return _( DATASHEET_CANONICAL ); // Link to a datasheet for symbol + default: return wxString::Format( _( "Field%d" ), aFieldNdx ); } - } -#undef REFERENCE_CANONICAL -#undef VALUE_CANONICAL -#undef FOOTPRINT_CANONICAL -#undef DATASHEET_CANONICAL - void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const { diff --git a/eeschema/dialogs/dialog_change_symbols.cpp b/eeschema/dialogs/dialog_change_symbols.cpp index b863a7e445..96a0f7390b 100644 --- a/eeschema/dialogs/dialog_change_symbols.cpp +++ b/eeschema/dialogs/dialog_change_symbols.cpp @@ -100,7 +100,7 @@ DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS( SCH_EDIT_FRAME* aParent, SCH_SYMBO for( int i = 0; i < MANDATORY_FIELDS; ++i ) { - m_fieldsBox->Append( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) ); + m_fieldsBox->Append( TEMPLATE_FIELDNAME::GetDefaultFieldName( i, DO_TRANSLATE ) ); if( i == REFERENCE_FIELD ) m_fieldsBox->Check( i, g_selectRefDes ); diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index a30707f1d1..18b5b3f0f1 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -250,6 +250,10 @@ public: if( aCol == QUANTITY_COLUMN ) return _( "Qty" ); else if( aCol < MANDATORY_FIELDS ) + // FIX ME: the column label should be displayed translated. + // but when translated, and the DATASHEET column is shown, a new field + // with the translated DATASHEET field name is added when saving fields + // return TEMPLATE_FIELDNAME::GetDefaultFieldName( aCol DO_TRANSLATE ); return TEMPLATE_FIELDNAME::GetDefaultFieldName( aCol ); else return m_fieldNames[ aCol ]; diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 1d546b89c5..4708d74d0a 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -855,7 +855,7 @@ void DIALOG_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event ) SCHEMATIC_SETTINGS& settings = m_symbol->Schematic()->Settings(); int fieldID = m_fields->size(); SCH_FIELD newField( wxPoint( 0, 0 ), fieldID, m_symbol, - TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID ) ); + TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID, DO_TRANSLATE ) ); newField.SetTextAngle( m_fields->at( REFERENCE_FIELD ).GetTextAngle() ); newField.SetTextSize( wxSize( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) ); diff --git a/eeschema/dialogs/dialog_update_symbol_fields.cpp b/eeschema/dialogs/dialog_update_symbol_fields.cpp index 1c31d724a1..b45c662441 100644 --- a/eeschema/dialogs/dialog_update_symbol_fields.cpp +++ b/eeschema/dialogs/dialog_update_symbol_fields.cpp @@ -47,7 +47,7 @@ DIALOG_UPDATE_SYMBOL_FIELDS::DIALOG_UPDATE_SYMBOL_FIELDS( SYMBOL_EDIT_FRAME* aPa for( int i = 0; i < MANDATORY_FIELDS; ++i ) { - m_fieldsBox->Append( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) ); + m_fieldsBox->Append( TEMPLATE_FIELDNAME::GetDefaultFieldName( i, DO_TRANSLATE ) ); m_fieldsBox->Check( i, true ); } diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index e93de918c2..2018e8664c 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -476,7 +476,7 @@ wxString FIELDS_GRID_TABLE::GetValue( int aRow, int aCol ) if( m_parentType == SCH_SYMBOL_T ) { if( aRow < m_mandatoryFieldCount ) - return TEMPLATE_FIELDNAME::GetDefaultFieldName( aRow ); + return TEMPLATE_FIELDNAME::GetDefaultFieldName( aRow, DO_TRANSLATE ); else return field.GetName( false ); } diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index c7a1980485..8baf7df7be 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -425,10 +425,11 @@ wxString LIB_FIELD::GetCanonicalName() const { switch( m_id ) { - case REFERENCE_FIELD: return wxT( "Reference" ); - case VALUE_FIELD: return wxT( "Value" ); - case FOOTPRINT_FIELD: return wxT( "Footprint" ); - case DATASHEET_FIELD: return wxT( "Datasheet" ); + case REFERENCE_FIELD: + case VALUE_FIELD: + case FOOTPRINT_FIELD: + case DATASHEET_FIELD: + return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id ); } return m_name; diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index f7e44f9f40..1717845ae5 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -85,7 +85,7 @@ public: void Init( int aId ); /** - * Return the field name. + * Return the field name (not translated). * * The first four field IDs are reserved and therefore always return their respective * names. diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 26d655a74d..33a537f4ac 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -96,7 +96,7 @@ public: void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) override; /** - * Return the field name. + * Return the field name (not translated).. * * @param aUseDefaultName When true return the default field name if the field name is * empty. Otherwise the default field name is returned. diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index f931002cce..0b9d77eb03 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -179,27 +179,12 @@ SCH_LABEL_BASE::SCH_LABEL_BASE( const SCH_LABEL_BASE& aLabel ) : const wxString SCH_LABEL_BASE::GetDefaultFieldName( const wxString& aName, bool aUseDefaultName ) { - static void* locale = nullptr; - static wxString intersheetRefsDefault; - static wxString netclassRefDefault; - static wxString userFieldDefault; - - // Fetching translations can take a surprising amount of time when loading libraries, - // so only do it when necessary. - if( Pgm().GetLocale() != locale ) - { - intersheetRefsDefault = _( "Sheet References" ); - netclassRefDefault = _( "Net Class" ); - userFieldDefault = _( "Field" ); - locale = Pgm().GetLocale(); - } - if( aName == wxT( "Intersheetrefs" ) ) - return intersheetRefsDefault; + return _( "Sheet References" ); else if( aName == wxT( "Netclass" ) ) - return netclassRefDefault; + return _( "Net Class" ); else if( aName.IsEmpty() && aUseDefaultName ) - return userFieldDefault; + return _( "Field" ); else return aName; } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 94e03934c1..2a582a3b01 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -52,11 +52,6 @@ const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx, bool aTranslated ) { - static void* locale = nullptr; - static wxString sheetnameDefault; - static wxString sheetfilenameDefault; - static wxString userFieldDefault; - if( !aTranslated ) { switch( aFieldNdx ) @@ -67,22 +62,12 @@ const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx, bool aTranslated ) } } - // Fetching translations can take a surprising amount of time when loading libraries, - // so only do it when necessary. - if( Pgm().GetLocale() != locale ) - { - sheetnameDefault = _( SHEET_NAME_CANONICAL ); - sheetfilenameDefault = _( SHEET_FILE_CANONICAL ); - userFieldDefault = _( USER_FIELD_CANONICAL ); - locale = Pgm().GetLocale(); - } - // Fixed values for the mandatory fields switch( aFieldNdx ) { - case SHEETNAME: return sheetnameDefault; - case SHEETFILENAME: return sheetfilenameDefault; - default: return wxString::Format( userFieldDefault, aFieldNdx ); + case SHEETNAME: return _( SHEET_NAME_CANONICAL ); + case SHEETFILENAME: return _( SHEET_FILE_CANONICAL ); + default: return wxString::Format( _( USER_FIELD_CANONICAL ), aFieldNdx ); } } diff --git a/include/template_fieldnames.h b/include/template_fieldnames.h index efa16dd0ee..ea4d8171ba 100644 --- a/include/template_fieldnames.h +++ b/include/template_fieldnames.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2014-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -50,6 +50,9 @@ enum MANDATORY_FIELD_T { MANDATORY_FIELDS }; +// A helper to call GetDefaultFieldName with or without translation. +// Translation should be used only to display field names in dialogs +#define DO_TRANSLATE true /** * Hold a name of a symbol's field, field value, and default visibility. @@ -103,9 +106,10 @@ struct TEMPLATE_FIELDNAME * These field names are not modifiable but template field names are. * * @param aFieldNdx The field number index, > 0. - * @param aTranslate If true, return the translated field name, else get the canonical name. + * @param aTranslateForHI If true, return the translated field name, + * else get the canonical name (defualt). Translation is intended only for dialogs */ - static const wxString GetDefaultFieldName( int aFieldNdx, bool aTranslate = true ); + static const wxString GetDefaultFieldName( int aFieldNdx, bool aTranslateForHI = false ); wxString m_Name; // The field name bool m_Visible; // Field defaults to being visible in schematic.