Added logic for language translation

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/3/head
Michele Calgaro 2 years ago
parent b4d35ab97d
commit 64dc8cad72
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -18,3 +18,6 @@
// strstream support // strstream support
#cmakedefine HAVE_STRSTREAM #cmakedefine HAVE_STRSTREAM
// Need to undefine this to let TQt3's translator work properly
#undef TQT_NO_TRANSLATION

@ -32,11 +32,14 @@
///-- #include "UiGuiHighlighter.h" ///-- #include "UiGuiHighlighter.h"
///-- #include "IndentHandler.h" ///-- #include "IndentHandler.h"
#include <tqpixmap.h>
#include <tqaction.h> #include <tqaction.h>
#include <tqapplication.h>
#include <tqcheckbox.h> #include <tqcheckbox.h>
#include <tqlocale.h>
#include <tqpixmap.h>
#include <tqpopupmenu.h> #include <tqpopupmenu.h>
#include <tqpushbutton.h> #include <tqpushbutton.h>
#include <tqtranslator.h>
///-- #include <tqwidget.h> ///-- #include <tqwidget.h>
///-- #include <tqlabel.h> ///-- #include <tqlabel.h>
///-- #include <tqstring.h> ///-- #include <tqstring.h>
@ -50,8 +53,6 @@
///-- #include <tqcloseevent.h> ///-- #include <tqcloseevent.h>
///-- #include <tqhelpevent.h> ///-- #include <tqhelpevent.h>
///-- #include <tqtooltip.h> ///-- #include <tqtooltip.h>
///-- #include <tqtranslator.h>
///-- #include <tqlocale.h>
///-- #include <tqtextcodec.h> ///-- #include <tqtextcodec.h>
///-- #include <tqdate.h> ///-- #include <tqdate.h>
///-- #include <tqurl.h> ///-- #include <tqurl.h>
@ -65,6 +66,7 @@
// \defgroup grp_MainWindow All concerning main window functionality. // \defgroup grp_MainWindow All concerning main window functionality.
/* /*
\class MainWindow \class MainWindow
\ingroup grp_MainWindow \ingroup grp_MainWindow
@ -79,21 +81,22 @@
\brief Constructs the main window. \brief Constructs the main window.
*/ */
MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) :
MainWindowBase(parent), m_aboutDialog(NULL), m_qSciSourceCodeEditor(NULL) MainWindowBase(parent), m_aboutDialog(nullptr), m_qSciSourceCodeEditor(nullptr),
///- _mainWindowForm(NULL), _settings(NULL), m_qTranslator(nullptr), m_uiGuiTranslator(nullptr)
///- _highlighter(NULL), _textEditVScrollBar(NULL), _aboutDialogGraphicsView( ///- _mainWindowForm(nullptr), _settings(nullptr), _saveEncodedActionGroup(nullptr),
///- NULL), _settingsDialog(NULL), _encodingActionGroup(NULL), _saveEncodedActionGroup(NULL), ///- _highlighter(nullptr), _textEditVScrollBar(nullptr), _aboutDialogGraphicsView(
///- _highlighterActionGroup(NULL), _uiGuiTranslator(NULL), _qTTranslator(NULL), _toolBarWidget( ///- nullptr), _settingsDialog(nullptr), _encodingActionGroup(nullptr)
///- NULL), _indentHandler(NULL), _textEditLineColumnInfoLabel(NULL) ///- _highlighterActionGroup(nullptr), _toolBarWidget(
///- nullptr), _indentHandler(nullptr), _textEditLineColumnInfoLabel(nullptr)
{ {
// Init of some variables. // Init of some variables.
m_sourceCodeChanged = false; m_sourceCodeChanged = false;
// Create the _settings object, which loads all UiGui settings from a file. // Create the _settings object, which loads all UiGui settings from a file.
m_settings = UiGuiSettings::getInstance(); m_settings = UiGuiSettings::getInstance();
///--
///-- // Initialize the language of the application. // Initialize the language of the application.
///-- initApplicationLanguage(); initApplicationLanguage();
// Creates the main window and initializes it. // Creates the main window and initializes it.
initMainWindow(); initMainWindow();
@ -224,7 +227,6 @@ void MainWindow::initMainWindow()
connect(m_settings, SIGNAL(whiteSpaceIsVisible(bool)), connect(m_settings, SIGNAL(whiteSpaceIsVisible(bool)),
actionWhiteSpaceIsVisible, SLOT(setOn(bool))); actionWhiteSpaceIsVisible, SLOT(setOn(bool)));
actionWhiteSpaceIsVisible->setOn(m_settings->getValueByName("WhiteSpaceIsVisible").toBool()); actionWhiteSpaceIsVisible->setOn(m_settings->getValueByName("WhiteSpaceIsVisible").toBool());
// Tell the TQScintilla editor if it has to show white space. // Tell the TQScintilla editor if it has to show white space.
connect(m_settings, SIGNAL(whiteSpaceIsVisible(bool)), this, SLOT(setWhiteSpaceVisibility(bool))); connect(m_settings, SIGNAL(whiteSpaceIsVisible(bool)), this, SLOT(setWhiteSpaceVisibility(bool)));
@ -356,76 +358,75 @@ void MainWindow::initToolBar()
///-- _settings->registerObjectProperty(actionEnableSyntaxHighlighting, "checked", ///-- _settings->registerObjectProperty(actionEnableSyntaxHighlighting, "checked",
///-- "SyntaxHighlightingEnabled"); ///-- "SyntaxHighlightingEnabled");
///-- } ///-- }
///--
///-- /* /*
///-- \brief Initializes the language of UniversalIndentGUI. \brief Initializes the language of UniversalIndentGUI.
///--
///-- If the program language is defined in the _settings, the corresponding language If the program language is defined in the _settings, the corresponding language
///-- file will be loaded and set for the application. If not set there, the system file will be loaded and set for the application. If not set there, the system
///-- default language will be set, if a translation file for that language exists. default language will be set, if a translation file for that language exists.
///-- Returns true, if the translation file could be loaded. Otherwise it returns Returns true, if the translation file could be loaded. Otherwise it returns
///-- false and uses the default language, which is English. false and uses the default language, which is English.
///-- */ */
///-- bool MainWindow::initApplicationLanguage() bool MainWindow::initApplicationLanguage()
///-- { {
///-- TQString languageShort; TQString languageShort;
///--
///-- // Get the language _settings from the _settings object. // Get the language settings from the settings object.
///-- int languageIndex = _settings->getValueByName("language").toInt(); int languageIndex = m_settings->getValueByName("Language").toInt();
///--
///-- // If no language was set, indicated by a negative index, use the system language. // If no language was set, indicated by a negative index, use the system language.
///-- if (languageIndex < 0) if (languageIndex < 0)
///-- { {
///-- languageShort = TQLocale::system().name(); languageShort = TQLocale::system().name();
///--
///-- // Chinese and Japanese language consist of country and language code. // Chinese and Japanese language consist of country and language code.
///-- // For all others the language code will be cut off. // For all others the language code will be cut off.
///-- if (languageShort.left(2) != "zh" && languageShort.left(2) != "ja") if (languageShort.left(2) != "zh" && languageShort.left(2) != "ja")
///-- { {
///-- languageShort = languageShort.left(2); languageShort = languageShort.left(2);
///-- } }
///--
///-- // If no translation file for the systems local language exist, fall back to English. // If no translation file for the systems local language exist, fall back to English.
///-- if (_settings->getAvailableTranslations().indexOf(languageShort) < 0) if (m_settings->getAvailableTranslations().findIndex(languageShort) < 0)
///-- { {
///-- languageShort = "en"; languageShort = "en";
///-- } }
///--
///-- // Set the language setting to the new language. // Set the language setting to the new language.
///-- _settings->setValueByName("language", m_settings->setValueByName("Language",
///-- _settings->getAvailableTranslations().indexOf(languageShort)); m_settings->getAvailableTranslations().findIndex(languageShort));
///-- } }
///-- // If a language was defined in the _settings, get this language mnemonic. // If a language was defined in the m_settings, get this language mnemonic.
///-- else else
///-- { {
///-- languageShort = _settings->getAvailableTranslations().at(languageIndex); languageShort = m_settings->getAvailableTranslations()[languageIndex];
///-- } }
///--
///-- // Load the TQt own translation file and set it for the application. // Load the TQt own translation file and set it for the application.
///-- _qTTranslator = new TQTranslator(); m_qTranslator = new TQTranslator();
///-- bool translationFileLoaded; bool translationFileLoaded;
///-- translationFileLoaded = _qTTranslator->load( translationFileLoaded = m_qTranslator->load(SettingsPaths::getGlobalFilesPath() +
///-- SettingsPaths::getGlobalFilesPath() + "/translations/qt_" + languageShort); "/translations/qt_" + languageShort);
///-- if (translationFileLoaded) if (translationFileLoaded)
///-- { {
///-- tqApp->installTranslator(_qTTranslator); tqApp->installTranslator(m_qTranslator);
///-- } }
///--
///-- // Load the uigui translation file and set it for the application. // Load the uigui translation file and set it for the application.
///-- _uiGuiTranslator = new TQTranslator(); m_uiGuiTranslator = new TQTranslator();
///-- translationFileLoaded = _uiGuiTranslator->load( translationFileLoaded = m_uiGuiTranslator->load(SettingsPaths::getGlobalFilesPath() +
///-- SettingsPaths::getGlobalFilesPath() + "/translations/universalindent_" + languageShort); "/translations/universalindent_" + languageShort);
///-- if (translationFileLoaded) if (translationFileLoaded)
///-- { {
///-- tqApp->installTranslator(_uiGuiTranslator); tqApp->installTranslator(m_uiGuiTranslator);
///-- } }
///--
///-- //connect( _settings, SIGNAL(language(int)), this, SLOT(languageChanged(int)) ); connect(m_settings, SIGNAL(language(int)), this, SLOT(languageChanged(int)) );
///-- _settings->registerObjectSlot(this, "languageChanged(int)", "language");
///-- return translationFileLoaded;
///-- return translationFileLoaded; }
///-- }
///--
///-- /* ///-- /*
///-- \brief Creates and initializes the indenter. ///-- \brief Creates and initializes the indenter.
///-- */ ///-- */
@ -1166,42 +1167,42 @@ bool MainWindow::maybeSave()
return true; return true;
} }
///-- /* /*
///-- \brief This slot is called whenever a language is selected in the menu. It tries to find the \brief This slot is called whenever a language is selected in the menu. It tries to find the
///-- corresponding action in the languageInfoList and sets the language. corresponding action in the languageInfoList and sets the language.
///-- */ */
///-- void MainWindow::languageChanged(int languageIndex) void MainWindow::languageChanged(int languageIndex)
///-- { {
///-- if (languageIndex < _settings->getAvailableTranslations().size()) if (languageIndex >= 0 && languageIndex < m_settings->getAvailableTranslations().size())
///-- { {
///-- // Get the mnemonic of the new selected language. // Get the mnemonic of the new selected language.
///-- TQString languageShort = _settings->getAvailableTranslations().at(languageIndex); TQString languageShort = m_settings->getAvailableTranslations()[languageIndex];
///--
///-- // Remove the old qt translation. // Remove the old qt translation.
///-- tqApp->removeTranslator(_qTTranslator); tqApp->removeTranslator(m_qTranslator);
///--
///-- // Remove the old uigui translation. // Remove the old uigui translation.
///-- tqApp->removeTranslator(_uiGuiTranslator); tqApp->removeTranslator(m_uiGuiTranslator);
///--
///-- // Load the TQt own translation file and set it for the application. // Load the TQt own translation file and set it for the application.
///-- bool translationFileLoaded; bool translationFileLoaded;
///-- translationFileLoaded = _qTTranslator->load( translationFileLoaded = m_qTranslator->load(SettingsPaths::getGlobalFilesPath() +
///-- SettingsPaths::getGlobalFilesPath() + "/translations/qt_" + languageShort); "/translations/qt_" + languageShort);
///-- if (translationFileLoaded) if (translationFileLoaded)
///-- { {
///-- tqApp->installTranslator(_qTTranslator); tqApp->installTranslator(m_qTranslator);
///-- } }
///--
///-- // Load the uigui translation file and set it for the application. // Load the uigui translation file and set it for the application.
///-- translationFileLoaded = _uiGuiTranslator->load( translationFileLoaded = m_uiGuiTranslator->load(SettingsPaths::getGlobalFilesPath() +
///-- SettingsPaths::getGlobalFilesPath() + "/translations/universalindent_" + languageShort); "/translations/universalindent_" + languageShort);
///-- if (translationFileLoaded) if (translationFileLoaded)
///-- { {
///-- tqApp->installTranslator(_uiGuiTranslator); tqApp->installTranslator(m_uiGuiTranslator);
///-- } }
///-- } }
///-- } }
///--
///-- /* ///-- /*
///-- \brief Creates a menu entries in the file menu for opening and saving a file with different encodings. ///-- \brief Creates a menu entries in the file menu for opening and saving a file with different encodings.
///-- */ ///-- */

@ -35,9 +35,8 @@ class ToolBarWidget;
/// class TQLabel; /// class TQLabel;
/// class TQScrollBar; /// class TQScrollBar;
/// class TQActionGroup; /// class TQActionGroup;
/// class TQTranslator;
///
class TQextScintilla; class TQextScintilla;
class TQTranslator;
class MainWindow : public MainWindowBase class MainWindow : public MainWindowBase
@ -68,7 +67,7 @@ class MainWindow : public MainWindowBase
void previewTurnedOnOff(bool turnOn); void previewTurnedOnOff(bool turnOn);
void exportToPDF(); void exportToPDF();
void exportToHTML(); void exportToHTML();
///-- void languageChanged(int languageIndex); void languageChanged(int languageIndex);
///-- void encodingChanged(TQAction *encodingAction); ///-- void encodingChanged(TQAction *encodingAction);
///-- void numberOfLinesChanged(); ///-- void numberOfLinesChanged();
void updateRecentlyOpenedList(); void updateRecentlyOpenedList();
@ -86,7 +85,7 @@ class MainWindow : public MainWindowBase
bool maybeSave(); bool maybeSave();
///-- void createEncodingMenu(); ///-- void createEncodingMenu();
///-- void createHighlighterMenu(); ///-- void createHighlighterMenu();
///-- bool initApplicationLanguage(); bool initApplicationLanguage();
void initMainWindow(); void initMainWindow();
void initToolBar(); void initToolBar();
///-- void initTextEditor(); ///-- void initTextEditor();
@ -118,8 +117,8 @@ class MainWindow : public MainWindowBase
///-- TQActionGroup *_encodingActionGroup; ///-- TQActionGroup *_encodingActionGroup;
///-- TQActionGroup *_saveEncodedActionGroup; ///-- TQActionGroup *_saveEncodedActionGroup;
///-- TQActionGroup *_highlighterActionGroup; ///-- TQActionGroup *_highlighterActionGroup;
///-- TQTranslator *_uiGuiTranslator; TQTranslator *m_uiGuiTranslator;
///-- TQTranslator *_qTTranslator; TQTranslator *m_qTranslator;
///-- ///--
bool m_sourceCodeChanged; bool m_sourceCodeChanged;
///-- bool _indentSettingsChanged; ///-- bool _indentSettingsChanged;

@ -361,6 +361,10 @@ void UiGuiSettings::emitSignalForSetting(TQString settingName)
{ {
emit whiteSpaceIsVisible(m_settings[settingName].toBool()); emit whiteSpaceIsVisible(m_settings[settingName].toBool());
} }
else if (settingName == "Language")
{
emit language(m_settings[settingName].toInt());
}
} }
/* /*

@ -94,7 +94,7 @@ class UiGuiSettings : public TQObject
void whiteSpaceIsVisible(bool value); void whiteSpaceIsVisible(bool value);
// [++] void indenterParameterTooltipsEnabled(bool value); // [++] void indenterParameterTooltipsEnabled(bool value);
// [++] void tabWidth(int value); // [++] void tabWidth(int value);
// [++] void language(int value); void language(int value);
// [++] void lastUpdateCheck(TQDate value); // [++] void lastUpdateCheck(TQDate value);
// [++] void mainWindowState(TQByteArray value); // [++] void mainWindowState(TQByteArray value);

Loading…
Cancel
Save