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
34namespace Common {
35
45class File;
46
53};
54
58struct TLanguage {
60 int id;
62 TLanguage() : id(0) {}
63
67 TLanguage(const U32String &n, int i) : name(n), id(i) {}
68};
69
70bool operator<(const TLanguage &l, const TLanguage &r);
71
72typedef Array<TLanguage> TLangArray;
73
78 int msgid;
82};
83
88public:
96
104 String getLangById(int id) const;
105
115 void setLanguage(const String &lang);
116
123 void setLanguage(int 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
184 U32String getTranslation(uint32 index) const;
185
192
199
204
209
214
215private:
224 int32 findMatchingLanguage(const String &lang);
225
232 bool openTranslationsFile(File &);
233
239 bool openTranslationsFile(const FSNode &node, File &, int depth = -1);
240
244 void loadTranslationsInfoDat(const Common::String &name);
245
251 void loadLanguageDat(int index);
252
256 bool checkHeader(File &in);
257
264 U32String getPoTranslation(const char *message) const;
265 U32String getPoTranslation(const char *message, const char *context) const;
266
272 bool loadLanguagePo(int index);
273
274 StringArray _langs;
275 StringArray _langNames;
276
277 StringArray _messageIds;
278 Array<PoMessageEntry> _currentTranslationMessages;
279 int _currentLang;
280 Common::String _translationsFileName;
281 bool _havePoDirectory;
282 bool _usingPo;
283 HashMap<Common::String, int> _poTranslations;
284};
285
286class MainTranslationManager : public TranslationManager, public Singleton<MainTranslationManager> {
287public:
288 MainTranslationManager() : TranslationManager("translations.dat") {}
290};
291
294} // End of namespace Common
295
296#define TransMan Common::MainTranslationManager::instance()
297
298#define _(str) TransMan.getTranslation(str)
299#define _c(str, context) TransMan.getTranslation(str, context)
300
301#else // !USE_TRANSLATION
302
303#define _(str) Common::U32String(str)
304#define _c(str, context) Common::U32String(str)
305
306#endif // USE_TRANSLATION
307
308#define _s(str) str
309#define _sc(str, ctxt) str
310#define DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(str, ctxt)
311
312#endif // COMMON_TRANSLATION_H
Definition: fs.h:69
Definition: file.h:47
Definition: translation.h:286
Definition: noncopyable.h:39
Definition: singleton.h:42
Definition: str.h:59
Definition: translation.h:87
String getLangById(int id) const
int parseLanguage(const String &lang) const
U32String getTranslation(const char *message, const char *context) const
U32String getTranslation(const String &message, const String &context) const
const StringArray getContexts() const
bool currentIsBuiltinLanguage() const
void setLanguage(int id)
Definition: translation.h:123
TranslationManager(const Common::String &fileName)
const TLangArray getSupportedLanguageNames() const
U32String getTranslation(uint32 index) const
U32String getTranslation(const String &message) const
void setLanguage(const String &lang)
U32String getTranslation(const char *message) const
String getCurrentLanguage() const
int getCurrentLanguageId() const
Definition: ustr.h:57
TranslationIDs
Definition: translation.h:50
@ kTranslationBuiltinId
Definition: translation.h:52
@ kTranslationAutodetectId
Definition: translation.h:51
Definition: algorithm.h:29
Definition: translation.h:77
int msgid
Definition: translation.h:78
String msgstr
Definition: translation.h:81
String msgctxt
Definition: translation.h:79
Definition: translation.h:58
TLanguage(const U32String &n, int i)
Definition: translation.h:67
U32String name
Definition: translation.h:59
int id
Definition: translation.h:60