CI18nTranslator Class Reference

#include <CI18nTranslator.h>

List of all members.

Public Member Functions

bool shouldBeTranslatedAttribute (string inAttribute) const
bool shouldBeTranslatedText (string inContainingTag) const
void setCurrentLanguage (const string &inLanguage)
string getCurrentLanguage () const
void setShouldBeTranslatedAttribute (string inString)
void addTranslationPair (string inString, string inTranslatedString)
 CI18nTranslator (string inTranslationFileName)
const CXMLElementgetLanguagesXML () const
bool hasLanguage (string inLanguageCode) const
const pair< bool, string > translateAttribute (string inLanguageCode, const string &inAttribute, const string &inValue) const
const pair< bool, string > translateText (string inLanguageCode, const string &inContainingTag, const string &inText)
void translateXMLTree (string inLanguageCode, CXMLElement &inoutToBeTranslated) const

Static Public Member Functions

static void startXMLElement (void *inUserData, const char *inElementName, const char **inAttributes)
static void endXMLElement (void *inUserData, const char *inElementName)

Private Types

typedef map< string, string > CTranslatorMap
typedef map< string, boolCShouldBeTranslatedMap
typedef map< string,
CTranslatorMap
CLanguageMap

Private Attributes

CLanguageMap mLanguageMap
CShouldBeTranslatedMap mShouldBeTranslatedAttribute
string mCurrentLanguage


Detailed Description

This class offers runtime translation of strings. In contrast to GNU gettext we can chose during runtime the language without additional overhead.

Definition at line 38 of file CI18nTranslator.h.


Member Typedef Documentation

typedef map<string,string> CI18nTranslator::CTranslatorMap [private]

a map that translates strings

Definition at line 40 of file CI18nTranslator.h.

typedef map<string,bool> CI18nTranslator::CShouldBeTranslatedMap [private]

a map that contains the decision if a given string is to be translated

Definition at line 43 of file CI18nTranslator.h.

typedef map<string,CTranslatorMap> CI18nTranslator::CLanguageMap [private]

a map that contains translators for a number of languages

Definition at line 45 of file CI18nTranslator.h.


Constructor & Destructor Documentation

CI18nTranslator::CI18nTranslator ( string  inTranslationFileName  ) 

The constructor

This class offers runtime translation of strings. In contrast to GNU gettext we can chose during runtime the language without additional overhead. The constructor

Definition at line 34 of file CI18nTranslator.cc.

References endXMLElement(), and startXMLElement().

00034                                                             {
00035   ifstream inFile(inTranslationFileName.c_str());
00036 
00037   inFile.seekg(0,ios::end);
00038   int lFileSize(inFile.tellg());
00039   inFile.seekg(0,ios::beg);
00040   
00041   cout << "FileSize:" 
00042        << lFileSize 
00043        << " characters" 
00044        << endl;
00045   if(inFile){
00046     char* lBuffer=new char[lFileSize+1];
00047     inFile.read(lBuffer,lFileSize);
00048     lBuffer[lFileSize]=char(0);
00049     
00050     cout << "Read " << inTranslationFileName << endl;
00051     
00052     
00053   XML_Parser lParser = XML_ParserCreate(NULL);//default encoding
00054   
00055   XML_SetUserData(lParser,
00056       this);
00057   XML_SetElementHandler(lParser, 
00058       CI18nTranslator::startXMLElement,
00059       CI18nTranslator::endXMLElement);
00060   bool lDone=false;
00061   if (!XML_Parse(lParser, 
00062      lBuffer, 
00063      lFileSize, 
00064      lDone)) {
00065     cerr << __FILE__ <<":" << __LINE__ << ": XML ERROR: "
00066    << XML_ErrorString(XML_GetErrorCode(lParser))
00067    << " at line "
00068    << XML_GetCurrentLineNumber(lParser)
00069    << endl
00070    << "Internationalization will be disabled in this run of the GIFT"
00071    << endl;
00072   }
00073   XML_ParserFree(lParser);  
00074   }else{
00075     cerr << __FILE__ <<":" << __LINE__ << ": File unreadable."
00076    << endl << "Internationalization will be disabled in this run of the GIFT"
00077    << endl;
00078 
00079   }
00080 };


Member Function Documentation

bool CI18nTranslator::shouldBeTranslatedAttribute ( string  inString  )  const

should a given attribute string be translated?

Should the attribute be translated

Definition at line 126 of file CI18nTranslator.cc.

References mShouldBeTranslatedAttribute.

Referenced by CXEVI18nTranslator::startVisit().

00126                                                                      {
00127   return  
00128     mShouldBeTranslatedAttribute.find(inString)!=mShouldBeTranslatedAttribute.end() 
00129     && mShouldBeTranslatedAttribute.find(inString)->second;
00130 };

bool CI18nTranslator::shouldBeTranslatedText ( string  inContainingTag  )  const

should a given attribute string be translated?

void CI18nTranslator::setCurrentLanguage ( const string &  inLanguage  ) 

set the current language during construction

Definition at line 115 of file CI18nTranslator.cc.

References mCurrentLanguage.

00115                                                                 {
00116   mCurrentLanguage=inLanguage;
00117 }

string CI18nTranslator::getCurrentLanguage (  )  const

set the current language during construction

Definition at line 118 of file CI18nTranslator.cc.

References mCurrentLanguage.

00118                                                {
00119   return mCurrentLanguage;
00120 }

void CI18nTranslator::setShouldBeTranslatedAttribute ( string  inString  ) 

Should the attribute be translated

Definition at line 122 of file CI18nTranslator.cc.

References mShouldBeTranslatedAttribute.

00122                                                                    {
00123   mShouldBeTranslatedAttribute[inString]=true;
00124 };

void CI18nTranslator::addTranslationPair ( string  inString,
string  inTranslatedString 
)

Add one translation pair

Definition at line 132 of file CI18nTranslator.cc.

References mCurrentLanguage, and mLanguageMap.

00132                                                                                  {
00133   mLanguageMap[mCurrentLanguage][inString]=inTranslatedString;
00134 };

const CXMLElement * CI18nTranslator::getLanguagesXML (  )  const

Get an MRML tag containing all offered languages

Definition at line 83 of file CI18nTranslator.cc.

00083                                                         {
00084   return 0;
00085 };

bool CI18nTranslator::hasLanguage ( string  inLanguage  )  const

Get a string list containing all languages

Get an MRML tag containing all offered languages

Definition at line 87 of file CI18nTranslator.cc.

References mLanguageMap.

Referenced by CSession::commitLanguages().

00087                                                        {
00088   return mLanguageMap.find(inLanguage)!=mLanguageMap.end();
00089 };

const pair< bool, string > CI18nTranslator::translateAttribute ( string  inLanguageCode,
const string &  inAttribute,
const string &  inValue 
) const

Translate an attribute given by its name and its value

Returns:
pair: first, if the string should be translated, second, its value
Translate an attribute given by its name and its value
Returns:
pair: first, if the string should be translated, second, its value

Definition at line 94 of file CI18nTranslator.cc.

Referenced by CXEVI18nTranslator::startVisit().

00096                                              {
00097   return make_pair(true, inValue);
00098 };

const pair< bool, string > CI18nTranslator::translateText ( string  inLanguageCode,
const string &  inContainingTag,
const string &  inText 
)

Translate an tag containing pdata given by its name and its value

Returns:
pair: first, if the string should be translated, second, its value
Translate an tag containing pdata given by its name and its value
Returns:
pair: first, if the string should be translated, second, its value

Definition at line 103 of file CI18nTranslator.cc.

00105                                         {
00106   return make_pair(true, inText);
00107 };

void CI18nTranslator::translateXMLTree ( string  inLanguageCode,
CXMLElement inoutToBeTranslated 
) const

Translate a complete XML Tree

Definition at line 109 of file CI18nTranslator.cc.

References CXMLElement::traverse().

Referenced by CSessionManager::translate().

00110                                                      {
00111   CXEVI18nTranslator lVisitor(*this,inLanguageCode);
00112   inoutToBeTranslated.traverse(lVisitor);
00113 };

void CI18nTranslator::startXMLElement ( void *  inUserData,
const char *  inElementName,
const char **  inAttributes 
) [static]

for parsing the config file

Definition at line 136 of file CI18nTranslator.cc.

References CAttributeList::stringReadAttribute().

Referenced by CI18nTranslator().

00138                                      {
00139 
00140   CI18nTranslator* self=(CI18nTranslator*)inUserData;
00141 
00142   CAttributeList lAttributes(inAttributes);
00143 
00144   if(strcmp("attribute",inElementName) && lAttributes.stringReadAttribute("name").first){
00145     self->setShouldBeTranslatedAttribute(lAttributes.stringReadAttribute("name").second);
00146   }
00147   if(strcmp("translation-list",inElementName) && lAttributes.stringReadAttribute("language-code").first){
00148     self->setCurrentLanguage(lAttributes.stringReadAttribute("language-code").second);
00149   }
00150   if(strcmp("translate",inElementName) && lAttributes.stringReadAttribute("key").first && lAttributes.stringReadAttribute("to").first){
00151     self->addTranslationPair(lAttributes.stringReadAttribute("key").second,
00152            lAttributes.stringReadAttribute("to").second);
00153   }
00154 }

void CI18nTranslator::endXMLElement ( void *  inUserData,
const char *  inElementName 
) [static]

for parsing the config file

Definition at line 155 of file CI18nTranslator.cc.

Referenced by CI18nTranslator().

00156                                      {
00157   CI18nTranslator* self=(CI18nTranslator*)inUserData;
00158 }


Member Data Documentation

This map contains translators for each language given in the gift-i18n file.

Definition at line 51 of file CI18nTranslator.h.

Referenced by addTranslationPair(), and hasLanguage().

This map contains information about which

Definition at line 55 of file CI18nTranslator.h.

Referenced by setShouldBeTranslatedAttribute(), and shouldBeTranslatedAttribute().

the current language while parsing the config file

Definition at line 59 of file CI18nTranslator.h.

Referenced by addTranslationPair(), getCurrentLanguage(), and setCurrentLanguage().


The documentation for this class was generated from the following files:

Generated on Wed Jan 7 00:31:08 2009 for Gift by  doxygen 1.5.6