localization.h
1 //------------------------------------------------------------------------------
2 // localization.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2012 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef DOOMSEEKER_LOCALIZATION_H
24 #define DOOMSEEKER_LOCALIZATION_H
25 
26 #include "localizationinfo.h"
27 
28 #include <QIODevice>
29 #include <QList>
30 #include <QString>
31 #include <QTranslator>
32 
34 {
35 public:
36  QList<LocalizationInfo> localizations;
37 
38  static Localization *get();
39 
44  LocalizationInfo coerceBestMatchingLocalization(const QString &localeName) const;
45  const LocalizationInfo &currentLocalization() const;
46 
47  bool isCurrentlyLoaded(const QString &localeName) const;
48  bool loadTranslation(const QString &localeName);
49  QList<LocalizationInfo> loadLocalizationsList(const QStringList &definitionsFileSearchDirs);
50 
51 private:
52  class LocalizationLoader;
53 
54  static Localization *instance;
55 
56  Localization();
57 
58  QList<QTranslator *> currentlyLoadedTranslations;
59  LocalizationInfo currentLocalization_;
60 
61  void installQtTranslations(const QString &localeName, QStringList searchPaths);
62  bool installTranslation(const QString &translationName, const QStringList &searchPaths);
63  QTranslator *loadTranslationFile(const QString &translationName, const QStringList &searchPaths);
64 };
65 
66 #endif