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.
This commit is contained in:
parent
8288f24264
commit
20d1d0705e
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* 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) 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
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -35,18 +35,9 @@ using namespace TFIELD_T;
|
||||||
#define FOOTPRINT_CANONICAL "Footprint"
|
#define FOOTPRINT_CANONICAL "Footprint"
|
||||||
#define DATASHEET_CANONICAL "Datasheet"
|
#define DATASHEET_CANONICAL "Datasheet"
|
||||||
|
|
||||||
static std::mutex s_defaultFieldMutex;
|
const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx, bool aTranslateForHI )
|
||||||
|
|
||||||
const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx, bool aTranslate )
|
|
||||||
{
|
{
|
||||||
static void* locale = nullptr;
|
if( !aTranslateForHI )
|
||||||
static wxString referenceDefault;
|
|
||||||
static wxString valueDefault;
|
|
||||||
static wxString footprintDefault;
|
|
||||||
static wxString datasheetDefault;
|
|
||||||
static wxString fieldDefault;
|
|
||||||
|
|
||||||
if( !aTranslate )
|
|
||||||
{
|
{
|
||||||
switch( aFieldNdx )
|
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 VALUE_FIELD: return VALUE_CANONICAL; // The symbol value
|
||||||
case FOOTPRINT_FIELD: return FOOTPRINT_CANONICAL; // The footprint for use with Pcbnew
|
case FOOTPRINT_FIELD: return FOOTPRINT_CANONICAL; // The footprint for use with Pcbnew
|
||||||
case DATASHEET_FIELD: return DATASHEET_CANONICAL; // Link to a datasheet for symbol
|
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 )
|
switch( aFieldNdx )
|
||||||
{
|
{
|
||||||
case REFERENCE_FIELD: return referenceDefault; // The symbol reference, R1, C1, etc.
|
case REFERENCE_FIELD: return _( REFERENCE_CANONICAL ); // The symbol reference, R1, C1, etc.
|
||||||
case VALUE_FIELD: return valueDefault; // The symbol value
|
case VALUE_FIELD: return _( VALUE_CANONICAL ); // The symbol value
|
||||||
case FOOTPRINT_FIELD: return footprintDefault; // The footprint for use with Pcbnew
|
case FOOTPRINT_FIELD: return _( FOOTPRINT_CANONICAL ); // The footprint for use with Pcbnew
|
||||||
case DATASHEET_FIELD: return datasheetDefault; // Link to a datasheet for symbol
|
case DATASHEET_FIELD: return _( DATASHEET_CANONICAL ); // Link to a datasheet for symbol
|
||||||
default: return wxString::Format( fieldDefault, aFieldNdx );
|
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
|
void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,7 +100,7 @@ DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS( SCH_EDIT_FRAME* aParent, SCH_SYMBO
|
||||||
|
|
||||||
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
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 )
|
if( i == REFERENCE_FIELD )
|
||||||
m_fieldsBox->Check( i, g_selectRefDes );
|
m_fieldsBox->Check( i, g_selectRefDes );
|
||||||
|
|
|
@ -250,6 +250,10 @@ public:
|
||||||
if( aCol == QUANTITY_COLUMN )
|
if( aCol == QUANTITY_COLUMN )
|
||||||
return _( "Qty" );
|
return _( "Qty" );
|
||||||
else if( aCol < MANDATORY_FIELDS )
|
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 );
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aCol );
|
||||||
else
|
else
|
||||||
return m_fieldNames[ aCol ];
|
return m_fieldNames[ aCol ];
|
||||||
|
|
|
@ -855,7 +855,7 @@ void DIALOG_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
|
||||||
SCHEMATIC_SETTINGS& settings = m_symbol->Schematic()->Settings();
|
SCHEMATIC_SETTINGS& settings = m_symbol->Schematic()->Settings();
|
||||||
int fieldID = m_fields->size();
|
int fieldID = m_fields->size();
|
||||||
SCH_FIELD newField( wxPoint( 0, 0 ), fieldID, m_symbol,
|
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.SetTextAngle( m_fields->at( REFERENCE_FIELD ).GetTextAngle() );
|
||||||
newField.SetTextSize( wxSize( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
newField.SetTextSize( wxSize( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
||||||
|
|
|
@ -47,7 +47,7 @@ DIALOG_UPDATE_SYMBOL_FIELDS::DIALOG_UPDATE_SYMBOL_FIELDS( SYMBOL_EDIT_FRAME* aPa
|
||||||
|
|
||||||
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
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 );
|
m_fieldsBox->Check( i, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -476,7 +476,7 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
|
||||||
if( m_parentType == SCH_SYMBOL_T )
|
if( m_parentType == SCH_SYMBOL_T )
|
||||||
{
|
{
|
||||||
if( aRow < m_mandatoryFieldCount )
|
if( aRow < m_mandatoryFieldCount )
|
||||||
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aRow );
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aRow, DO_TRANSLATE );
|
||||||
else
|
else
|
||||||
return field.GetName( false );
|
return field.GetName( false );
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,10 +425,11 @@ wxString LIB_FIELD::GetCanonicalName() const
|
||||||
{
|
{
|
||||||
switch( m_id )
|
switch( m_id )
|
||||||
{
|
{
|
||||||
case REFERENCE_FIELD: return wxT( "Reference" );
|
case REFERENCE_FIELD:
|
||||||
case VALUE_FIELD: return wxT( "Value" );
|
case VALUE_FIELD:
|
||||||
case FOOTPRINT_FIELD: return wxT( "Footprint" );
|
case FOOTPRINT_FIELD:
|
||||||
case DATASHEET_FIELD: return wxT( "Datasheet" );
|
case DATASHEET_FIELD:
|
||||||
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_name;
|
return m_name;
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
void Init( int aId );
|
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
|
* The first four field IDs are reserved and therefore always return their respective
|
||||||
* names.
|
* names.
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) override;
|
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
|
* @param aUseDefaultName When true return the default field name if the field name is
|
||||||
* empty. Otherwise the default field name is returned.
|
* empty. Otherwise the default field name is returned.
|
||||||
|
|
|
@ -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 )
|
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" ) )
|
if( aName == wxT( "Intersheetrefs" ) )
|
||||||
return intersheetRefsDefault;
|
return _( "Sheet References" );
|
||||||
else if( aName == wxT( "Netclass" ) )
|
else if( aName == wxT( "Netclass" ) )
|
||||||
return netclassRefDefault;
|
return _( "Net Class" );
|
||||||
else if( aName.IsEmpty() && aUseDefaultName )
|
else if( aName.IsEmpty() && aUseDefaultName )
|
||||||
return userFieldDefault;
|
return _( "Field" );
|
||||||
else
|
else
|
||||||
return aName;
|
return aName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,11 +52,6 @@
|
||||||
|
|
||||||
const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx, bool aTranslated )
|
const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx, bool aTranslated )
|
||||||
{
|
{
|
||||||
static void* locale = nullptr;
|
|
||||||
static wxString sheetnameDefault;
|
|
||||||
static wxString sheetfilenameDefault;
|
|
||||||
static wxString userFieldDefault;
|
|
||||||
|
|
||||||
if( !aTranslated )
|
if( !aTranslated )
|
||||||
{
|
{
|
||||||
switch( aFieldNdx )
|
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
|
// Fixed values for the mandatory fields
|
||||||
switch( aFieldNdx )
|
switch( aFieldNdx )
|
||||||
{
|
{
|
||||||
case SHEETNAME: return sheetnameDefault;
|
case SHEETNAME: return _( SHEET_NAME_CANONICAL );
|
||||||
case SHEETFILENAME: return sheetfilenameDefault;
|
case SHEETFILENAME: return _( SHEET_FILE_CANONICAL );
|
||||||
default: return wxString::Format( userFieldDefault, aFieldNdx );
|
default: return wxString::Format( _( USER_FIELD_CANONICAL ), aFieldNdx );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* 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) 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
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -50,6 +50,9 @@ enum MANDATORY_FIELD_T {
|
||||||
MANDATORY_FIELDS
|
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.
|
* 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.
|
* These field names are not modifiable but template field names are.
|
||||||
*
|
*
|
||||||
* @param aFieldNdx The field number index, > 0.
|
* @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
|
wxString m_Name; // The field name
|
||||||
bool m_Visible; // Field defaults to being visible in schematic.
|
bool m_Visible; // Field defaults to being visible in schematic.
|
||||||
|
|
Loading…
Reference in New Issue