1 /*
2  i18n.cpp     MindForger thinking notebook
3 
4  Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "i18nl10n.h"
20 
21 namespace m8r {
22 
23 using namespace std;
24 
l10n(QApplication & mindforgerApplication)25 void l10n(QApplication& mindforgerApplication)
26 {
27     // Qt to delete translator
28     QTranslator* mfTranslator = new QTranslator();
29     QString translatorTargetAudience{};
30     if(Configuration::getInstance().isUiNerdTargetAudience()) {
31         translatorTargetAudience.append("nerd_");
32     }
33     // loader does fallback: :/translations/mindforger_us_EN.qm > :/translations/mindforger_us.qm
34     QString translationPath{":/translations/mindforger_"+translatorTargetAudience+QLocale::system().name()+".qm"};
35     MF_DEBUG("Loading locale " << translationPath.toStdString() << endl);
36     if(mfTranslator->load(translationPath)) {
37         if(!mindforgerApplication.installTranslator(mfTranslator)) {
38 #ifdef MF_DEBUG_L10N
39             cerr << "Error: unable to install translator " << translationPath.toStdString() << endl;
40 #endif
41         }
42     }
43 #ifdef MF_DEBUG_L10N
44     else {
45         cerr << "Error: unable to load translator " << translationPath.toStdString() << endl;
46     }
47 #endif
48 }
49 
50 } // m8r
51