The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SWLocale Class Reference

#include <swlocale.h>

+ Collaboration diagram for SWLocale:

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 51 of file swlocale.cpp.

51  {
52  p = new Private;
53  ConfigEntMap::iterator confEntry;
54 
55  name = 0;
56  description = 0;
57  encoding = 0;
58  bookAbbrevs = 0;
59  bookLongNames = 0;
60  bookPrefAbbrev = 0;
61  if (ifilename) {
62  localeSource = new SWConfig(ifilename);
63  }
64  else {
65  localeSource = new SWConfig(0);
66  (*localeSource)["Meta"]["Name"] = DEFAULT_LOCALE_NAME;
67  (*localeSource)["Meta"]["Description"] = "English (US)";
70  }
71 
72  confEntry = localeSource->getSection("Meta").find("Name");
73  if (confEntry != localeSource->getSection("Meta").end())
74  stdstr(&name, (*confEntry).second.c_str());
75 
76  confEntry = localeSource->getSection("Meta").find("Description");
77  if (confEntry != localeSource->getSection("Meta").end())
78  stdstr(&description, (*confEntry).second.c_str());
79 
80  confEntry = localeSource->getSection("Meta").find("Encoding"); //Either empty (==Latin1) or UTF-8
81  if (confEntry != localeSource->getSection("Meta").end())
82  stdstr(&encoding, (*confEntry).second.c_str());
83 }
Private * p
Definition: swlocale.h:43
SWORD_NAMESPACE_START struct abbrev builtin_abbrevs[]
Definition: canon_abbrevs.h:36
char * name
Definition: swlocale.h:49
int abbrevsCnt
Definition: swlocale.h:53
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
ConfigEntMap & getSection(const char *section)
Definition: swconfig.h:76
static const char * DEFAULT_LOCALE_NAME
Definition: swlocale.h:75
char * encoding
Definition: swlocale.h:51
struct abbrev * bookAbbrevs
Definition: swlocale.h:52
char * description
Definition: swlocale.h:50
SWConfig * localeSource
Definition: swlocale.h:47
const char ** bookPrefAbbrev
Definition: swlocale.h:55
const char * osis
const char ** bookLongNames
Definition: swlocale.h:54
SWLocale::~SWLocale ( )
virtual

Definition at line 86 of file swlocale.cpp.

86  {
87 
88  delete localeSource;
89 
90  if (encoding)
91  delete [] encoding;
92 
93  if (description)
94  delete [] description;
95 
96  if (name)
97  delete [] name;
98 
100  delete [] bookAbbrevs;
101 
102  delete p;
103 }
Private * p
Definition: swlocale.h:43
SWORD_NAMESPACE_START struct abbrev builtin_abbrevs[]
Definition: canon_abbrevs.h:36
char * name
Definition: swlocale.h:49
char * encoding
Definition: swlocale.h:51
struct abbrev * bookAbbrevs
Definition: swlocale.h:52
char * description
Definition: swlocale.h:50
SWConfig * localeSource
Definition: swlocale.h:47

Member Function Documentation

void SWLocale::augment ( SWLocale addFrom)
virtual

Definition at line 173 of file swlocale.cpp.

173  {
174  *localeSource += *addFrom.localeSource;
175 }
SWConfig * localeSource
Definition: swlocale.h:47
struct abbrev * SWLocale::getBookAbbrevs ( int *  retSize)
virtual

Definition at line 178 of file swlocale.cpp.

178  {
179  static const char *nullstr = "";
180  if (!bookAbbrevs) {
181  // Assure all english abbrevs are present
182  for (int j = 0; builtin_abbrevs[j].osis[0]; j++) {
184  }
185  ConfigEntMap::iterator it = localeSource->getSection("Book Abbrevs").begin();
186  ConfigEntMap::iterator end = localeSource->getSection("Book Abbrevs").end();
187  for (; it != end; it++) {
188  p->mergedAbbrevs[it->first.c_str()] = it->second.c_str();
189  }
190  int size = (int)p->mergedAbbrevs.size();
191  bookAbbrevs = new struct abbrev[size + 1];
192  int i = 0;
193  for (LookupMap::iterator it = p->mergedAbbrevs.begin(); it != p->mergedAbbrevs.end(); it++, i++) {
194  bookAbbrevs[i].ab = it->first.c_str();
195  bookAbbrevs[i].osis = it->second.c_str();
196  }
197 
198  bookAbbrevs[i].ab = nullstr;
199  bookAbbrevs[i].osis = nullstr;
200  abbrevsCnt = size;
201  }
202 
203  *retSize = abbrevsCnt;
204  return bookAbbrevs;
205 }
Private * p
Definition: swlocale.h:43
SWORD_NAMESPACE_START struct abbrev builtin_abbrevs[]
Definition: canon_abbrevs.h:36
const char * ab
int abbrevsCnt
Definition: swlocale.h:53
ConfigEntMap & getSection(const char *section)
Definition: swconfig.h:76
struct abbrev * bookAbbrevs
Definition: swlocale.h:52
SWConfig * localeSource
Definition: swlocale.h:47
int size
Definition: regex.c:5043
LookupMap mergedAbbrevs
Definition: swlocale.cpp:47
const char * osis
const char * SWLocale::getDescription ( )
virtual
Returns
The description. A possible example is "German".

Definition at line 163 of file swlocale.cpp.

163  {
164  return description;
165 }
char * description
Definition: swlocale.h:50
const char * SWLocale::getEncoding ( )
virtual

Definition at line 168 of file swlocale.cpp.

168  {
169  return encoding;
170 }
char * encoding
Definition: swlocale.h:51
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 158 of file swlocale.cpp.

158  {
159  return name;
160 }
char * name
Definition: swlocale.h:49
virtual SWLocale& SWLocale::operator+= ( SWLocale addFrom)
inlinevirtual

Definition at line 73 of file swlocale.h.

73 { augment(addFrom); return *this; }
virtual void augment(SWLocale &addFrom)
Definition: swlocale.cpp:173
const char * SWLocale::translate ( const char *  text)
virtual

Definition at line 106 of file swlocale.cpp.

106  {
107  LookupMap::iterator entry;
108 
109  entry = p->lookupTable.find(text);
110 
111  if (entry == p->lookupTable.end()) {
112  ConfigEntMap::const_iterator confEntry;
113  bool found = false;
114 
115  SWBuf textBuf = text;
116  if (textBuf.startsWith("prefAbbr_")) {
117  textBuf.stripPrefix('_');
118  confEntry = localeSource->getSection("Pref Abbrevs").find(textBuf);
119  found = (confEntry != localeSource->getSection("Pref Abbrevs").end());
120  }
121  if (!found) {
122  confEntry = localeSource->getSection("Text").find(textBuf);
123  found = (confEntry != localeSource->getSection("Text").end());
124  }
125 
126  if (!found) {
127  p->lookupTable.insert(LookupMap::value_type(text, textBuf.c_str()));
128  }
129  else {//valid value found
130  /*
131  - If Encoding==Latin1 and we have a StringHelper, convert to UTF-8
132  - If StringHelper present and Encoding is UTF-8, use UTF8
133  - If StringHelper not present and Latin1, use Latin1
134  - If StringHelper not present and UTF-8, no idea what to do. Should't happen
135  */
136 /* if (StringHelper::getSystemStringHelper()) {
137  if (!strcmp(encoding, "UTF-8")) {
138  p->lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
139  }
140  else { //latin1 expected, convert to UTF-8
141  SWBuf t((*confEntry).second.c_str());
142  t = StringHelper::getSystemStringHelper()->latin2unicode( t );
143 
144  p->lookupTable.insert(LookupMap::value_type(text, t.c_str()));
145  }
146  }
147  else { //no stringhelper, just insert. Nothing we can do*/
148  p->lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
149 // }
150 
151  }
152  entry = p->lookupTable.find(text);
153  }
154  return (*entry).second.c_str();
155 }
Private * p
Definition: swlocale.h:43
Definition: swbuf.h:47
LookupMap lookupTable
Definition: swlocale.cpp:46
bool startsWith(const SWBuf &prefix) const
Definition: swbuf.h:486
ConfigEntMap & getSection(const char *section)
Definition: swconfig.h:76
const char * c_str() const
Definition: swbuf.h:158
const char * stripPrefix(char separator, bool endOfStringAsSeparator=false)
Definition: swbuf.h:457
SWConfig * localeSource
Definition: swlocale.h:47

Member Data Documentation

int SWLocale::abbrevsCnt
private

Definition at line 53 of file swlocale.h.

struct abbrev* SWLocale::bookAbbrevs
private

Definition at line 52 of file swlocale.h.

const char** SWLocale::bookLongNames
private

Definition at line 54 of file swlocale.h.

const char** SWLocale::bookPrefAbbrev
private

Definition at line 55 of file swlocale.h.

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

Definition at line 75 of file swlocale.h.

char* SWLocale::description
private

Definition at line 50 of file swlocale.h.

char* SWLocale::encoding
private

Definition at line 51 of file swlocale.h.

SWConfig* SWLocale::localeSource
private

Definition at line 47 of file swlocale.h.

char* SWLocale::name
private

Definition at line 49 of file swlocale.h.

Private* SWLocale::p
private

Definition at line 43 of file swlocale.h.


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