Skip to content

Commit

Permalink
fix for blg dict
Browse files Browse the repository at this point in the history
1/fix some babylon dict's language name not displayed (ex: Traditional Chinese )
2/add babylon style (dict name & icon)
3/fix for issue @goldendict#19
  • Loading branch information
vtliem committed Jan 28, 2012
1 parent 25bca90 commit 96bc934
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 19 deletions.
6 changes: 6 additions & 0 deletions article-style-st-babylon.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body{background: ##FFFFFF;font-size: 16px;}
::selection{background:#4492E8;color:#fff;}
.gddictname{border:none;background:#EBEBEB;border-top-left-radius:8px;border-top-right-radius:8px;padding-top:8px;padding-bottom:5px}
.gddicticon{display:inline;padding-right:2px;}
.gddicticon img{border:0;height:16px;}
.gdfromprefix{display:none}
4 changes: 4 additions & 0 deletions article-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pre
padding-top: 1px;
margin-top: -9px;
margin-bottom: 8px;
/*fix for invalid blg*/
font-style:normal;
}

/* Appears between the articles */
Expand Down Expand Up @@ -2619,3 +2621,5 @@ in bg url to hide it from iemac */

.mwiki .infl-inline { display: inline }
.mwiki .infl-table { display: none }
/****default hide dict icon ***/
.gddicticon{display:none;}
4 changes: 3 additions & 1 deletion article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ void ArticleRequest::bodyFinished()

closePrevSpan = true;

head += string( "<div class=\"gddictname\"><span class=\"gdfromprefix\">" ) +
head += string( "<div class=\"gddictname\"><span class=\"gddicticon\"><img src=\"gico://")
+ Html::escape( dictId )
+ "/\"></span><span class=\"gdfromprefix\">" +
Html::escape( tr( "From " ).toUtf8().data() ) + "</span>" +
Html::escape( activeDict->getName().c_str() )
+ "</div>";
Expand Down
18 changes: 16 additions & 2 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
return articleMaker.makeDefinitionFor( word, group, contexts, mutedDicts );
}

if ( ( url.scheme() == "bres" || url.scheme() == "gdau" ) &&
if ( ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gico" ) &&
url.path().size() )
{
//DPRINTF( "Get %s\n", req.url().host().toLocal8Bit().data() );
Expand All @@ -160,7 +160,21 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
{
for( unsigned x = 0; x < dictionaries.size(); ++x )
if ( dictionaries[ x ]->getId() == id )
return dictionaries[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() );
{
if( url.scheme() == "gico" )
{
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
dictionaries[ x ]->getIcon().pixmap( 16 ).save(&buffer, "PNG");
buffer.close();
sptr< Dictionary::DataRequestInstant > ico = new Dictionary::DataRequestInstant( true );
ico->getData().resize( bytes.size() );
memcpy( &( ico->getData().front() ), bytes.data(), bytes.size() );
return ico;
}
return dictionaries[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() );
}
}
else
{
Expand Down
11 changes: 11 additions & 0 deletions bgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,19 @@ void BglArticleRequest::run()

BglDictionary::replaceCharsetEntities( result );
result = QString::fromUtf8( result.c_str() )
// onclick location to link
.replace( QRegExp( "<([a-z0-9]+)\\s+[^>]*onclick=\"[a-z.]*location(?:\\.href)\\s*=\\s*'([^']+)[^>]*>([^<]+)</\\1>", Qt::CaseInsensitive ),
"<a href=\"\\2\">\\3</a>")
.replace( QRegExp( "(<\\s*a\\s+[^>]*href\\s*=\\s*[\"']\\s*)bword://", Qt::CaseInsensitive ),
"\\1bword:" )
//remove invalid width, height attrs
.replace(QRegExp( "(width)|(height)\\s*=\\s*[\"']\\d{7,}[\"'']" ),
"" )
//remove invalid <br> tag
.replace( QRegExp( "<br>(<div|<table|<tbody|<tr|<td|</div>|</table>|</tbody>|</tr>|</td>|function addScript|var scNode|scNode|var atag|while\\(atag|atag=atag|document\\.getElementsByTagName|addScript|src=\"bres|<a onmouseover=\"return overlib|onclick=\"return overlib)", Qt::CaseInsensitive ),
"\\1" )
.replace( QRegExp( "(AUTOSTATUS, WRAP\\);\" |</DIV>|addScript\\('JS_FILE_PHONG_VT_45634'\\);|appendChild\\(scNode\\);|atag\\.firstChild;)<br>", Qt::CaseInsensitive ),
" \\1 " )
.toUtf8().data();

Mutex::Lock _( dataMutex );
Expand Down
30 changes: 15 additions & 15 deletions bgl_babylon.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ const std::string bgl_language[] = {
"German",
"Russian",
"Japanese",
"Traditional Chinese",
"Simplified Chinese",
"\x01",//"Traditional Chinese",
"\x02",//"Simplified Chinese",
"Greek",
"Korean",
"Turkish",
"Hebrew",
"Arabic",
"Thai",
"Other",
"Other Simplified Chinese dialects",
"Other Traditional Chinese dialects",
"Other Eastern-European languages",
"Other Western-European languages",
"Other Russian languages",
"Other Japanese languages",
"Other Baltic languages",
"Other Greek languages",
"Other Korean dialects",
"Other Turkish dialects",
"Other Thai dialects",
"\x03",//"Other",
"\x04",//"Other Simplified Chinese dialects",
"\x05",//Other Traditional Chinese dialects",
"\x06",//Other Eastern-European languages",
"\x07",//Other Western-European languages",
"\x08",//Other Russian languages",
"\x09",//Other Japanese languages",
"\x0A",//"Other Baltic languages",
"\x0B",//Other Greek languages",
"\x0C",//"Other Korean dialects",
"\x0D",//Other Turkish dialects",
"\x0E",//"Other Thai dialects",
"Polish",
"Hungarian",
"Czech",
Expand Down Expand Up @@ -193,7 +193,7 @@ public:

enum
{
ParserVersion = 12
ParserVersion = 13
};

private:
Expand Down
3 changes: 2 additions & 1 deletion flags.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/" >
<qresource prefix="/">
<file>flags/wiki.png</file>
<file>flags/folder.png</file>
<file>flags/ad.png</file>
Expand Down Expand Up @@ -254,5 +254,6 @@
<file>flags/en.png</file>
<file>flags/uk.png</file>
<file>flags/eo.png</file>
<file>flags/other.png</file>
</qresource>
</RCC>
Binary file added flags/other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions langcoder.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "langcoder.hh"
#include "folding.hh"
#include "wstring_qt.hh"
#include "language.hh"

#include <cctype>

Expand Down Expand Up @@ -79,6 +80,12 @@ quint32 LangCoder::code3toInt(const std::string& code3)

quint32 LangCoder::findIdForLanguage( gd::wstring const & lang )
{
//fix for babylon
if( lang.length() == 1 )
{
quint16 index = lang[ 0 ];
if( index > 0 && index < 14 ) return Language::getBabylonLangByIndex( index - 1 ).id;
}
gd::wstring langFolded = Folding::apply( lang );

for( LangCode const * lc = LangCodes; lc->code[ 0 ]; ++lc )
Expand Down
36 changes: 36 additions & 0 deletions language.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,36 @@ Db::Db()

}

/// babylon languages
#define blgCode2Int( index, code0, code1 ) (((uint32_t)index) << 16 ) + (((uint32_t)code1) << 8 ) + (uint32_t)code0
const BabylonLang BabylonDb[] ={
{ blgCode2Int( 1, 'z', 'h' ), "tw", "Traditional Chinese", QT_TR_NOOP( "Traditional Chinese" ) },
{ blgCode2Int( 2, 'z', 'h' ), "cn", "Simplified Chinese", QT_TR_NOOP( "Simplified Chinese" ) },
{ blgCode2Int( 3, 0, 0 ), "other", "Other", QT_TR_NOOP( "Other" ) },
{ blgCode2Int( 4, 'z', 'h' ), "cn", "Other Simplified Chinese dialects", QT_TR_NOOP( "Other Simplified Chinese dialects" ) },
{ blgCode2Int( 5, 'z', 'h' ), "tw", "Other Traditional Chinese dialects", QT_TR_NOOP( "Other Traditional Chinese dialects" ) },
{ blgCode2Int( 6, 0, 0 ), "other", "Other Eastern-European languages", QT_TR_NOOP( "Other Eastern-European languages" ) },
{ blgCode2Int( 7, 0, 0 ), "other", "Other Western-European languages", QT_TR_NOOP( "Other Western-European languages" )},
{ blgCode2Int( 8, 'r', 'u' ), "ru", "Other Russian languages", QT_TR_NOOP( "Other Russian languages" ) },
{ blgCode2Int( 9, 'j', 'a' ), "jp", "Other Japanese languages", QT_TR_NOOP( "Other Japanese languages" ) },
{ blgCode2Int( 10, 0, 0 ), "other", "Other Baltic languages", QT_TR_NOOP( "Other Baltic languages" )},
{ blgCode2Int( 11, 'e', 'l' ), "gr", "Other Greek languages", QT_TR_NOOP( "Other Greek languages" ) },
{ blgCode2Int( 12, 'k', 'o' ), "kr", "Other Korean dialects", QT_TR_NOOP( "Other Korean dialects" ) },
{ blgCode2Int( 13, 't', 'r' ), "tr", "Other Turkish dialects", QT_TR_NOOP( "Other Turkish dialects" ) },
{ blgCode2Int( 14, 't', 'h' ), "th", "Other Thai dialects", QT_TR_NOOP( "Other Thai dialects" ) }
};

BabylonLang getBabylonLangByIndex( int index )
{
return BabylonDb[ index ];
}

QString englishNameForId( Id id )
{
if( id >= 0x010000 && id <= 0x0effff ) //babylon
{
return BabylonDb[ ( (id >> 16 ) & 0x0f) - 1 ].englishName;
}
map< QString, QString >::const_iterator i =
Db::instance().getIso2ToEnglish().find( LangCoder::intToCode2( id ) );

Expand All @@ -374,6 +402,10 @@ QString englishNameForId( Id id )

QString localizedNameForId( Id id )
{
if( id >= 0x010000 && id <= 0x0effff ) //babylon
{
return QCoreApplication::translate( "Language", BabylonDb[ ( ( id >> 16 ) & 0x0f ) - 1 ].localizedName );
}
map< QString, QString >::const_iterator i =
Db::instance().getIso2ToLocalized().find( LangCoder::intToCode2( id ) );

Expand All @@ -385,6 +417,10 @@ QString localizedNameForId( Id id )

QString countryCodeForId( Id id )
{
if( id >= 0x010000 && id <= 0x0effff ) //babylon
{
return BabylonDb[ ( ( id >> 16 ) & 0x0f ) - 1 ].contryCode;
}
map< QString, QString >::const_iterator i =
Db::instance().getIso2ToCountry().find( LangCoder::intToCode2( id ) );

Expand Down
8 changes: 8 additions & 0 deletions language.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ QString countryCodeForId( Id );
// All other functions are to be used from LangCoder, which is supposed to
// be migrated here over time.

struct BabylonLang{
Id id;
const QString contryCode;
const QString englishName;
const char * localizedName;
};
BabylonLang getBabylonLangByIndex( int index );

}

#endif
1 change: 1 addition & 0 deletions preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):

ui.displayStyle->addItem( QIcon( ":/icons/programicon.png" ), tr( "Default" ), QString() );
ui.displayStyle->addItem( QIcon( ":/icons/icon32_dsl.png" ), tr( "Lingvo" ), QString( "lingvo" ) );
ui.displayStyle->addItem( QIcon( ":/icons/icon32_bgl.png" ), tr( "Babylon" ), QString( "babylon" ) );

for( int x = 0; x < ui.displayStyle->count(); ++x )
if ( ui.displayStyle->itemData( x ).toString() == p.displayStyle )
Expand Down
5 changes: 5 additions & 0 deletions qt-style-st-babylon.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MainWindow #searchPane #translateLine, MainWindow #searchPane #wordList, MainWindow #dictsPane #dictsList
{
background: white;
}

2 changes: 2 additions & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
<file>icons/highlighter.png</file>
<file>icons/error.png</file>
<file>icons/macicon.png</file>
<file>article-style-st-babylon.css</file>
<file>qt-style-st-babylon.css</file>
</qresource>
</RCC>

0 comments on commit 96bc934

Please sign in to comment.