QTrans.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                 L a n g u a g e  T r a n s l a t i o n                        *
00004 *                                                                               *
00005 *********************************************************************************
00006 *        Copyright (C) 2003-2006 by Niall Douglas.   All Rights Reserved.       *
00007 *       NOTE THAT I DO NOT PERMIT ANY OF MY CODE TO BE PROMOTED TO THE GPL      *
00008 *********************************************************************************
00009 * This code is free software; you can redistribute it and/or modify it under    *
00010 * the terms of the GNU Library General Public License v2.1 as published by the  *
00011 * Free Software Foundation EXCEPT that clause 3 does not apply ie; you may not  *
00012 * "upgrade" this code to the GPL without my prior written permission.           *
00013 * Please consult the file "License_Addendum2.txt" accompanying this file.       *
00014 *                                                                               *
00015 * This code is distributed in the hope that it will be useful,                  *
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                          *
00018 *********************************************************************************
00019 * $Id:                                                                          *
00020 ********************************************************************************/
00021 
00022 #ifndef QTRANS_H
00023 #define QTRANS_H
00024 
00025 #include "fxdefs.h"
00026 #include "FXProcess.h"
00027 
00028 namespace FX {
00029 
00034 class FXString;
00035 class FXStream;
00036 
00051 struct QTransStringPrivate;
00052 class FXAPI QTransString
00053 {
00054     friend class QTrans;
00055     friend struct QTransStringPrivate;
00056     QTransStringPrivate *p;
00057 protected:
00058     QTransString() : p(0) { }
00059     QTransString(const char *context, const char *text, const char *hint, const FXString *langid=0);
00061     bool empty() const throw();
00063     QTransString copy() const;
00065     typedef Generic::Functor<Generic::TL::create<const FXString *>::value> GetLangIdSpec;
00067     GetLangIdSpec *langIdFunc() const throw();
00069     void setLangIdFunc(GetLangIdSpec *idfunc) throw();
00072     FXString translate(const FXString *id=0);
00074     void contents(const char *&context, const char *&text, const char *&hint) const;
00075 public:
00076 #ifndef HAVE_CPP0XRVALUEREFS
00077 #ifdef HAVE_CONSTTEMPORARIES
00078     QTransString(const QTransString &o);
00079     QTransString &operator=(const QTransString &);
00080 #else
00081     QTransString(QTransString &o);
00082     QTransString &operator=(QTransString &);
00083 #endif
00084 #else
00085 private:
00086     QTransString(const QTransString &); // disable copy constructor
00087     QTransString &operator=(const QTransString &);
00088 public:
00089     QTransString(QTransString &&o);
00090     QTransString &&operator=(QTransString &&o);
00091 #endif
00092     ~QTransString();
00098     QTransString &arg(const FXString &str, FXint fieldwidth=0);
00100     QTransString &arg(char c, FXint fieldwidth=0);
00102     QTransString &arg(FXlong num,  FXint fieldwidth=0, FXint base=10);
00104     QTransString &arg(FXulong num, FXint fieldwidth=0, FXint base=10);
00106     QTransString &arg(FXint num,  FXint fieldwidth=0, FXint base=10) { return arg((base!=10) ? (FXulong)((FXuint) num) : (FXlong) num, fieldwidth, base); }
00108     QTransString &arg(FXuint num, FXint fieldwidth=0, FXint base=10) { return arg((FXulong) num, fieldwidth, base); }
00110     QTransString &arg(double num, FXint fieldwidth=0, FXchar fmt='g', int prec=-1);
00112     operator FXString() { return translate(); }
00114     const FXchar *text();
00115 
00117     void save(FXStream &s) const;
00119     void load(FXStream &s);
00120 };
00121 
00122 
00195 template<class type> class QValueList;
00196 class QTransPrivate;
00197 struct QTransEmbeddedFile;
00198 class FXAPI QTrans
00199 {
00200     QTransPrivate *p;
00201     friend class QTransInit;
00202     QTrans(int &argc, char **argv, FXStream &txtout);
00203     FXDLLLOCAL void addData(QTransEmbeddedFile &data);
00204     FXDLLLOCAL void removeData(const QTransEmbeddedFile &data);
00205 public:
00206     ~QTrans();
00217     static QTransString tr(const char *context, const char *text, const char *hint=0);
00218     enum LanguageType
00219     {
00220         ISO639=0    
00221     };
00223     static const FXString &language(LanguageType=ISO639);
00224     enum CountryType
00225     {
00226         ISO3166=0   
00227     };
00229     static const FXString &country(CountryType=ISO3166);
00234     static void refresh();
00238     static void overrideLanguage(const FXString &iso639);
00242     static void overrideCountry(const FXString &iso3166);
00244     struct ProvidedInfo
00245     {
00246         FXString module, language, country;
00247         ProvidedInfo() { }
00248         ProvidedInfo(const FXString &_module, const FXString &_language, const FXString &_country)
00249             : module(_module), language(_language), country(_country) { }
00250         bool operator<(const ProvidedInfo &o) const { return module<o.module || (module==o.module && (language<o.language || (language==o.language && country<o.country))); }
00251         bool operator>(const ProvidedInfo &o) const { return module>o.module || (module==o.module && (language>o.language || (language==o.language && country>o.country))); }
00252     };
00254     typedef QValueList<ProvidedInfo> ProvidedInfoList;
00261     static ProvidedInfoList provided();
00262 private:
00263     friend class QTrans_EmbeddedTranslationFile;
00264     friend class QTransString;
00265     FXDLLLOCAL void int_translateString(FXString &dest, QTransString &src, const FXString *langid=0);
00266     static void int_registerEmbeddedTranslationFile(const char *buffer, FXuint len, void *staticaddr);
00267     static void int_deregisterEmbeddedTranslationFile(const char *buffer, FXuint len, void *staticaddr);
00268 };
00269 
00270 #ifndef __GCCXML__
00271 class QTrans_EmbeddedTranslationFile
00272 {
00273     const char *buffer;
00274     FXuint len;
00275 public:
00276     QTrans_EmbeddedTranslationFile(const FXuchar *_buffer, FXuint _len) : buffer((const char *) _buffer), len(_len)
00277     {
00278         QTrans::int_registerEmbeddedTranslationFile(buffer, len, this);
00279     }
00280     QTrans_EmbeddedTranslationFile(const char *_buffer, FXuint _len) : buffer(_buffer), len(_len)
00281     {
00282         QTrans::int_registerEmbeddedTranslationFile(buffer, len, this);
00283     }
00284     ~QTrans_EmbeddedTranslationFile()
00285     {
00286         QTrans::int_deregisterEmbeddedTranslationFile(buffer, len, this);
00287     }
00288 };
00291 #define QTRANS_SETTRANSFILE(buffer, len) static QTrans_EmbeddedTranslationFile _tnfox_myembeddedtranslationfile_(buffer, len)
00292 #endif
00293 
00294 } // namespace
00295 
00296 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:26 2009 for TnFOX by doxygen v1.4.7