SWLocale Class Reference

#include <swlocale.h>

Collaboration diagram for SWLocale:
Collaboration graph
[legend]

List of all members.

Classes

class  Private

Public Member Functions

virtual void augment (SWLocale &addFrom)
virtual struct abbrevgetBookAbbrevs (int *retSize)
virtual const char * getDescription ()
virtual const char * getEncoding ()
virtual const char * getName ()
virtual SWLocaleoperator+= (SWLocale &addFrom)
 SWLocale (const char *ifilename)
virtual const char * translate (const char *text)
virtual ~SWLocale ()

Static Public Attributes

static const char * DEFAULT_LOCALE_NAME = "en"

Private Attributes

int abbrevsCnt
struct abbrevbookAbbrevs
const char ** bookLongNames
const char ** bookPrefAbbrev
char * description
char * encoding
SWConfiglocaleSource
char * name
Privatep

Detailed Description

SWLocale is used for the localisation of the booknames The SWLocale is a class which holds the information of one language. Every language supported by SWORD has one SWLocale object, get the name of the Language using

See also:
getname of this class. Another functions useful for frontend developers is
getDescription.

Definition at line 39 of file swlocale.h.


Constructor & Destructor Documentation

SWLocale::SWLocale ( const char *  ifilename  ) 

Definition at line 44 of file swlocale.cpp.

00044                                         {
00045     p = new Private;
00046     ConfigEntMap::iterator confEntry;
00047 
00048     name           = 0;
00049     description    = 0;
00050     encoding       = 0;
00051     bookAbbrevs    = 0;
00052     bookLongNames  = 0;
00053     bookPrefAbbrev = 0;
00054     if (ifilename) {
00055         localeSource   = new SWConfig(ifilename);
00056     }
00057     else {
00058         localeSource   = new SWConfig(0);
00059         (*localeSource)["Meta"]["Name"] = DEFAULT_LOCALE_NAME;
00060         (*localeSource)["Meta"]["Description"] = "English (US)";
00061         bookAbbrevs = (struct abbrev *)builtin_abbrevs;
00062         for (abbrevsCnt = 0; builtin_abbrevs[abbrevsCnt].osis[0]; abbrevsCnt++);
00063     }
00064 
00065     confEntry = localeSource->Sections["Meta"].find("Name");
00066     if (confEntry != localeSource->Sections["Meta"].end())
00067         stdstr(&name, (*confEntry).second.c_str());
00068     
00069     confEntry = localeSource->Sections["Meta"].find("Description");
00070     if (confEntry != localeSource->Sections["Meta"].end())
00071         stdstr(&description, (*confEntry).second.c_str());
00072 
00073     confEntry = localeSource->Sections["Meta"].find("Encoding"); //Either empty (==Latin1) or UTF-8
00074     if (confEntry != localeSource->Sections["Meta"].end())
00075         stdstr(&encoding, (*confEntry).second.c_str());
00076 }

SWLocale::~SWLocale (  )  [virtual]

Definition at line 79 of file swlocale.cpp.

00079                     {
00080 
00081     delete localeSource;
00082 
00083     if (encoding)
00084         delete [] encoding;
00085     
00086     if (description)
00087         delete [] description;
00088 
00089     if (name)
00090         delete [] name;
00091 
00092     if (bookAbbrevs != builtin_abbrevs)
00093         delete [] bookAbbrevs;
00094 
00095     delete p;
00096 }


Member Function Documentation

void SWLocale::augment ( SWLocale addFrom  )  [virtual]

Definition at line 151 of file swlocale.cpp.

00151                                         {
00152     *localeSource += *addFrom.localeSource;
00153 }

struct abbrev * SWLocale::getBookAbbrevs ( int *  retSize  )  [read, virtual]

Definition at line 156 of file swlocale.cpp.

00156                                                           {
00157     static const char *nullstr = "";
00158     if (!bookAbbrevs) {
00159         // Assure all english abbrevs are present
00160         for (int j = 0; builtin_abbrevs[j].osis[0]; j++) {
00161             p->mergedAbbrevs[builtin_abbrevs[j].ab] = builtin_abbrevs[j].osis;
00162         }
00163         ConfigEntMap::iterator it = localeSource->Sections["Book Abbrevs"].begin();
00164         ConfigEntMap::iterator end = localeSource->Sections["Book Abbrevs"].end();
00165         for (; it != end; it++) {
00166             p->mergedAbbrevs[it->first.c_str()] = it->second.c_str();
00167         }
00168         int size = p->mergedAbbrevs.size();
00169         bookAbbrevs = new struct abbrev[size + 1];
00170         int i = 0;
00171         for (LookupMap::iterator it = p->mergedAbbrevs.begin(); it != p->mergedAbbrevs.end(); it++, i++) {
00172             bookAbbrevs[i].ab = it->first.c_str();
00173             bookAbbrevs[i].osis = it->second.c_str();
00174         }
00175 
00176         bookAbbrevs[i].ab = nullstr;
00177         bookAbbrevs[i].osis = nullstr;
00178         abbrevsCnt = size;
00179     }
00180         
00181     *retSize = abbrevsCnt;
00182     return bookAbbrevs;
00183 }

const char * SWLocale::getDescription (  )  [virtual]
Returns:
The description. A possible example is "German".

Definition at line 143 of file swlocale.cpp.

00143                                      {
00144     return description;
00145 }

const char * SWLocale::getEncoding (  )  [virtual]

Definition at line 147 of file swlocale.cpp.

00147                                   {
00148     return encoding;
00149 }

const char * SWLocale::getName (  )  [virtual]

This function is used to get the name of the languages which this object is handling.

Returns:
The name of the managed language. A possible example is "de".

Definition at line 138 of file swlocale.cpp.

00138                               {
00139     return name;
00140 }

virtual SWLocale& SWLocale::operator+= ( SWLocale addFrom  )  [inline, virtual]

Definition at line 71 of file swlocale.h.

00071 { augment(addFrom); return *this; }

const char * SWLocale::translate ( const char *  text  )  [virtual]

Definition at line 99 of file swlocale.cpp.

00099                                                 {
00100     LookupMap::iterator entry;
00101 
00102     entry = p->lookupTable.find(text);
00103 
00104     if (entry == p->lookupTable.end()) {
00105         ConfigEntMap::iterator confEntry;
00106         confEntry = localeSource->Sections["Text"].find(text);
00107         if (confEntry == localeSource->Sections["Text"].end())
00108             p->lookupTable.insert(LookupMap::value_type(text, text));
00109         else {//valid value found
00110             /*
00111             - If Encoding==Latin1 and we have a StringHelper, convert to UTF-8
00112             - If StringHelper present and Encoding is UTF-8, use UTF8
00113             - If StringHelper not present and Latin1, use Latin1
00114             - If StringHelper not present and UTF-8, no idea what to do. Should't happen
00115             */
00116 /*          if (StringHelper::getSystemStringHelper()) {
00117                 if (!strcmp(encoding, "UTF-8")) {
00118                     p->lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
00119                 }
00120                 else { //latin1 expected, convert to UTF-8
00121                     SWBuf t((*confEntry).second.c_str());
00122                     t = StringHelper::getSystemStringHelper()->latin2unicode( t );
00123                     
00124                     p->lookupTable.insert(LookupMap::value_type(text, t.c_str()));
00125                 }
00126             }
00127             else { //no stringhelper, just insert. Nothing we can do*/
00128                 p->lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
00129 //          }
00130             
00131         }
00132         entry = p->lookupTable.find(text);
00133     }
00134     return (*entry).second.c_str();
00135 }


Member Data Documentation

int SWLocale::abbrevsCnt [private]

Definition at line 51 of file swlocale.h.

struct abbrev* SWLocale::bookAbbrevs [read, private]

Definition at line 50 of file swlocale.h.

const char** SWLocale::bookLongNames [private]

Definition at line 52 of file swlocale.h.

const char** SWLocale::bookPrefAbbrev [private]

Definition at line 53 of file swlocale.h.

const char * SWLocale::DEFAULT_LOCALE_NAME = "en" [static]

Definition at line 73 of file swlocale.h.

char* SWLocale::description [private]

Definition at line 48 of file swlocale.h.

char* SWLocale::encoding [private]

Definition at line 49 of file swlocale.h.

Definition at line 45 of file swlocale.h.

char* SWLocale::name [private]

Definition at line 47 of file swlocale.h.

Private* SWLocale::p [private]

Definition at line 41 of file swlocale.h.


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

Generated on 18 Mar 2013 for The SWORD Project by  doxygen 1.6.1