2009-04-22 21:37:32 +00:00
|
|
|
#ifndef LANGCODER_H
|
|
|
|
#define LANGCODER_H
|
|
|
|
|
|
|
|
#include <QtGui>
|
2009-04-23 11:41:13 +00:00
|
|
|
#include "wstring.hh"
|
2009-04-22 21:37:32 +00:00
|
|
|
|
2013-07-20 09:50:21 +00:00
|
|
|
struct GDLangCode
|
2009-04-22 21:37:32 +00:00
|
|
|
{
|
2009-04-23 11:41:13 +00:00
|
|
|
char code[ 3 ]; // ISO 639-1
|
2012-01-27 11:40:42 +00:00
|
|
|
char code3[ 4 ]; // ISO 639-2B ( http://www.loc.gov/standards/iso639-2/ )
|
2013-07-16 14:23:42 +00:00
|
|
|
int isRTL; // Right-to-left writing; 0 - no, 1 - yes, -1 - let Qt define
|
2009-04-23 22:25:25 +00:00
|
|
|
char const * lang; // Language name in English
|
2023-05-20 14:33:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template< typename T, int N >
|
|
|
|
inline int arraySize( T ( & )[ N ] )
|
|
|
|
{
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
2009-04-22 21:37:32 +00:00
|
|
|
struct LangStruct
|
|
|
|
{
|
|
|
|
int order;
|
|
|
|
quint32 code;
|
|
|
|
QIcon icon;
|
|
|
|
QString lang;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LangCoder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LangCoder();
|
|
|
|
|
|
|
|
static quint32 code2toInt(const char code[2])
|
2009-04-23 10:29:49 +00:00
|
|
|
{ return ( ((quint32)code[1]) << 8 ) + (quint32)code[0]; }
|
2009-04-22 21:37:32 +00:00
|
|
|
|
2009-05-24 15:45:37 +00:00
|
|
|
static QString intToCode2( quint32 );
|
|
|
|
|
2009-04-23 11:41:13 +00:00
|
|
|
/// Finds the id for the given language name, written in english. The search
|
|
|
|
/// is case- and punctuation insensitive.
|
|
|
|
static quint32 findIdForLanguage( gd::wstring const & );
|
|
|
|
|
2012-01-27 11:40:42 +00:00
|
|
|
static quint32 findIdForLanguageCode3( const char * );
|
2009-04-22 21:37:32 +00:00
|
|
|
|
2012-12-19 12:59:38 +00:00
|
|
|
static QPair<quint32,quint32> findIdsForName( QString const & );
|
2009-04-23 19:57:39 +00:00
|
|
|
static QPair<quint32,quint32> findIdsForFilename( QString const & );
|
|
|
|
|
|
|
|
static quint32 guessId( const QString & lang );
|
|
|
|
|
|
|
|
/// Returns decoded name of language or empty string if not found.
|
|
|
|
static QString decode(quint32 code);
|
2009-04-26 13:16:30 +00:00
|
|
|
/// Returns icon for language or empty string if not found.
|
|
|
|
static QIcon icon(quint32 code);
|
2009-04-23 19:57:39 +00:00
|
|
|
|
2023-05-20 14:33:20 +00:00
|
|
|
/// Return true for RTL languages
|
|
|
|
static bool isLanguageRTL( quint32 code );
|
|
|
|
|
|
|
|
LangStruct langStruct( quint32 code );
|
|
|
|
|
|
|
|
private:
|
|
|
|
QMap< quint32, int > codeMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define LangCodeRole Qt::UserRole
|
|
|
|
|
|
|
|
|
2009-04-22 21:37:32 +00:00
|
|
|
#endif // LANGCODER_H
|