2023-05-22 14:53:35 +00:00
|
|
|
#ifndef LANGCODER_H
|
|
|
|
#define LANGCODER_H
|
|
|
|
|
2023-05-30 06:31:07 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QIcon>
|
2023-05-22 14:53:35 +00:00
|
|
|
#include "wstring.hh"
|
|
|
|
|
|
|
|
struct GDLangCode
|
|
|
|
{
|
2024-06-19 06:17:02 +00:00
|
|
|
QString code2; // ISO 639-1 -> always 2 letters thus code2
|
2023-05-22 14:53:35 +00:00
|
|
|
std::string code3; // ISO 639-2B ( http://www.loc.gov/standards/iso639-2/ )
|
|
|
|
int isRTL; // Right-to-left writing; 0 - no, 1 - yes, -1 - let Qt define
|
|
|
|
std::string lang; // Language name in English
|
2023-05-20 14:33:20 +00:00
|
|
|
};
|
|
|
|
|
2023-05-22 14:53:35 +00:00
|
|
|
class LangCoder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
static quint32 code2toInt( const char code[ 2 ] )
|
|
|
|
{
|
|
|
|
return ( ( (quint32)code[ 1 ] ) << 8 ) + (quint32)code[ 0 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
static quint32 code2toInt( QString code )
|
|
|
|
{
|
|
|
|
if ( code.size() < 2 )
|
|
|
|
return 0;
|
|
|
|
auto c = code.toLatin1();
|
|
|
|
|
|
|
|
return ( ( (quint32)c[ 1 ] ) << 8 ) + (quint32)c[ 0 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString intToCode2( quint32 );
|
|
|
|
|
|
|
|
/// Finds the id for the given language name, written in english. The search
|
|
|
|
/// is case- and punctuation insensitive.
|
|
|
|
static quint32 findIdForLanguage( gd::wstring const & );
|
|
|
|
|
|
|
|
static quint32 findIdForLanguageCode3( std::string const & );
|
|
|
|
|
2024-06-19 01:19:18 +00:00
|
|
|
/// find id pairs like en-zh in dictioanry name
|
2024-06-19 03:10:14 +00:00
|
|
|
static std::pair< quint32, quint32 > findLangIdPairFromName( QString const & );
|
|
|
|
static std::pair< quint32, quint32 > findLangIdPairFromPath( std::string const & );
|
2023-05-22 14:53:35 +00:00
|
|
|
|
|
|
|
static quint32 guessId( const QString & lang );
|
|
|
|
|
|
|
|
/// Returns decoded name of language or empty string if not found.
|
2023-05-26 15:55:33 +00:00
|
|
|
static QString decode( quint32 _code );
|
2023-05-22 14:53:35 +00:00
|
|
|
|
2023-05-20 14:33:20 +00:00
|
|
|
/// Return true for RTL languages
|
|
|
|
static bool isLanguageRTL( quint32 code );
|
|
|
|
|
|
|
|
private:
|
2023-05-26 15:55:33 +00:00
|
|
|
static QMap< QString, GDLangCode > LANG_CODE_MAP;
|
2024-06-19 01:19:18 +00:00
|
|
|
static bool code2Exists( const QString & _code );
|
2023-05-20 14:33:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define LangCodeRole Qt::UserRole
|
|
|
|
|
|
|
|
|
2023-05-22 14:53:35 +00:00
|
|
|
#endif // LANGCODER_H
|