00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <tqfile.h>
00023
00024 #include <kdebug.h>
00025
00026 #include "kcatalogue.h"
00027 #include "kstandarddirs.h"
00028
00029 char *k_nl_find_msg(struct kde_loaded_l10nfile *domain_file,
00030 const char *msgid);
00031 void k_nl_unload_domain (struct loaded_domain *domain);
00032
00033 #ifndef KDE_USE_FINAL // with --enable-final, we're getting this from libintl.cpp
00034 struct kde_loaded_l10nfile
00035 {
00036 const char *filename;
00037 int decided;
00038
00039 const void *data;
00040
00041 kde_loaded_l10nfile() : filename(0), decided(0), data(0) {}
00042 };
00043 #endif
00044
00045 class KCataloguePrivate
00046 {
00047 public:
00048 TQString name;
00049 TQString language;
00050 int pluralType;
00051
00052 kde_loaded_l10nfile domain;
00053 };
00054
00055 KCatalogue::KCatalogue(const TQString & name, const TQString & language )
00056 : d( new KCataloguePrivate )
00057 {
00058 d->name = name;
00059 d->language = language;
00060
00061
00062
00063 d->pluralType = -1;
00064
00065 TQString path = TQString::fromLatin1("%1/LC_MESSAGES/%2.mo")
00066 .arg( d->language )
00067 .arg( d->name );
00068
00069 TQString fileName = locate( "locale", path );
00070 if (fileName.isEmpty())
00071 fileName = locate( "locale-bundle", path );
00072
00073 setFileName( fileName );
00074
00075 }
00076
00077 KCatalogue::KCatalogue(const KCatalogue & rhs)
00078 : d( new KCataloguePrivate )
00079 {
00080 *this = rhs;
00081 }
00082
00083 KCatalogue & KCatalogue::operator=(const KCatalogue & rhs)
00084 {
00085 d->name = rhs.d->name;
00086 d->language = rhs.d->language;
00087 d->pluralType = rhs.d->pluralType;
00088 setFileName( rhs.fileName() );
00089
00090 return *this;
00091 }
00092
00093 KCatalogue::~KCatalogue()
00094 {
00095 doUnload();
00096
00097 delete d;
00098 }
00099
00100 TQString KCatalogue::name() const
00101 {
00102 return d->name;
00103 }
00104
00105 TQString KCatalogue::language() const
00106 {
00107 return d->language;
00108 }
00109
00110 void KCatalogue::setPluralType( int pluralType)
00111 {
00112 d->pluralType = pluralType;
00113 }
00114
00115 int KCatalogue::pluralType() const
00116 {
00117 return d->pluralType;
00118 }
00119
00120
00121 void KCatalogue::setFileName( const TQString & fileName )
00122 {
00123
00124 if ( this->fileName() == fileName ) return;
00125
00126 doUnload();
00127
00128 TQCString newFileName = TQFile::encodeName( fileName );
00129
00130 if ( !fileName.isEmpty() )
00131 {
00132
00133 char *filename = new char[ newFileName.length() + 1 ];
00134 ::qstrcpy( filename, newFileName );
00135 d->domain.filename = filename;
00136 }
00137 }
00138
00139 TQString KCatalogue::fileName() const
00140 {
00141 return TQFile::decodeName( d->domain.filename );
00142 }
00143
00144 const char * KCatalogue::translate(const char * msgid) const
00145 {
00146 return ::k_nl_find_msg( &d->domain, msgid );
00147 }
00148
00149 void KCatalogue::doUnload()
00150 {
00151
00152 if ( d->domain.data )
00153 ::k_nl_unload_domain( (struct loaded_domain *)d->domain.data );
00154 d->domain.data = 0;
00155
00156
00157 delete [] const_cast<char *>(d->domain.filename);
00158 d->domain.filename = 0;
00159
00160 d->domain.decided = 0;
00161 }