1 /************************************************************************
2 **
3 **  Copyright (C) 2016  Kevin B. Hendricks, Stratford, ON, Canada
4 **  Copyright (C) 2011  John Schember <john@nachtimwald.com>
5 **
6 **  This file is part of Sigil.
7 **
8 **  Sigil is free software: you can redistribute it and/or modify
9 **  it under the terms of the GNU General Public License as published by
10 **  the Free Software Foundation, either version 3 of the License, or
11 **  (at your option) any later version.
12 **
13 **  Sigil is distributed in the hope that it will be useful,
14 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 **  GNU General Public License for more details.
17 **
18 **  You should have received a copy of the GNU General Public License
19 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
20 **
21 *************************************************************************/
22 
23 #pragma once
24 #ifndef LANGUAGE_H
25 #define LANGUAGE_H
26 
27 #include <QString>
28 #include <QStringList>
29 #include <QtCore/QCoreApplication>
30 #include <QtCore/QHash>
31 #include "Misc/DescriptiveInfo.h"
32 
33 /**
34  * Singleton.
35  *
36  * Language routines
37  */
38 class Language
39 {
40     Q_DECLARE_TR_FUNCTIONS(Language)
41 
42 public:
43     static Language *instance();
44 
45     QString GetLanguageName(QString language_code, QString ow=QString() );
46     QString GetLanguageCode(QString language_name, QString ow=QString() );
47     QStringList GetSortedPrimaryLanguageNames();
48     const QHash<QString, DescriptiveInfo> & GetLangMap();
49 
50 private:
51     Language();
52 
53     void SetLanguageMap();
54 
55     // Use hash since order is not important (sort later)
56     QHash<QString, QString> m_languageCodeMap;
57     QHash<QString, QString> m_languageNameMap;
58     QHash<QString, DescriptiveInfo> m_LangInfo;
59 
60     QStringList m_sortedPrimaryLanguageNames;
61 
62     static Language *m_instance;
63 };
64 
65 #endif // LANGUAGE_H
66