ScummVM API documentation
translation.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef COMMON_TRANSLATION_H
23 #define COMMON_TRANSLATION_H
24 
25 #include "common/array.h"
26 #include "common/fs.h"
27 #include "common/str.h"
28 #include "common/singleton.h"
29 #include "common/str-array.h"
30 #include "common/language.h"
31 
32 #ifdef USE_TRANSLATION
33 
34 namespace Common {
35 
45 class File;
46 
53 };
54 
58 struct TLanguage {
60  int id;
62  TLanguage() : id(0) {}
63 
67  TLanguage(const U32String &n, int i) : name(n), id(i) {}
68 };
69 
70 bool operator<(const TLanguage &l, const TLanguage &r);
71 
73 
78  int msgid;
82 };
83 
88 public:
94  TranslationManager(const Common::String &fileName);
96 
104  String getLangById(int id) const;
105 
115  void setLanguage(const String &lang);
116 
123  void setLanguage(int id) {
124  setLanguage(getLangById(id));
125  }
126 
135  int parseLanguage(const String &lang) const;
136 
143  U32String getTranslation(const char *message) const;
144 
151  U32String getTranslation(const String &message) const;
152 
163  U32String getTranslation(const char *message, const char *context) const;
164 
175  U32String getTranslation(const String &message, const String &context) const;
176 
182  const TLangArray getSupportedLanguageNames() const;
183 
187  String getCurrentLanguage() const;
188 
192  int getCurrentLanguageId() const;
193 
197  bool currentIsBuiltinLanguage() const;
198 
199 private:
208  int32 findMatchingLanguage(const String &lang);
209 
216  bool openTranslationsFile(File &);
217 
223  bool openTranslationsFile(const FSNode &node, File &, int depth = -1);
224 
228  void loadTranslationsInfoDat(const Common::String &name);
229 
235  void loadLanguageDat(int index);
236 
240  bool checkHeader(File &in);
241 
242  StringArray _langs;
243  StringArray _langNames;
244 
245  StringArray _messageIds;
246  Array<PoMessageEntry> _currentTranslationMessages;
247  int _currentLang;
248  Common::String _translationsFileName;
249 };
250 
251 class MainTranslationManager : public TranslationManager, public Singleton<MainTranslationManager> {
252 public:
253  MainTranslationManager() : TranslationManager("translations.dat") {}
255 };
256 
259 } // End of namespace Common
260 
261 #define TransMan Common::MainTranslationManager::instance()
262 
263 #define _(str) TransMan.getTranslation(str)
264 #define _c(str, context) TransMan.getTranslation(str, context)
265 
266 #else // !USE_TRANSLATION
267 
268 #define _(str) Common::U32String(str)
269 #define _c(str, context) Common::U32String(str)
270 
271 #endif // USE_TRANSLATION
272 
273 #define _s(str) str
274 #define _sc(str, ctxt) str
275 #define DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(str, ctxt)
276 
277 #endif // COMMON_TRANSLATION_H
U32String name
Definition: translation.h:59
Definition: str.h:59
int msgid
Definition: translation.h:78
Language parseLanguage(const String &str)
Definition: array.h:52
String msgstr
Definition: translation.h:81
Definition: translation.h:52
Definition: translation.h:77
void setLanguage(int id)
Definition: translation.h:123
Definition: translation.h:51
Definition: noncopyable.h:39
Definition: ustr.h:57
Definition: file.h:47
Definition: translation.h:58
Definition: algorithm.h:29
Definition: fs.h:69
Definition: translation.h:87
String msgctxt
Definition: translation.h:79
Definition: translation.h:251
int id
Definition: translation.h:60
TLanguage(const U32String &n, int i)
Definition: translation.h:67
Definition: singleton.h:42
TranslationIDs
Definition: translation.h:50