00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <swlocale.h>
00024 #include <utilfuns.h>
00025
00026
00027 SWLocale::SWLocale(const char * ifilename) {
00028 ConfigEntMap::iterator confEntry;
00029
00030 name = 0;
00031 description = 0;
00032 bookAbbrevs = 0;
00033 BMAX = 0;
00034 books = 0;
00035 localeSource = new SWConfig(ifilename);
00036
00037 confEntry = localeSource->Sections["Meta"].find("Name");
00038 if (confEntry != localeSource->Sections["Meta"].end())
00039 stdstr(&name, (*confEntry).second.c_str());
00040
00041 confEntry = localeSource->Sections["Meta"].find("Description");
00042 if (confEntry != localeSource->Sections["Meta"].end())
00043 stdstr(&description, (*confEntry).second.c_str());
00044 }
00045
00046
00047 SWLocale::~SWLocale() {
00048
00049 delete localeSource;
00050
00051 if (description)
00052 delete [] description;
00053
00054 if (name)
00055 delete [] name;
00056
00057 if (bookAbbrevs)
00058 delete [] bookAbbrevs;
00059
00060 if (BMAX) {
00061 for (int i = 0; i < 2; i++)
00062 delete [] books[i];
00063 delete [] BMAX;
00064 delete [] books;
00065 }
00066 }
00067
00068
00069 const char *SWLocale::translate(const char *text) {
00070 LookupMap::iterator entry;
00071
00072 entry = lookupTable.find(text);
00073
00074 if (entry == lookupTable.end()) {
00075 ConfigEntMap::iterator confEntry;
00076 confEntry = localeSource->Sections["Text"].find(text);
00077 if (confEntry == localeSource->Sections["Text"].end())
00078 lookupTable.insert(LookupMap::value_type(text, text));
00079 else lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
00080 entry = lookupTable.find(text);
00081 }
00082 return (*entry).second.c_str();
00083 }
00084
00085
00086 const char *SWLocale::getName() {
00087 return name;
00088 }
00089
00090
00091 const char *SWLocale::getDescription() {
00092 return description;
00093 }
00094
00095
00096 SWLocale &SWLocale::operator +=(SWLocale &addFrom) {
00097 *localeSource += *addFrom.localeSource;
00098 return *this;
00099 }
00100
00101
00102 const struct abbrev *SWLocale::getBookAbbrevs() {
00103 static const char *nullstr = "";
00104 if (!bookAbbrevs) {
00105 ConfigEntMap::iterator it;
00106 int i;
00107 int size = localeSource->Sections["Book Abbrevs"].size();
00108 bookAbbrevs = new struct abbrev[size + 1];
00109 for (i = 0, it = localeSource->Sections["Book Abbrevs"].begin(); it != localeSource->Sections["Book Abbrevs"].end(); it++, i++) {
00110 bookAbbrevs[i].ab = (*it).first.c_str();
00111 bookAbbrevs[i].book = atoi((*it).second.c_str());
00112 }
00113 bookAbbrevs[i].ab = nullstr;
00114 bookAbbrevs[i].book = -1;
00115 }
00116
00117 return bookAbbrevs;
00118 }
00119
00120
00121 void SWLocale::getBooks(char **iBMAX, struct sbook ***ibooks) {
00122 if (!BMAX) {
00123 BMAX = new char [2];
00124 BMAX[0] = VerseKey::builtin_BMAX[0];
00125 BMAX[1] = VerseKey::builtin_BMAX[1];
00126
00127 books = new struct sbook *[2];
00128 books[0] = new struct sbook[BMAX[0]];
00129 books[1] = new struct sbook[BMAX[1]];
00130
00131 for (int i = 0; i < 2; i++) {
00132 for (int j = 0; j < BMAX[i]; j++) {
00133 books[i][j] = VerseKey::builtin_books[i][j];
00134 books[i][j].name = translate(VerseKey::builtin_books[i][j].name);
00135 }
00136 }
00137 }
00138
00139 *iBMAX = BMAX;
00140 *ibooks = books;
00141 }