ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

translation.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_TRANSLATION_H
00024 #define COMMON_TRANSLATION_H
00025 
00026 #include "common/array.h"
00027 #include "common/fs.h"
00028 #include "common/str.h"
00029 #include "common/singleton.h"
00030 #include "common/str-array.h"
00031 
00032 #ifdef USE_TRANSLATION
00033 
00034 namespace Common {
00035 
00036 class File;
00037 
00038 enum TranslationIDs {
00039     kTranslationAutodetectId = 0,
00040     kTranslationBuiltinId = 1000
00041 };
00042 
00043 struct TLanguage {
00044     const char *name;
00045     int id;
00046 
00047     TLanguage() : name(nullptr), id(0) {}
00048     TLanguage(const char *n, int i) : name(n), id(i) {}
00049 };
00050 
00051 bool operator<(const TLanguage &l, const TLanguage &r);
00052 
00053 typedef Array<TLanguage> TLangArray;
00054 
00055 struct PoMessageEntry {
00056     int msgid;
00057     String msgctxt;
00058     String msgstr;
00059 };
00060 
00064 class TranslationManager : public Singleton<TranslationManager> {
00065 public:
00070     TranslationManager();
00071     ~TranslationManager();
00072 
00079     String getLangById(int id) const;
00080 
00088     void setLanguage(const String &lang);
00089 
00096     void setLanguage(int id) {
00097         setLanguage(getLangById(id));
00098     }
00099 
00107     int parseLanguage(const String &lang) const;
00108 
00114     const char *getTranslation(const char *message) const;
00115 
00121     String getTranslation(const String &message) const;
00122 
00132     const char *getTranslation(const char *message, const char *context) const;
00133 
00143     String getTranslation(const String &message, const String &context) const;
00144 
00150     const TLangArray getSupportedLanguageNames() const;
00151 
00155     String getCurrentCharset() const;
00156 
00170     const uint32 *getCharsetMapping() const { return _charmap; }
00171 
00175     String getCurrentLanguage() const;
00176 
00177 private:
00185     int32 findMatchingLanguage(const String &lang);
00186 
00192     bool openTranslationsFile(File &);
00193 
00198     bool openTranslationsFile(const FSNode &node, File &, int depth = -1);
00199 
00203     void loadTranslationsInfoDat();
00204 
00210     void loadLanguageDat(int index);
00211 
00215     bool checkHeader(File &in);
00216 
00217     StringArray _langs;
00218     StringArray _langNames;
00219     StringArray _charmaps;
00220 
00221     StringArray _messageIds;
00222     Array<PoMessageEntry> _currentTranslationMessages;
00223     String _currentCharset;
00224     int _currentLang;
00225 
00226     uint32 _charmapStart;
00227     uint32 *_charmap;
00228 };
00229 
00230 } // End of namespace Common
00231 
00232 #define TransMan Common::TranslationManager::instance()
00233 
00234 #define _(str) TransMan.getTranslation(str)
00235 #define _c(str, context) TransMan.getTranslation(str, context)
00236 
00237 #else // !USE_TRANSLATION
00238 
00239 #define _(str) str
00240 #define _c(str, context) str
00241 
00242 #endif // USE_TRANSLATION
00243 
00244 #define _s(str) str
00245 #define _sc(str, ctxt) str
00246 #define DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(str, ctxt)
00247 
00248 #endif // COMMON_TRANSLATION_H


Generated on Sat Jul 20 2019 05:00:48 for ResidualVM by doxygen 1.7.1
curved edge   curved edge