From 66d20609424af07d56f3fe30923420b8f6034a05 Mon Sep 17 00:00:00 2001
From: jean-pierre charras <jp.charras@wanadoo.fr>
Date: Sun, 16 Jun 2019 20:35:32 +0200
Subject: [PATCH] Partial fix for missing language selection menu.

The fix is partial because in the list of languages the menuitem corresponding to the selected language is not checked.
---
 common/CMakeLists.txt                   |   1 +
 common/languages_menu.cpp               |  77 ++++++++++++++
 common/pgm_base.cpp                     | 131 ++++++------------------
 cvpcb/menubar.cpp                       |  11 +-
 eeschema/libedit/menubar_libedit.cpp    |   2 +-
 eeschema/menubar.cpp                    |   6 +-
 gerbview/gerbview_frame.cpp             |   4 +
 gerbview/menubar.cpp                    |   3 +-
 include/menus_helpers.h                 |   6 ++
 include/pgm_base.h                      |  41 ++++++--
 kicad/menubar.cpp                       |  20 ++--
 pagelayout_editor/menubar.cpp           |   2 +-
 pagelayout_editor/pl_editor_frame.cpp   |   1 +
 pcb_calculator/CMakeLists.txt           |   1 +
 pcb_calculator/pcb_calculator_frame.cpp |   2 +-
 pcbnew/menubar_footprint_editor.cpp     |   2 +-
 pcbnew/menubar_pcb_editor.cpp           |   2 +-
 17 files changed, 180 insertions(+), 132 deletions(-)
 create mode 100644 common/languages_menu.cpp

diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index e235f97c7b..5b286473d7 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -309,6 +309,7 @@ set( COMMON_SRCS
     kiway_express.cpp
     kiway_holder.cpp
     kiway_player.cpp
+    languages_menu.cpp
     lib_id.cpp
     lib_table_base.cpp
     lib_table_keywords.cpp
diff --git a/common/languages_menu.cpp b/common/languages_menu.cpp
new file mode 100644
index 0000000000..374628d0b0
--- /dev/null
+++ b/common/languages_menu.cpp
@@ -0,0 +1,77 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 1992-2019 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+
+/**
+ * @file languages_menu.cpp
+ *
+ * @brief build the standard menu to show the list of available translations
+ */
+
+#include <fctsys.h>
+
+#include <pgm_base.h>
+#include <id.h>
+#include <tool/tool_interactive.h>
+#include <tool/conditional_menu.h>
+#include <bitmaps.h>
+
+
+extern LANGUAGE_DESCR LanguagesList[];
+
+
+/**
+ * Function AddMenuLanguageList
+ * creates a menu list for language choice, and add it as submenu to \a MasterMenu.
+ *
+ * @param aMasterMenu The main menu.
+ */
+
+void AddMenuLanguageList( CONDITIONAL_MENU* aMasterMenu, TOOL_INTERACTIVE* aControlTool )
+{
+    CONDITIONAL_MENU* langsMenu = new CONDITIONAL_MENU( false, aControlTool );
+    langsMenu->SetTitle( _( "Set Language" ) );
+    langsMenu->SetIcon( language_xpm );
+    aMasterMenu->AddMenu( langsMenu );
+    wxString tooltip;
+
+    // Fix me: find the way to return true for the menutitem having the same m_WX_Lang_Identifier
+    // value as Pgm().GetSelectedLanguageIdentifier()
+    auto isCurrentLanguage = [] ( const SELECTION& aSel )
+    {
+        return false;
+    };
+
+    for( unsigned ii = 0;  LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
+    {
+        wxString label;
+
+        if( LanguagesList[ii].m_DoNotTranslate )
+            label = LanguagesList[ii].m_Lang_Label;
+        else
+            label = wxGetTranslation( LanguagesList[ii].m_Lang_Label );
+
+        langsMenu->AddCheckItem( LanguagesList[ii].m_KI_Lang_Identifier,    // wxMenuItem wxID
+                                 label, tooltip, LanguagesList[ii].m_Lang_Icon,
+                                 isCurrentLanguage );
+    }
+}
diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp
index bb4e60707e..c8bd31288d 100644
--- a/common/pgm_base.cpp
+++ b/common/pgm_base.cpp
@@ -69,58 +69,13 @@ static const wxChar showEnvVarWarningDialog[] = wxT( "ShowEnvVarWarningDialog" )
 static const wxChar traceEnvVars[]     = wxT( "KIENVVARS" );
 
 
-FILE_HISTORY::FILE_HISTORY( size_t aMaxFiles, int aBaseFileId ) :
-        wxFileHistory( std::min( aMaxFiles, (size_t) MAX_FILE_HISTORY_SIZE ) )
-{
-    SetBaseId( aBaseFileId );
-}
-
-
-void FILE_HISTORY::SetMaxFiles( size_t aMaxFiles )
-{
-    m_fileMaxFiles = std::min( aMaxFiles, (size_t) MAX_FILE_HISTORY_SIZE );
-
-    size_t numFiles = m_fileHistory.size();
-
-    while( numFiles > m_fileMaxFiles )
-        RemoveFileFromHistory( --numFiles );
-}
-
-
 /**
- *   A small class to handle the list of existing translations.
- *   The locale translation is automatic.
- *   The selection of languages is mainly for maintainer's convenience
- *   To add a support to a new translation:
- *   create a new icon (flag of the country) (see Lang_Fr.xpm as an example)
- *   add a new item to s_Languages[].
- */
-struct LANGUAGE_DESCR
-{
-    /// wxWidgets locale identifier (See wxWidgets doc)
-    int         m_WX_Lang_Identifier;
-
-    /// KiCad identifier used in menu selection (See id.h)
-    int         m_KI_Lang_Identifier;
-
-    /// The menu language icons
-    BITMAP_DEF  m_Lang_Icon;
-
-    /// Labels used in menus
-    wxString    m_Lang_Label;
-
-    /// Set to true if the m_Lang_Label must not be translated
-    bool        m_DoNotTranslate;
-};
-
-
-/**
- * Variable s_Languages
+ * LanguagesList
  * Note: because this list is not created on the fly, wxTranslation
  * must be called when a language name must be displayed after translation.
  * Do not change this behavior, because m_Lang_Label is also used as key in config
  */
-static LANGUAGE_DESCR s_Languages[] =
+LANGUAGE_DESCR LanguagesList[] =
 {
     { wxLANGUAGE_DEFAULT,    ID_LANGUAGE_DEFAULT,    lang_def_xpm,  _( "Default" ) },
     { wxLANGUAGE_ENGLISH,    ID_LANGUAGE_ENGLISH,    lang_en_xpm, wxT( "English" ), true },
@@ -146,10 +101,29 @@ static LANGUAGE_DESCR s_Languages[] =
     { wxLANGUAGE_DUTCH,      ID_LANGUAGE_DUTCH,      lang_nl_xpm,   _( "Dutch" ) },
     { wxLANGUAGE_JAPANESE,   ID_LANGUAGE_JAPANESE,   lang_jp_xpm,   _( "Japanese" ) },
     { wxLANGUAGE_BULGARIAN,  ID_LANGUAGE_BULGARIAN,  lang_bg_xpm,   _( "Bulgarian" ) },
-    { wxLANGUAGE_LITHUANIAN, ID_LANGUAGE_LITHUANIAN, lang_lt_xpm,   _( "Lithuanian" ) }
+    { wxLANGUAGE_LITHUANIAN, ID_LANGUAGE_LITHUANIAN, lang_lt_xpm,   _( "Lithuanian" ) },
+    { 0, 0, lang_def_xpm,   "" }         // Sentinel
 };
 
 
+FILE_HISTORY::FILE_HISTORY( size_t aMaxFiles, int aBaseFileId ) :
+        wxFileHistory( std::min( aMaxFiles, (size_t) MAX_FILE_HISTORY_SIZE ) )
+{
+    SetBaseId( aBaseFileId );
+}
+
+
+void FILE_HISTORY::SetMaxFiles( size_t aMaxFiles )
+{
+    m_fileMaxFiles = std::min( aMaxFiles, (size_t) MAX_FILE_HISTORY_SIZE );
+
+    size_t numFiles = m_fileHistory.size();
+
+    while( numFiles > m_fileMaxFiles )
+        RemoveFileFromHistory( --numFiles );
+}
+
+
 PGM_BASE::PGM_BASE()
 {
     m_pgm_checker = NULL;
@@ -683,11 +657,11 @@ bool PGM_BASE::SetLanguage( bool first_time )
         m_common_settings->Read( languageCfgKey, &languageSel );
 
         // Search for the current selection
-        for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
+        for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
         {
-            if( s_Languages[ii].m_Lang_Label == languageSel )
+            if( LanguagesList[ii].m_Lang_Label == languageSel )
             {
-                setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
+                setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
                 break;
             }
         }
@@ -725,11 +699,11 @@ bool PGM_BASE::SetLanguage( bool first_time )
         wxString languageSel;
 
         // Search for the current selection language name
-        for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
+        for( unsigned ii = 0;  LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
         {
-            if( s_Languages[ii].m_WX_Lang_Identifier == m_language_id )
+            if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
             {
-                languageSel = s_Languages[ii].m_Lang_Label;
+                languageSel = LanguagesList[ii].m_Lang_Label;
                 break;
             }
         }
@@ -764,13 +738,13 @@ bool PGM_BASE::SetLanguage( bool first_time )
 void PGM_BASE::SetLanguageIdentifier( int menu_id )
 {
     wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
-                menu_id, (int)arrayDim( s_Languages ) );
+                menu_id, (int)arrayDim( LanguagesList )-1 );
 
-    for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
+    for( unsigned ii = 0;  LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
     {
-        if( menu_id == s_Languages[ii].m_KI_Lang_Identifier )
+        if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
         {
-            setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
+            setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
             break;
         }
     }
@@ -812,47 +786,6 @@ void PGM_BASE::SetLanguagePath()
 }
 
 
-void PGM_BASE::AddMenuLanguageList( wxMenu* MasterMenu )
-{
-    wxMenu*      menu = NULL;
-    wxMenuItem*  item = MasterMenu->FindItem( ID_LANGUAGE_CHOICE );
-
-    if( item )     // This menu exists, do nothing
-        return;
-
-    menu = new wxMenu;
-
-    for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
-    {
-        wxString label;
-
-        if( s_Languages[ii].m_DoNotTranslate )
-            label = s_Languages[ii].m_Lang_Label;
-        else
-            label = wxGetTranslation( s_Languages[ii].m_Lang_Label );
-
-        AddMenuItem( menu, s_Languages[ii].m_KI_Lang_Identifier,
-                     label, KiBitmap(s_Languages[ii].m_Lang_Icon ),
-                     wxITEM_CHECK );
-    }
-
-    AddMenuItem( MasterMenu, menu,
-                 ID_LANGUAGE_CHOICE,
-                 _( "Set Language" ),
-                 _( "Select application language (only for testing)" ),
-                 KiBitmap( language_xpm ) );
-
-    // Set Check mark on current selected language
-    for( unsigned ii = 0;  ii < arrayDim( s_Languages );  ii++ )
-    {
-        if( m_language_id == s_Languages[ii].m_WX_Lang_Identifier )
-            menu->Check( s_Languages[ii].m_KI_Lang_Identifier, true );
-        else
-            menu->Check( s_Languages[ii].m_KI_Lang_Identifier, false );
-    }
-}
-
-
 bool PGM_BASE::SetLocalEnvVariable( const wxString& aName, const wxString& aValue )
 {
     wxString env;
diff --git a/cvpcb/menubar.cpp b/cvpcb/menubar.cpp
index 33a6299249..ef8db00a3e 100644
--- a/cvpcb/menubar.cpp
+++ b/cvpcb/menubar.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
- * Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors.
+ * Copyright (C) 2004-2019 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
@@ -30,6 +30,7 @@
 #include <tool/common_control.h>
 #include "cvpcb_id.h"
 #include "cvpcb_mainframe.h"
+#include <menus_helpers.h>
 
 
 void CVPCB_MAINFRAME::ReCreateMenuBar()
@@ -44,11 +45,11 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
     //
     CONDITIONAL_MENU*   fileMenu = new CONDITIONAL_MENU( false, tool );
 
-    fileMenu->AddItem( ID_SAVE_PROJECT, 
+    fileMenu->AddItem( ID_SAVE_PROJECT,
                        _( "&Save Schematic\tCtrl+S" ),
                        _( "Save footprint associations in schematic symbol footprint fields" ),
                        save_xpm,                        SELECTION_CONDITIONS::ShowAlways );
-    
+
     fileMenu->Resolve();
 
     //-- Preferences menu -----------------------------------------------
@@ -63,14 +64,14 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
                         preference_xpm,                 SELECTION_CONDITIONS::ShowAlways );
 
     prefsMenu->AddSeparator();
-    prefsMenu->AddItem( ID_CVPCB_EQUFILES_LIST_EDIT, 
+    prefsMenu->AddItem( ID_CVPCB_EQUFILES_LIST_EDIT,
                         _( "Footprint &Association Files..." ),
                         _( "Configure footprint association file (.equ) list.  These files are "
                            "used to automatically assign footprint names from symbol values." ),
                         library_table_xpm,              SELECTION_CONDITIONS::ShowAlways );
 
     prefsMenu->AddSeparator();
-    Pgm().AddMenuLanguageList( prefsMenu );
+    AddMenuLanguageList( prefsMenu, tool );
 
     prefsMenu->Resolve();
 
diff --git a/eeschema/libedit/menubar_libedit.cpp b/eeschema/libedit/menubar_libedit.cpp
index 33ce380b62..a4fbdc547c 100644
--- a/eeschema/libedit/menubar_libedit.cpp
+++ b/eeschema/libedit/menubar_libedit.cpp
@@ -215,7 +215,7 @@ void LIB_EDIT_FRAME::ReCreateMenuBar()
                         preference_xpm,                    EE_CONDITIONS::ShowAlways );
 
     prefsMenu->AddSeparator();
-    Pgm().AddMenuLanguageList( prefsMenu );
+    AddMenuLanguageList( prefsMenu, selTool );
 
     prefsMenu->AddSeparator();
     prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp
index 41d2d7217b..fdf40f9681 100644
--- a/eeschema/menubar.cpp
+++ b/eeschema/menubar.cpp
@@ -33,7 +33,7 @@
 #include "eeschema_id.h"
 #include "sch_edit_frame.h"
 
-class CONDITIONAL_MENU;
+extern void AddMenuLanguageList( CONDITIONAL_MENU* aMasterMenu, TOOL_INTERACTIVE* aControlTool );
 
 
 void SCH_EDIT_FRAME::ReCreateMenuBar()
@@ -97,7 +97,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
     submenuImport->SetTitle( _( "Import" ) );
     submenuImport->SetIcon( import_xpm );
 
-    submenuImport->Add( _( "Footprint Association File..." ), 
+    submenuImport->Add( _( "Footprint Association File..." ),
                         _( "Back-import symbol footprint associations from .cmp file created by Pcbnew" ),
                         ID_BACKANNO_ITEMS, import_footprint_names_xpm );
 
@@ -314,7 +314,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
                         preference_xpm,                    EE_CONDITIONS::ShowAlways );
 
     prefsMenu->AddSeparator();
-    Pgm().AddMenuLanguageList( prefsMenu );
+    AddMenuLanguageList( prefsMenu, selTool );
 
     prefsMenu->AddSeparator();
     prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp
index 6c61659d89..5e0c2b71e2 100644
--- a/gerbview/gerbview_frame.cpp
+++ b/gerbview/gerbview_frame.cpp
@@ -51,6 +51,7 @@
 #include <tools/gerbview_control.h>
 #include <view/view.h>
 #include <gerbview_painter.h>
+#include <geometry/shape_poly_set.h>
 
 
 // Config keywords
@@ -87,6 +88,9 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ):
     m_displayMode   = 0;
     m_AboutTitle = "GerbView";
 
+    SHAPE_POLY_SET dummy;   // A ugly trick to force the linker to include
+                            // some methods in code and avoid link errors
+
     int fileHistorySize;
     Pgm().CommonSettings()->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize,
                                   DEFAULT_FILE_HISTORY_SIZE );
diff --git a/gerbview/menubar.cpp b/gerbview/menubar.cpp
index 23ee2b8adc..8f9b5a318c 100644
--- a/gerbview/menubar.cpp
+++ b/gerbview/menubar.cpp
@@ -35,6 +35,7 @@
 #include <tools/gerbview_selection_tool.h>
 #include <tools/gerbview_actions.h>
 
+
 void GERBVIEW_FRAME::ReCreateMenuBar()
 {
     GERBVIEW_SELECTION_TOOL* selTool = m_toolManager->GetTool<GERBVIEW_SELECTION_TOOL>();
@@ -254,7 +255,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
                               preference_xpm,                    SELECTION_CONDITIONS::ShowAlways );
 
     preferencesMenu->AddSeparator();
-    Pgm().AddMenuLanguageList( preferencesMenu );
+    AddMenuLanguageList( preferencesMenu, selTool );
 
     preferencesMenu->AddSeparator();
     preferencesMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
diff --git a/include/menus_helpers.h b/include/menus_helpers.h
index 773710042d..2bac0b44f2 100644
--- a/include/menus_helpers.h
+++ b/include/menus_helpers.h
@@ -35,6 +35,12 @@
 #include <wx/menuitem.h>
 #include <bitmaps.h>
 
+class CONDITIONAL_MENU;
+class TOOL_INTERACTIVE;
+
+void AddMenuLanguageList( CONDITIONAL_MENU* aMasterMenu, TOOL_INTERACTIVE* aControlTool );
+
+
 /**
  * Add a bitmap to a menuitem
  * @param aMenu is the menuitem.
diff --git a/include/pgm_base.h b/include/pgm_base.h
index dd056043ba..8c2a896bf8 100644
--- a/include/pgm_base.h
+++ b/include/pgm_base.h
@@ -37,6 +37,7 @@
 #include <wx/filehistory.h>
 #include <search_stack.h>
 #include <wx/gdicmn.h>
+#include <bitmaps_png/bitmap_def.h>
 
 
 ///@{
@@ -63,6 +64,32 @@ class wxApp;
 class wxMenu;
 class wxWindow;
 
+/**
+ *   A small class to handle the list of existing translations.
+ *   The locale translation is automatic.
+ *   The selection of languages is mainly for maintainer's convenience
+ *   To add a support to a new translation:
+ *   create a new icon (flag of the country) (see Lang_Fr.xpm as an example)
+ *   add a new item to s_Languages[].
+ */
+struct LANGUAGE_DESCR
+{
+    /// wxWidgets locale identifier (See wxWidgets doc)
+    int         m_WX_Lang_Identifier;
+
+    /// KiCad identifier used in menu selection (See id.h)
+    int         m_KI_Lang_Identifier;
+
+    /// The menu language icons
+    BITMAP_DEF  m_Lang_Icon;
+
+    /// Labels used in menus
+    wxString    m_Lang_Label;
+
+    /// Set to true if the m_Lang_Label must not be translated
+    bool        m_DoNotTranslate;
+};
+
 
 class FILE_HISTORY : public wxFileHistory
 {
@@ -236,15 +263,6 @@ public:
      */
     VTBL_ENTRY bool SetLanguage( bool first_time = false );
 
-    /**
-     * Function AddMenuLanguageList
-     * creates a menu list for language choice, and add it as submenu to \a MasterMenu.
-     *
-     * @param MasterMenu The main menu. The sub menu list will be accessible from the menu
-     *                   item with id ID_LANGUAGE_CHOICE
-     */
-    VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
-
     /**
      * Function SetLanguageIdentifier
      * sets in .m_language_id member the wxWidgets language identifier Id  from
@@ -255,6 +273,11 @@ public:
      */
     VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
 
+    /**
+     * @return the wxWidgets language identifier Id of the language currently selected
+     */
+    VTBL_ENTRY int GetSelectedLanguageIdentifier() const { return m_language_id; }
+
     VTBL_ENTRY void SetLanguagePath();
 
     /**
diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp
index b4eaf128f4..673499693d 100644
--- a/kicad/menubar.cpp
+++ b/kicad/menubar.cpp
@@ -65,10 +65,10 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
     fileMenu->AddItem( KICAD_MANAGER_ACTIONS::newFromTemplate, SELECTION_CONDITIONS::ShowAlways );
     fileMenu->AddItem( KICAD_MANAGER_ACTIONS::openProject,     SELECTION_CONDITIONS::ShowAlways );
     fileMenu->AddMenu( openRecentMenu,                         SELECTION_CONDITIONS::ShowAlways );
-    
+
     fileMenu->AddSeparator();
-    fileMenu->AddItem( ID_IMPORT_EAGLE_PROJECT, 
-                       _( "Import EAGLE Project..." ), 
+    fileMenu->AddItem( ID_IMPORT_EAGLE_PROJECT,
+                       _( "Import EAGLE Project..." ),
                        _( "Import EAGLE CAD XML schematic and board" ),
                        import_project_xpm,                     SELECTION_CONDITIONS::ShowAlways );
 
@@ -79,7 +79,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
                        zip_xpm,                                SELECTION_CONDITIONS::ShowAlways );
 
     fileMenu->AddItem( ID_READ_ZIP_ARCHIVE,
-                       _( "&Unarchive Project..." ),  
+                       _( "&Unarchive Project..." ),
                        _( "Unarchive project files from zip archive" ),
                        unzip_xpm,                              SELECTION_CONDITIONS::ShowAlways );
 
@@ -92,7 +92,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
     //-- View menu -----------------------------------------------------------
     //
     CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, controlTool );
-    
+
     viewMenu->AddItem( ACTIONS::zoomRedraw,                    SELECTION_CONDITIONS::ShowAlways );
 
     viewMenu->AddSeparator();
@@ -126,7 +126,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
     toolsMenu->AddItem( ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR,
                        _( "Edit Local File..." ), _( "Edit local file in text editor" ),
                        browse_files_xpm,                       SELECTION_CONDITIONS::ShowAlways );
-    
+
     toolsMenu->Resolve();
 
     //-- Preferences menu -----------------------------------------------
@@ -142,8 +142,8 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
                         preference_xpm,                 SELECTION_CONDITIONS::ShowAlways );
 
     prefsMenu->AddSeparator();
-    Pgm().AddMenuLanguageList( prefsMenu );
-    
+    AddMenuLanguageList( prefsMenu, controlTool );
+
     prefsMenu->Resolve();
 
     //-- Menubar -------------------------------------------------------------
@@ -204,14 +204,14 @@ void KICAD_MANAGER_FRAME::RecreateLauncher()
     else
         m_launcher = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
                                          KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
-    
+
     m_launcher->Add( KICAD_MANAGER_ACTIONS::editSchematic );
     m_launcher->Add( KICAD_MANAGER_ACTIONS::editSymbols );
 
     KiScaledSeparator( m_launcher, this );
     m_launcher->Add( KICAD_MANAGER_ACTIONS::editPCB );
     m_launcher->Add( KICAD_MANAGER_ACTIONS::editFootprints );
-    
+
     KiScaledSeparator( m_launcher, this );
     m_launcher->Add( KICAD_MANAGER_ACTIONS::viewGerbers );
     m_launcher->Add( KICAD_MANAGER_ACTIONS::convertImage );
diff --git a/pagelayout_editor/menubar.cpp b/pagelayout_editor/menubar.cpp
index a2f86a6356..ae0d4ab452 100644
--- a/pagelayout_editor/menubar.cpp
+++ b/pagelayout_editor/menubar.cpp
@@ -167,7 +167,7 @@ void PL_EDITOR_FRAME::ReCreateMenuBar()
                               preference_xpm,                SELECTION_CONDITIONS::ShowAlways );
 
     // Language submenu
-    Pgm().AddMenuLanguageList( preferencesMenu );
+    AddMenuLanguageList( preferencesMenu, selTool );
 
     //-- Menubar -----------------------------------------------------------
     //
diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp
index 1b45f0c42a..217ac383c9 100644
--- a/pagelayout_editor/pl_editor_frame.cpp
+++ b/pagelayout_editor/pl_editor_frame.cpp
@@ -54,6 +54,7 @@
 #include <invoke_pl_editor_dialog.h>
 #include <tools/pl_editor_control.h>
 
+
 BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
     EVT_CLOSE( PL_EDITOR_FRAME::OnCloseWindow )
     EVT_MENU( wxID_FILE, PL_EDITOR_FRAME::Files_io )
diff --git a/pcb_calculator/CMakeLists.txt b/pcb_calculator/CMakeLists.txt
index 2f66733343..df3c651e7b 100644
--- a/pcb_calculator/CMakeLists.txt
+++ b/pcb_calculator/CMakeLists.txt
@@ -69,6 +69,7 @@ target_link_libraries( pcb_calculator
     # There's way too much crap coming in from common yet.
     common
     gal
+    common
     ${wxWidgets_LIBRARIES}
     )
 
diff --git a/pcb_calculator/pcb_calculator_frame.cpp b/pcb_calculator/pcb_calculator_frame.cpp
index cc5f1bbd5b..1c114861ec 100644
--- a/pcb_calculator/pcb_calculator_frame.cpp
+++ b/pcb_calculator/pcb_calculator_frame.cpp
@@ -62,7 +62,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
     m_TWNested = false;
 
     SHAPE_POLY_SET dummy;   // A ugly trick to force the linker to include
-                            //some methods in code and avoid link errors
+                            // some methods in code and avoid link errors
 
     // Populate transline list ordered like in dialog menu list
     const static TRANSLINE_TYPE_ID tltype_list[8] =
diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp
index 73d9a8fe37..6e615ee530 100644
--- a/pcbnew/menubar_footprint_editor.cpp
+++ b/pcbnew/menubar_footprint_editor.cpp
@@ -281,7 +281,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar()
                         preference_xpm,                      SELECTION_CONDITIONS::ShowAlways );
 
     prefsMenu->AddSeparator();
-    Pgm().AddMenuLanguageList( prefsMenu );
+    AddMenuLanguageList( prefsMenu, selTool );
 
     prefsMenu->AddSeparator();
     prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics,   acceleratedGraphicsCondition );
diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp
index ed53ef5808..0b475b1c5a 100644
--- a/pcbnew/menubar_pcb_editor.cpp
+++ b/pcbnew/menubar_pcb_editor.cpp
@@ -491,7 +491,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
                         preference_xpm,                       SELECTION_CONDITIONS::ShowAlways );
 
     prefsMenu->AddSeparator();
-    Pgm().AddMenuLanguageList( prefsMenu );
+    AddMenuLanguageList( prefsMenu, selTool );
 
     prefsMenu->AddSeparator();
     prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );