1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
#ifndef _KVI_LOCALE_H_
#define _KVI_LOCALE_H_
//=============================================================================
//
// File : kvi_locale.h
// Creation date : Sat Jan 16 1999 18:15:01 by Szymon Stefanek
//
// This file is part of the KVirc irc client distribution
// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
//
// This program is FREE software. You can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your opinion) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================
#include "kvi_settings.h"
#include "kvi_qstring.h"
#include "kvi_string.h"
#include "kvi_pointerhashtable.h"
#include <qapplication.h>
class QTextCodec;
class KviMessageCatalogue;
namespace KviLocale
{
typedef struct _EncodingDescription
{
char * szName;
char bSmart; // is it a smart codec ?
char bSendUtf8; // does it send utf8 or the local charset ?
char * szDescription;
} EncodingDescription;
// you MUST start iterating from 0 and terminate when
// you get an entry with a NULL szName
KVILIB_API EncodingDescription * encodingDescription(int iIdx);
KVILIB_API QTextCodec * codecForName(const char * szName);
KVILIB_API const KviStr & localeName();
KVILIB_API bool findCatalogue(QString &szBuffer,const QString& name,const QString& szLocaleDir);
KVILIB_API bool loadCatalogue(const QString& name,const QString& szLocaleDir);
KVILIB_API KviMessageCatalogue * getLoadedCatalogue(const QString& name);
KVILIB_API bool unloadCatalogue(const QString& name);
KVILIB_API void init(QApplication * app,const QString& localeDir);
KVILIB_API void done(QApplication * app);
KVILIB_API const char * translate(const char * text,const char * context);
KVILIB_API const QString & translateToQString(const char * text,const char * context);
};
// not exported
class KviTranslationEntry
{
public:
KviStr m_szKey;
KviStr m_szEncodedTranslation;
QString * m_pQTranslation;
public:
KviTranslationEntry(char * keyptr,int keylen,char * trptr,int trlen)
: m_szKey(keyptr,keylen) , m_szEncodedTranslation(trptr,trlen)
{
m_pQTranslation = 0;
}
KviTranslationEntry(const char * keyandtr)
: m_szKey(keyandtr) , m_szEncodedTranslation(keyandtr)
{
m_pQTranslation = 0;
}
~KviTranslationEntry()
{
if(m_pQTranslation)delete m_pQTranslation;
}
};
class KVILIB_API KviMessageCatalogue
{
public:
KviMessageCatalogue();
~KviMessageCatalogue();
protected:
//KviPointerHashTable<const char *,KviTranslationEntry> * m_pMessages;
KviPointerHashTable<const char *,KviTranslationEntry> * m_pMessages;
QTextCodec * m_pTextCodec;
public:
bool load(const QString& name);
const char * translate(const char * text);
const QString & translateToQString(const char * text);
};
#ifndef _KVI_LOCALE_CPP_
extern KVILIB_API KviMessageCatalogue * g_pMainCatalogue;
#endif // !_KVI_LOCALE_CPP_
#define __tr(__text__) g_pMainCatalogue->translate(__text__)
#define __tr_no_lookup(__text__) __text__
#define __tr_no_xgettext(__text__) g_pMainCatalogue->translate(__text__)
#define __tr2qs(__text__) g_pMainCatalogue->translateToQString(__text__)
#define __tr2qs_no_xgettext(__text__) g_pMainCatalogue->translateToQString(__text__)
#define __tr_ctx(__text__,__context__) KviLocale::translate(__text__,__context__)
#define __tr_no_lookup_ctx(__text__,__context__) __text__
#define __tr_no_xgettext_ctx(__text__,__context__) KviLocale::translate(__text__,__context__)
#define __tr2qs_ctx(__text__,__context__) KviLocale::translateToQString(__text__,__context__)
#define __tr2qs_ctx_no_xgettext(__text__,__context__) KviLocale::translateToQString(__text__,__context__)
#define __tr2qs_no_lookup(__text__) __text__
#include <qtranslator.h>
#include <qstring.h>
class KVILIB_API KviTranslator : public QTranslator
{
Q_OBJECT
public:
KviTranslator(QObject * parent,const char * name);
~KviTranslator();
public:
#ifdef COMPILE_USE_QT4
virtual QString translate(const char * context,const char * message,const char * comment) const;
#endif
// Deprecated in qt 4.x
virtual QString find(const char * context,const char * message) const;
#ifndef COMPILE_USE_QT4
// Dead in qt 4.x
virtual QTranslatorMessage findMessage(const char * context,const char * sourceText,const char * comment = 0) const;
#endif
};
#endif //!_KVI_LOCALE_H_
|