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 #include "common/language.h"
00032 
00033 #ifdef USE_TRANSLATION
00034 
00035 namespace Common {
00036 
00037 class File;
00038 
00039 enum TranslationIDs {
00040     kTranslationAutodetectId = 0,
00041     kTranslationBuiltinId = 1000
00042 };
00043 
00044 struct TLanguage {
00045     const char *name;
00046     int id;
00047 
00048     TLanguage() : name(nullptr), id(0) {}
00049     TLanguage(const char *n, int i) : name(n), id(i) {}
00050 };
00051 
00052 bool operator<(const TLanguage &l, const TLanguage &r);
00053 
00054 typedef Array<TLanguage> TLangArray;
00055 
00056 struct PoMessageEntry {
00057     int msgid;
00058     String msgctxt;
00059     String msgstr;
00060 };
00061 
00065 class TranslationManager : public Singleton<TranslationManager> {
00066 public:
00071     TranslationManager();
00072     ~TranslationManager();
00073 
00080     String getLangById(int id) const;
00081 
00089     void setLanguage(const String &lang);
00090 
00097     void setLanguage(int id) {
00098         setLanguage(getLangById(id));
00099     }
00100 
00108     int parseLanguage(const String &lang) const;
00109 
00115     const char *getTranslation(const char *message) const;
00116 
00122     String getTranslation(const String &message) const;
00123 
00133     const char *getTranslation(const char *message, const char *context) const;
00134 
00144     String getTranslation(const String &message, const String &context) const;
00145 
00151     const TLangArray getSupportedLanguageNames() const;
00152 
00156     String getCurrentCharset() const;
00157 
00171     const uint32 *getCharsetMapping() const { return _charmap; }
00172 
00176     String getCurrentLanguage() const;
00177 
00178     /*
00179      * Wrapper for GNU FriBidi implementation of the Unicode Bidirectional Algorithm
00180      * For LTR (Left To Right) languages, returns the original input
00181      * For RTL (Right To Left) languages, returns visual representation of a logical single-line input
00182      */
00183     String convertBiDiString(const String &input);
00184 
00185 private:
00193     int32 findMatchingLanguage(const String &lang);
00194 
00200     bool openTranslationsFile(File &);
00201 
00206     bool openTranslationsFile(const FSNode &node, File &, int depth = -1);
00207 
00211     void loadTranslationsInfoDat();
00212 
00218     void loadLanguageDat(int index);
00219 
00223     bool checkHeader(File &in);
00224 
00225     StringArray _langs;
00226     StringArray _langNames;
00227     StringArray _charmaps;
00228 
00229     StringArray _messageIds;
00230     Array<PoMessageEntry> _currentTranslationMessages;
00231     String _currentCharset;
00232     int _currentLang;
00233 
00234     uint32 _charmapStart;
00235     uint32 *_charmap;
00236 };
00237 
00238 } // End of namespace Common
00239 
00240 #define TransMan Common::TranslationManager::instance()
00241 
00242 #define _(str) TransMan.getTranslation(str)
00243 #define _c(str, context) TransMan.getTranslation(str, context)
00244 
00245 #else // !USE_TRANSLATION
00246 
00247 #define _(str) str
00248 #define _c(str, context) str
00249 
00250 #endif // USE_TRANSLATION
00251 
00252 #define _s(str) str
00253 #define _sc(str, ctxt) str
00254 #define DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(str, ctxt)
00255 
00256 #endif // COMMON_TRANSLATION_H


Generated on Sat Jul 4 2020 05:01:14 for ResidualVM by doxygen 1.7.1
curved edge   curved edge