Skip to content

Commit

Permalink
Finished adding support to override ui language via config dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhaotix committed Jul 28, 2017
1 parent fac15c7 commit 159075c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions libpgmodeler_ui/src/generalconfigwidget.cpp
Expand Up @@ -323,6 +323,9 @@ void GeneralConfigWidget::loadConfiguration(void)
source_editor_edt->setText(config_params[ParsersAttributes::CONFIGURATION][ParsersAttributes::SOURCE_EDITOR_APP]);
source_editor_args_edt->setText(config_params[ParsersAttributes::CONFIGURATION][ParsersAttributes::SOURCE_EDITOR_ARGS]);

int ui_idx = ui_language_cmb->findData(config_params[ParsersAttributes::CONFIGURATION][ParsersAttributes::UI_LANGUAGE]);
ui_language_cmb->setCurrentIndex(ui_idx >= 0 ? ui_idx : 0);

for(QWidget *wgt : child_wgts)
wgt->blockSignals(false);

Expand Down
2 changes: 1 addition & 1 deletion libpgmodeler_ui/ui/generalconfigwidget.ui
Expand Up @@ -1262,7 +1262,7 @@
<item row="0" column="1">
<widget class="QComboBox" name="ui_language_cmb">
<property name="statusTip">
<string>Overrides the default user interface language defined by the system. Requires restarting the program.</string>
<string>Overrides the default user interface language defined by the system. Requires restarting the program. &lt;strong&gt;NOTE:&lt;/strong&gt; UI translations are third party collaborations. Any typo should be reported to their respective maintainers.</string>
</property>
</widget>
</item>
Expand Down
31 changes: 27 additions & 4 deletions main/src/application.cpp
Expand Up @@ -18,6 +18,7 @@
#include "application.h"
#include "globalattributes.h"
#include "messagebox.h"
#include "parsersattributes.h"

Application::Application(int &argc, char **argv) : QApplication(argc,argv)
{
Expand Down Expand Up @@ -62,15 +63,37 @@ Application::Application(int &argc, char **argv) : QApplication(argc,argv)
}
}

//Trying to identify if the user defined a custom UI language in the pgmodeler.conf file
QString conf_file = GlobalAttributes::CONFIGURATIONS_DIR +
GlobalAttributes::DIR_SEPARATOR +
GlobalAttributes::GENERAL_CONF +
GlobalAttributes::CONFIGURATION_EXT;
QFile input;
QString lang_id = QLocale::system().name();

input.setFileName(conf_file);

if(input.open(QFile::ReadOnly))
{
QString buf = QString(input.readAll());
QRegExp regexp = QRegExp(QString("(%1)(.*)(=)(\\\")(.)+(\\\")(\\\n)").arg(ParsersAttributes::UI_LANGUAGE));
int idx = regexp.indexIn(QString(buf));

//Extract the value of the ui-language attribute in the conf file
lang_id = buf.mid(idx, regexp.matchedLength());
lang_id.remove(ParsersAttributes::UI_LANGUAGE);
lang_id.remove(QChar('"')).remove(QChar('=')).remove(QChar('\n'));
}

//Tries to load the main ui translation according to the system's locale
main_translator=new QTranslator(this);
main_translator->load(QLocale::system().name(), GlobalAttributes::LANGUAGES_DIR);
main_translator->load(lang_id, GlobalAttributes::LANGUAGES_DIR);
this->installTranslator(main_translator);

//Trying to load plugins translations
dir_list=QDir(GlobalAttributes::PLUGINS_DIR +
GlobalAttributes::DIR_SEPARATOR,
QString("*"), QDir::Name, QDir::AllDirs | QDir::NoDotAndDotDot).entryList();
GlobalAttributes::DIR_SEPARATOR,
QString("*"), QDir::Name, QDir::AllDirs | QDir::NoDotAndDotDot).entryList();

while(!dir_list.isEmpty())
{
Expand All @@ -83,7 +106,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc,argv)
GlobalAttributes::DIR_SEPARATOR + QString("lang") +
GlobalAttributes::DIR_SEPARATOR;

plug_lang_file=plugin_name + QString(".") + QLocale::system().name();
plug_lang_file=plugin_name + QString(".") + lang_id;

//Check if the .qm file exists for the current plugin. If so create and install a translator
if(QFileInfo(plug_lang_dir + plug_lang_file + QString(".qm")).exists())
Expand Down

0 comments on commit 159075c

Please sign in to comment.