mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
ChineseConversion: load OpenCC data files by relative path on Windows and OS X
This commit is contained in:
parent
a1986254d2
commit
b5ac249062
20
chinese.cc
20
chinese.cc
|
@ -20,7 +20,7 @@ class CharacterConversionDictionary: public Transliteration::BaseTransliteration
|
|||
public:
|
||||
|
||||
CharacterConversionDictionary( std::string const & id, std::string const & name,
|
||||
QIcon icon, std::string const & openccConfig);
|
||||
QIcon icon, QString const & openccConfig);
|
||||
~CharacterConversionDictionary();
|
||||
|
||||
std::vector< gd::wstring > getAlternateWritings( gd::wstring const & )
|
||||
|
@ -30,15 +30,15 @@ public:
|
|||
CharacterConversionDictionary::CharacterConversionDictionary( std::string const & id,
|
||||
std::string const & name_,
|
||||
QIcon icon_,
|
||||
std::string const & openccConfig):
|
||||
QString const & openccConfig):
|
||||
Transliteration::BaseTransliterationDictionary( id, name_, icon_, false ),
|
||||
converter( NULL )
|
||||
{
|
||||
try {
|
||||
converter = new opencc::SimpleConverter( openccConfig );
|
||||
converter = new opencc::SimpleConverter( openccConfig.toLocal8Bit().constData() );
|
||||
} catch ( std::runtime_error& e ) {
|
||||
gdWarning( "CharacterConversionDictionary: failed to initialize OpenCC from config %s: %s\n",
|
||||
openccConfig.c_str(), e.what() );
|
||||
openccConfig.toLocal8Bit().constData(), e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,27 +78,33 @@ std::vector< sptr< Dictionary::Class > > makeDictionaries( Config::Chinese const
|
|||
{
|
||||
std::vector< sptr< Dictionary::Class > > result;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
QString configDir = "";
|
||||
#else
|
||||
QString configDir = Config::getOpenCCDir() + "/";
|
||||
#endif
|
||||
|
||||
if ( cfg.enable )
|
||||
{
|
||||
if ( cfg.enableSCToTWConversion )
|
||||
{
|
||||
result.push_back( new CharacterConversionDictionary( "bf1c33a59cbacea8f39b5b5475787cfd",
|
||||
QCoreApplication::translate( "ChineseConversion", "Simplified to traditional Chinese (Taiwan variant) conversion" ).toUtf8().data(),
|
||||
QIcon( ":/flags/tw.png" ), "s2tw.json" ) );
|
||||
QIcon( ":/flags/tw.png" ), configDir + "s2tw.json" ) );
|
||||
}
|
||||
|
||||
if ( cfg.enableSCToHKConversion )
|
||||
{
|
||||
result.push_back( new CharacterConversionDictionary( "9e0681fb9e1c0b6c90e6fb46111d96b5",
|
||||
QCoreApplication::translate( "ChineseConversion", "Simplified to traditional Chinese (Hong Kong variant) conversion" ).toUtf8().data(),
|
||||
QIcon( ":/flags/hk.png" ), "s2hk.json" ) );
|
||||
QIcon( ":/flags/hk.png" ), configDir + "s2hk.json" ) );
|
||||
}
|
||||
|
||||
if ( cfg.enableTCToSCConversion )
|
||||
{
|
||||
result.push_back( new CharacterConversionDictionary( "0db536ce0bdc52ea30d11a82c5db4a27",
|
||||
QCoreApplication::translate( "ChineseConversion", "Traditional to simplified Chinese conversion" ).toUtf8().data(),
|
||||
QIcon( ":/flags/cn.png" ), "t2s.json" ) );
|
||||
QIcon( ":/flags/cn.png" ), configDir + "t2s.json" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
config.cc
10
config.cc
|
@ -2024,6 +2024,16 @@ QString getHelpDir() throw()
|
|||
return QCoreApplication::applicationDirPath() + "/help";
|
||||
}
|
||||
|
||||
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
|
||||
QString getOpenCCDir() throw()
|
||||
{
|
||||
if ( QDir( "opencc" ).exists() )
|
||||
return "opencc";
|
||||
else
|
||||
return QCoreApplication::applicationDirPath() + "/opencc";
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isPortableVersion() throw()
|
||||
{
|
||||
struct IsPortable
|
||||
|
|
|
@ -675,6 +675,11 @@ QString getLocDir() throw();
|
|||
/// Returns the directory storing program help files (.qch).
|
||||
QString getHelpDir() throw();
|
||||
|
||||
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
|
||||
/// Returns the directory storing OpenCC configuration and dictionary files (.json and .ocd).
|
||||
QString getOpenCCDir() throw();
|
||||
#endif
|
||||
|
||||
/// Returns true if the program is configured as a portable version. In that
|
||||
/// mode, all the settings and indices are kept in the program's directory.
|
||||
bool isPortableVersion() throw();
|
||||
|
|
5
main.cc
5
main.cc
|
@ -183,6 +183,11 @@ int main( int argc, char ** argv )
|
|||
app.setWindowIcon( QIcon( ":/icons/programicon.png" ) );
|
||||
#endif
|
||||
|
||||
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
|
||||
// OpenCC needs to load it's data files by relative path on Windows and OS X
|
||||
QDir::setCurrent( Config::getProgramDataDir() );
|
||||
#endif
|
||||
|
||||
// Load translations for system locale
|
||||
|
||||
QTranslator qtTranslator;
|
||||
|
|
Loading…
Reference in a new issue