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.

(cherry picked from commit 20d1d0705e)
This commit is contained in:
jean-pierre charras 2022-05-12 13:05:06 +02:00 committed by Seth Hillbrand
parent 8af64fb326
commit 9ac87132af
11 changed files with 34 additions and 71 deletions

View File

@ -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 <dick@softplc.com>
* 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<std::mutex> 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
{

View File

@ -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 );

View File

@ -233,6 +233,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 ];

View File

@ -867,7 +867,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 ) );

View File

@ -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 );
}

View File

@ -389,7 +389,7 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
if( aRow < m_mandatoryFieldCount )
{
if( m_parentType == SCH_SYMBOL_T )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aRow );
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aRow, DO_TRANSLATE );
else if( m_parentType == SCH_SHEET_T )
return SCH_SHEET::GetDefaultFieldName( aRow );
}

View File

@ -403,10 +403,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;

View File

@ -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.

View File

@ -94,7 +94,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.

View File

@ -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 );
}
}

View File

@ -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 <dick@softplc.com>
* 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.