Changeset 1856


Ignore:
Timestamp:
2001-01-23T10:58:19+13:00 (23 years ago)
Author:
sjboddie
Message:

Added Encoding and Language options to main.cfg configuration file so
it's now hopefully a little easier to add new languages and encodings
to the interface. Each interface language also now has a default encoding
so that changing languages from the preferences page causes the encoding
to change to a value reasonable for the selected language.

Location:
trunk/gsdl
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/etc/main.cfg

    r1811 r1856  
    2828# Set logcgiargs to true to keep a log of usage information in
    2929# $GSDLHOME/etc/usage.txt.
    30 logcgiargs      false
     30logcgiargs      true
    3131
    3232# Set usecookies to true to use cookies to identify users (cookie
    3333# information will be written to the usage log if logcgiargs is
    3434# true).
    35 usecookies      false
     35usecookies      true
    3636
    3737# LogDateFormat sets the format that timestamps will be stored in the usage
     
    7575        port.dm home.dm collect.dm
    7676
     77
     78# Define the interface languages and encodings supported by this receptionist
     79
     80# An "Encoding" line defines an encoding to be used by the receptionist
     81# options are:
     82# shortname -- Identifier for the given encoding. The shortname option is
     83#              mandatory and must be unique for each "Encoding" line.
     84# longname  -- The display name of the given encoding. If longname isn't set
     85#              it will default to using shortname instead.
     86
     87# type      -- The type of encoding. Note that for most encodings this
     88#              value is the directory name under which the map file for
     89#              this encoding resides in the Greenstone unicode/MAPPINGS
     90#              directory (e.g. 'WINDOWS', 'ISO_8859' etc.). It may also
     91#              take the values 'GB' and 'UTF8'.
     92# mapfile   -- The name of the map file for use when converting between
     93#              utf8 and the given encoding. The mapfile option is mandatory
     94#              for all encoding types with the exception of GB and UTF8.
     95# label     -- The standard label to which you must set the value of
     96#              "charset" within http headers or html meta tags to get a web
     97#              browser to use the given encoding. The label option is
     98#              mandatory.
     99Encoding shortname=utf8 "longname=Unicode (UTF-8)" type=UTF8 label=UTF-8
     100Encoding shortname=iso1 "longname=Western (ISO-8859-1)" type=ISO_8859 mapfile=1.TXT label=ISO-8859-1
     101Encoding shortname=w1251 "longname=Cyrillic (Windows-1251)" type=WINDOWS mapfile=1251.TXT label=windows-1251
     102Encoding shortname=w1256 "longname=Arabic (Windows-1256)" type=WINDOWS mapfile=1256.TXT label=windows-1256
     103Encoding shortname=gb "longname=Simplified Chinese (GBK)" type=GB label=GBK
     104Encoding shortname=koi8r "longname=Cyrillic (KOI8-R)" type=CYRILLIC mapfile=koi8_r.txt label=koi8-r
     105
     106
     107# A "Language" line defines an interface language to be used by the
     108# interface. Note that it is possible to display only a subset of the
     109# specified languages on the preferences page for a given collection by
     110# using the "PreferenceLanguages" format option in your collect.cfg
     111# configuration file.
     112# options are:
     113# shortname        -- ISO 639 two letter language symbol. The shortname
     114                      option is mandatory.
     115# longname         -- The display name for the given language. If longname
     116                      isn't set it will default to using shortname instead.
     117# default_encoding -- The encoding to use by default when using the given
     118#                     interface language. This should be set to the
     119#                     "shortname" of a valid "Encoding" line
     120Language shortname=en longname=English default_encoding=iso1
     121Language shortname=fr longname=French default_encoding=iso1
     122Language shortname=zh longname=Chinese default_encoding=gb
     123Language shortname=de longname=German default_encoding=iso1
     124Language shortname=es longname=Spanish default_encoding=iso1
     125Language shortname=mi longname=Maori default_encoding=iso1
     126Language shortname=ar longname=Arabic default_encoding=w1256
     127Language shortname=pt longname=Portuguese default_encoding=iso1
     128Language shortname=nl longname=Dutch default_encoding=iso1
     129
     130
    77131# Define any additional page parameters to be used by the above macro files
    78132# (the current default page parameters are c (collection) and l (language)
     
    113167# set a default value for the built-in "p" cgi argument
    114168cgiarg          shortname=p argdefault=home
     169
  • trunk/gsdl/macros/english.dm

    r1806 r1856  
    627627_textdigitlib_ {the digital library}
    628628_textweb_ {the web}
    629 _textlangeng_ {English}
    630 _textlanggerman_ {German}
    631 _textlangfrench_ {French}
    632 _textlangspanish_ {Spanish}
    633 _textlangmaori_ {M_amn_ori}
    634 _textlangchinese_ {Chinese}
    635 _textlangarabic_ {Arabic}
    636 _textlangportuguese_ {Portuguese}
    637 _textlangdutch_ {Dutch}
    638629_textgraphical_ {Graphical}
    639630_texttextual_ {Textual}
  • trunk/gsdl/macros/pref.dm

    r1838 r1856  
    200200function updatel () \{
    201201  value = document.PrefForm.l.options[document.PrefForm.l.selectedIndex].value;
    202   location.href = location.href + "&l=" + value + getargs();
     202  location.href = location.href + "&nl=1&l=" + value + getargs();
    203203\}
    204204
     
    210210function updatew () \{
    211211  value = document.PrefForm.w.options[document.PrefForm.w.selectedIndex].value;
    212   location.href = location.href + "&nw=" + value + getargs();
     212  location.href = location.href + "&nl=0&nw=" + value + getargs();
    213213\}
    214214}
     
    330330}
    331331
     332# set from within pageaction
    332333_languageoption_ {}
    333 
    334 _enlanguageoption_ {<option value="en"_If_("_cgiargl_",, selected)_If_("_cgiargl_" eq "en", selected)>_textlangeng_}
    335 _delanguageoption_ {<option value="de"_If_("_cgiargl_" eq "de", selected)>_textlanggerman_}
    336 _frlanguageoption_ {<option value="fr"_If_("_cgiargl_" eq "fr", selected)>_textlangfrench_}
    337 _eslanguageoption_ {<option value="es"_If_("_cgiargl_" eq "es", selected)>_textlangspanish_}
    338 _milanguageoption_ {<option value="mi"_If_("_cgiargl_" eq "mi", selected)>_textlangmaori_}
    339 _zhlanguageoption_ {<option value="zh"_If_("_cgiargl_" eq "zh", selected)>_textlangchinese_}
    340 _arlanguageoption_ {<option value="ar"_If_("_cgiargl_" eq "ar", selected)>_textlangarabic_}
    341 _ptlanguageoption_ {<option value="pt"_If_("_cgiargl_" eq "pt", selected)>_textlangportuguese_}
    342 _nllanguageoption_ {<option value="nl"_If_("_cgiargl_" eq "nl", selected)>_textlangdutch_}
    343 
    344 _encodingoption_ {
    345 _textencoding_
    346 <select name="w" onChange="updatew();">
    347   <option value="w" _If_("_cgiargw_" eq "w",selected)>Western (ISO-8859-1)
    348   <option value="u" _If_("_cgiargw_" eq "u",selected)>UTF-8
    349   <option value="g" _If_("_cgiargw_" eq "g",selected)>GBK
    350   <option value="a" _If_("_cgiargw_" eq "a",selected)>Arabic (windows 1256)
    351   <option value="c" _If_("_cgiargw_" eq "c",selected)>Cyrillic (windows 1251)
    352 </select>
    353 }
     334_encodingoption_ {}
    354335
    355336_formatoption_ {
     
    365346_navigationbar_
    366347</center>
     348
    367349<blockquote>
    368350
     
    409391
    410392<p>
    411 _languageoption_
    412 
    413 <p>
    414 _encodingoption_
     393_If_(_languageoption_,_textlanguage__languageoption_)
     394
     395<p>
     396_If_(_encodingoption_,_textencoding__encodingoption_)
    415397
    416398<p>
  • trunk/gsdl/src/recpt/librarymain.cpp

    r1838 r1856  
    111111#endif
    112112
     113  // Read main.cfg to get all the "Encoding" lines and add corresponding converters.
     114  // It might be possible to move this to somewhere like receptionist::configure, depending
     115  // on whether we need the converters before then (I don't think we do).
     116  text_tarray cfgline;
     117  text_t maincfg = filename_cat (gsdlhome, "etc", "main.cfg");
     118  if (file_exists (maincfg)) {
     119    char *maincfgc = maincfg.getcstr();
     120#ifdef GSDL_USE_IOS_H
     121    ifstream confin (maincfgc, ios::in | ios::nocreate);
     122#else
     123    ifstream confin (maincfgc, ios::in);
     124#endif
     125    delete maincfgc;
     126 
     127    if (confin) {
     128      text_t subkey, subvalue, shortname;
     129      text_tset saved;
     130      text_tmap tmp;
     131      text_t::const_iterator cfglinesub_here;
     132      text_tarray::const_iterator cfgline_here;
     133      text_tarray::const_iterator cfgline_end;
     134      while (read_cfg_line(confin, cfgline) >= 0) {
     135    if (cfgline.size () >= 4 && cfgline[0] == "Encoding") {
     136      tmp.erase(tmp.begin(), tmp.end());
     137      cfgline_here = cfgline.begin();
     138      cfgline_end = cfgline.end();
     139      while (cfgline_here != cfgline_end) {
     140        cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
     141                        (*cfgline_here).end(), '=', subkey);
     142        if (subkey == "shortname") {
     143          shortname = substr (cfglinesub_here, (*cfgline_here).end());
     144        } else {
     145          tmp[subkey] = substr (cfglinesub_here, (*cfgline_here).end());
     146        }
     147        cfgline_here++;
     148      }
     149      // we just use the saved set to prevent multiple encodings being added
     150      // that use the same shortname (i.e. any encodings after the first with
     151      // the same name will be ignored).
     152      if (!shortname.empty() && saved.find(shortname) == saved.end()) {
     153        saved.insert(shortname);
     154
     155        if (tmp["type"] == "UTF8") {
     156          utf8inconvertclass *utf8inconvert = new utf8inconvertclass();
     157          utf8outconvertclass *utf8outconvert = new utf8outconvertclass();
     158          recpt.add_converter (shortname, utf8inconvert, utf8outconvert);
     159
     160        } else if (tmp["type"] == "GB") {
     161          mapinconvertclass *gbinconvert = new mapinconvertclass();
     162          gbinconvert->setmapfile (gsdlhome, "gbku", 0x25a1);
     163          mapoutconvertclass *gboutconvert = new mapoutconvertclass();
     164          gboutconvert->setmapfile (gsdlhome, "ugbk", 0xa1f5);
     165          recpt.add_converter (shortname, gbinconvert, gboutconvert);
     166
     167        } else {
     168          if (!tmp["mapfile"].empty()) {
     169
     170        if (tmp["type"] == "ISO_8859" && tmp["mapfile"] == "1.TXT") {
     171          // iso-8859-1 is a special case as it'll always be
     172          // supported by the standard converter class and
     173          // therefore doesn't need to use its mapping file
     174          inconvertclass *inconvert = new inconvertclass();
     175          rzwsoutconvertclass *outconvert = new rzwsoutconvertclass();
     176          recpt.add_converter (shortname, inconvert, outconvert); 
     177
     178        } else {
     179          text_t mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS", tmp["type"], tmp["mapfile"]);
     180          if (file_exists (mapfile)) {
     181            simplemapinconvertclass *inconvert = new simplemapinconvertclass();
     182            inconvert->setmapfile (mapfile);
     183            simplemapoutconvertclass *outconvert = new simplemapoutconvertclass();
     184            outconvert->setmapfile (mapfile);
     185            recpt.add_converter (shortname, inconvert, outconvert); 
     186          }
     187        }
     188          }
     189        }
     190      }
     191    }
     192      }
     193      confin.close ();
     194    }
     195  }
     196
     197
    113198  // add other converters
    114   utf8inconvertclass utf8inconvert;
    115   utf8outconvertclass utf8outconvert;
    116   recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
    117 
    118   mapinconvertclass gbinconvert;
    119   gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
    120   mapoutconvertclass gboutconvert;
    121   gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
    122   recpt.add_converter ("g", &gbinconvert, &gboutconvert);
     199  //  utf8inconvertclass utf8inconvert;
     200  //  utf8outconvertclass utf8outconvert;
     201  //  recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
     202
     203  //  mapinconvertclass gbinconvert;
     204  //  gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
     205  //  mapoutconvertclass gboutconvert;
     206  //  gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
     207  //  recpt.add_converter ("g", &gbinconvert, &gboutconvert);
    123208
    124209  // arabic
    125   text_t mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
    126   mapfile = filename_cat (mapfile, "WINDOWS", "1256.TXT");
    127   simplemapinconvertclass arinconvert;
    128   arinconvert.setmapfile (mapfile);
    129   simplemapoutconvertclass aroutconvert;
    130   aroutconvert.setmapfile (mapfile);
    131   recpt.add_converter ("a", &arinconvert, &aroutconvert); 
     210  //  text_t mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
     211  //  mapfile = filename_cat (mapfile, "WINDOWS", "1256.TXT");
     212  //  simplemapinconvertclass arinconvert;
     213  //  arinconvert.setmapfile (mapfile);
     214  //  simplemapoutconvertclass aroutconvert;
     215  //  aroutconvert.setmapfile (mapfile);
     216  //  recpt.add_converter ("a", &arinconvert, &aroutconvert); 
    132217
    133218  // cyrillic
    134   mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
    135   mapfile = filename_cat (mapfile, "WINDOWS", "1251.TXT");
    136   simplemapinconvertclass cyinconvert;
    137   cyinconvert.setmapfile (mapfile);
    138   simplemapoutconvertclass cyoutconvert;
    139   cyoutconvert.setmapfile (mapfile);
    140   recpt.add_converter ("c", &cyinconvert, &cyoutconvert); 
     219  //  mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
     220  //  mapfile = filename_cat (mapfile, "WINDOWS", "1251.TXT");
     221  //  simplemapinconvertclass cyinconvert;
     222  //  cyinconvert.setmapfile (mapfile);
     223  //  simplemapoutconvertclass cyoutconvert;
     224  //  cyoutconvert.setmapfile (mapfile);
     225  //  recpt.add_converter ("c", &cyinconvert, &cyoutconvert); 
    141226 
    142227  // hindi
  • trunk/gsdl/src/recpt/pageaction.cpp

    r1759 r1856  
    187187  // _languageoption_      interface languages to select from (dependant on PreferenceLanguages)
    188188
    189   // _encodingoption_      will be overridden to "" if chinese language interface isn't specified
     189  // _encodingoption_      encodings to select from
    190190
    191191  // if page is "about"
     
    283283
    284284    // _languageoption_
    285     // this is kind of a hack (another one!!). note that there're potential
    286     // problems here as no checking is done anywhere to make sure language
    287     // is set to a valid value. this does allow us to set which languages
    288     // should go in the preference selection box (from collect.cfg) however
    289     // and that's sufficient for current requirements
    290    
    291     // currently supported languages (_languageoption_ will default to all
    292     // these languages unless PreferenceLanguages is set
    293     text_tarray languages;
    294     languages.push_back ("en");
    295     languages.push_back ("fr");
    296     languages.push_back ("de");
    297     languages.push_back ("es");
    298     languages.push_back ("mi");
    299     languages.push_back ("zh");
    300     languages.push_back ("ar");
    301     languages.push_back ("pt");
    302     languages.push_back ("nl");
    303     text_tarray::const_iterator this_lang = languages.begin();
    304     text_tarray::const_iterator end_lang = languages.end();
    305 
    306     text_t languageoption = "_textlanguage_\n<select name=\"l\" onChange=\"updatel();\">\n";
     285    // Create the "interface language" selection box for the preferences page.
     286    // You can use something like "format PreferenceLanguages en|fr|zn" from within
     287    // a collect.cfg file to use only a subset of the available languages for
     288    // any given collection. This facility is kind of ugly though and should be
     289    // replaced by something better when the configuration files are tidied up (as
     290    // should all the other "format Preference..." options).
     291   
     292    text_t &arg_l = args["l"];
     293    const recptconf &configinfo = recpt->get_configinfo();
     294    // put languages in another map to sort them by longname
     295    text_tmap languages;
     296    languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
     297    languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
     298    while (thislang != endlang) {
     299      languages[(*thislang).second.longname] = (*thislang).first;
     300      thislang++;
     301    }
     302    text_tmap::iterator tlang = languages.begin();
     303    text_tmap::iterator elang = languages.end();
     304
     305    text_t languageoption;
    307306    it = cinfo->format.find ("PreferenceLanguages");
    308307    if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
     
    310309      splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
    311310      if (pref_langs.size() > 1) {
    312     while (this_lang != end_lang) {
    313       if (pref_langs.find(*this_lang) != pref_langs.end())
    314         languageoption += "_" + *this_lang + "languageoption_\n";
    315       this_lang ++;
     311    while (tlang != elang) {
     312      if (pref_langs.find((*tlang).second) != pref_langs.end()) {
     313        languageoption += "<option value=\"" + (*tlang).second + "\"";
     314        if ((*tlang).second == arg_l) languageoption += " selected";
     315        languageoption += ">" + (*tlang).first + "\n";
     316      }
     317      tlang ++;
    316318    }
    317     languageoption += "</select>\n";
    318     disp.setmacro ("languageoption", "preferences", languageoption);
    319       }
    320    
    321       // _encodingoption_
    322 
    323       if (pref_langs.find("zh") == pref_langs.end())
    324     disp.setmacro ("encodingoption", "preferences", "");
     319      }
    325320
    326321    } else {
    327       while (this_lang != end_lang) {
    328     languageoption += "_" + *this_lang + "languageoption_\n";
    329     this_lang ++;
    330       }
     322      while (tlang != elang) {
     323    languageoption += "<option value=\"" + (*tlang).second + "\"";
     324    if ((*tlang).second == arg_l) languageoption += " selected";
     325    languageoption += ">" + (*tlang).first + "\n";
     326    tlang ++;
     327      }
     328    }
     329    if (!languageoption.empty()) {
     330      languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
    331331      languageoption += "</select>\n";
    332332      disp.setmacro ("languageoption", "preferences", languageoption);
     333    }
     334
     335    // _encodingoption_
     336    // create the "encoding" selection box for the preferences page
     337    text_t &arg_w = args["w"];
     338    // put encodings in another map to sort them by longname
     339    text_tmap encodings;
     340    encodinginfo_tmap::const_iterator thisenc = configinfo.encodings.begin();
     341    encodinginfo_tmap::const_iterator endenc = configinfo.encodings.end();
     342    while (thisenc != endenc) {
     343      encodings[(*thisenc).second.longname] = (*thisenc).first;
     344      thisenc++;
     345    }
     346    text_tmap::iterator tenc = encodings.begin();
     347    text_tmap::iterator eenc = encodings.end();
     348
     349    text_t encodingoption;
     350    while (tenc != eenc) {
     351      encodingoption += "<option value=\"" + (*tenc).second + "\"";
     352      if ((*tenc).second == arg_w) encodingoption += " selected";
     353      encodingoption += ">" + (*tenc).first + "\n";
     354      tenc ++;
     355    }
     356
     357    if (!encodingoption.empty()) {
     358      encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
     359      encodingoption += "</select>\n";
     360      disp.setmacro ("encodingoption", "preferences", encodingoption);
    333361    }
    334362   
  • trunk/gsdl/src/recpt/receptionist.cpp

    r1838 r1856  
    6565  EmailUserEvents = false;
    6666
     67  languages.erase(languages.begin(), languages.end());
     68  encodings.erase(encodings.begin(), encodings.end());
     69
    6770  // these default page parameters can always be overriden
    6871  // in the configuration file
     
    8487  info_loaded = false;
    8588  info.clear();
     89}
     90
     91void languageinfo_t::clear () {
     92  longname.clear();
     93  defaultencoding.clear();
     94}
     95
     96void encodinginfo_t::clear () {
     97  longname.clear();
     98  label.clear();
    8699}
    87100
     
    112125  ainfo.longname = "encoding";
    113126  ainfo.multiplechar = true;
    114   ainfo.defaultstatus = cgiarginfo::weak;
    115   ainfo.argdefault = "w";
     127  ainfo.defaultstatus = cgiarginfo::none;
     128  ainfo.argdefault = "";
    116129  ainfo.savedarginfo = cgiarginfo::must;
    117130  argsinfo.addarginfo (NULL, ainfo);
     
    142155  ainfo.savedarginfo = cgiarginfo::must;
    143156  argsinfo.addarginfo (NULL, ainfo);
    144 
     157 
     158  ainfo.shortname = "nl";
     159  ainfo.longname = "new language";
     160  ainfo.multiplechar = false;
     161  ainfo.defaultstatus = cgiarginfo::none;
     162  ainfo.argdefault = "0";
     163  ainfo.savedarginfo = cgiarginfo::mustnot;
     164  argsinfo.addarginfo (NULL, ainfo);
     165 
    145166  // the GSDL_UID (cookie)
    146167  ainfo.shortname = "z";
     
    293314      cfgline_here++;
    294315    }
     316      }
     317
     318    } else if (key == "Encoding") {
     319      text_t subkey, subvalue;
     320      text_t shortname, longname, label;
     321      text_t::const_iterator cfglinesub_here;
     322      text_tarray::const_iterator cfgline_here = cfgline.begin();
     323      text_tarray::const_iterator cfgline_end = cfgline.end();
     324      while (cfgline_here != cfgline_end) {
     325    cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
     326                    (*cfgline_here).end(), '=', subkey);
     327    if (subkey == "shortname") {
     328      shortname = substr (cfglinesub_here, (*cfgline_here).end());
     329    } else if (subkey == "longname") {
     330      longname = substr (cfglinesub_here, (*cfgline_here).end());
     331    } else if (subkey == "label") {
     332      label = substr (cfglinesub_here, (*cfgline_here).end());
     333    }
     334    cfgline_here++;
     335      }
     336      if (!shortname.empty() && !label.empty()) {
     337    encodinginfo_t enc;
     338    if (longname.empty()) enc.longname = shortname;
     339    else enc.longname = longname;
     340    enc.label = label;
     341    configinfo.encodings[shortname] = enc;
     342      }
     343
     344    } else if (key == "Language") {
     345      text_t subkey, subvalue;
     346      text_t shortname, longname, defaultencoding;
     347      text_t::const_iterator cfglinesub_here;
     348      text_tarray::const_iterator cfgline_here = cfgline.begin();
     349      text_tarray::const_iterator cfgline_end = cfgline.end();
     350      while (cfgline_here != cfgline_end) {
     351    cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
     352                    (*cfgline_here).end(), '=', subkey);
     353    if (subkey == "shortname") {
     354      shortname = substr (cfglinesub_here, (*cfgline_here).end());
     355    } else if (subkey == "longname") {
     356      longname = substr (cfglinesub_here, (*cfgline_here).end());
     357    } else if (subkey == "default_encoding") {
     358      defaultencoding = substr (cfglinesub_here, (*cfgline_here).end());
     359    }
     360    cfgline_here++;
     361      }
     362      if (!shortname.empty()) {
     363    languageinfo_t lang;
     364    if (longname.empty()) lang.longname = shortname;
     365    else lang.longname = longname;
     366    lang.defaultencoding = defaultencoding;
     367    configinfo.languages[shortname] = lang;
    295368      }
    296369    }
     
    400473  convertinfoclass::iterator converthere = converters.begin ();
    401474  convertinfoclass::iterator convertend = converters.end ();
    402   text_t defaultconvertname;
    403475  while (converthere != convertend) {
    404476    assert ((*converthere).second.outconverter != NULL);
    405477    if ((*converthere).second.outconverter != NULL) {
    406478      (*converthere).second.outconverter->set_rzws(1);
    407       if (defaultconvertname.empty())
    408     defaultconvertname = (*converthere).second.name;
    409479    }
    410480    converthere++;
    411   }
    412  
    413   // set default converter if no good one has been defined
    414   if (!defaultconvertname.empty()) {
    415     cgiarginfo *ainfo = argsinfo.getarginfo ("w");
    416     if (ainfo->argdefault != "w") {
    417       if ((ainfo != NULL) && (converters.get_outconverter(ainfo->argdefault) == NULL)) {
    418     ainfo->defaultstatus = cgiarginfo::good;
    419     ainfo->argdefault = defaultconvertname;
    420       }
    421     }
    422481  }
    423482
     
    470529}
    471530
     531// get the default encoding for the given language - if it fails for any
     532// reason return ""
     533text_t receptionist::get_default_encoding (const text_t &language) {
     534 
     535  // make sure language is valid
     536  if (configinfo.languages.find(language) == configinfo.languages.end()) return "";
     537
     538  text_t default_encoding = configinfo.languages[language].defaultencoding;
     539
     540  // make sure the encoding is valid
     541  if (configinfo.encodings.find(default_encoding) == configinfo.encodings.end()) return "";
     542
     543  return default_encoding;
     544}
    472545
    473546// parse_cgi_args parses cgi arguments into an argument class.
     
    476549bool receptionist::parse_cgi_args (const text_t &argstr, cgiargsclass &args,
    477550                   ostream &logout, text_tmap &fcgienv) {
    478   outconvertclass text_t2ascii;
    479551
    480552  // get an initial list of cgi arguments
     
    491563  if (configinfo.usecookies) get_cookie(args["z"], fcgienv);
    492564 
     565  // if we're changing languages, set the encoding to the default for the new language
     566  if (args["nl"] == "1") {
     567    args["nw"] = get_default_encoding(args["l"]);
     568  }
     569
    493570  // get the input encoding
     571  // if encoding isn't set, set it to the default for the current language
     572  if ((args.getarg("w") == NULL) || args["w"].empty()) {
     573    args["w"] = get_default_encoding(args["l"]);
     574  }
     575
    494576  text_t &arg_w = args["w"];
     577
    495578  inconvertclass defaultinconvert;
    496579  inconvertclass *inconvert = converters.get_inconverter (arg_w);
     
    520603  } else {
    521604    // the action was not found!!
     605    outconvertclass text_t2ascii;
    522606    logout << text_t2ascii << "Error: the action \"" << args["a"]
    523607       << "\" could not be found.\n";
     
    744828  // add the encoding information
    745829  if (response == content) {
    746     if (args["w"] == "u") {
    747       response_data += "; charset=UTF-8";
    748     } else if (args["w"] == "g") {
    749       response_data += "; charset=GBK";
    750     } else if (args["w"] == "a") {
    751       response_data += "; charset=windows-1256";
    752     } else if (args["w"] == "c") {
    753       response_data += "; charset=windows-1251";
     830    if (configinfo.encodings.find(args["w"]) != configinfo.encodings.end()) {
     831      response_data += "; charset=" + configinfo.encodings[args["w"]].label;
    754832    } else {
    755       response_data += "; charset=ISO-8859-1";     
     833      // default to latin 1
     834      response_data += "; charset=ISO-8859-1";
    756835    }
    757836
  • trunk/gsdl/src/recpt/receptionist.h

    r1779 r1856  
    6060};
    6161
     62struct languageinfo_t {
     63  void clear();
     64  languageinfo_t () {clear();}
     65
     66  text_t longname;
     67  text_t defaultencoding;
     68};
     69
     70struct encodinginfo_t {
     71  void clear();
     72  encodinginfo_t () {clear();}
     73 
     74  text_t longname;
     75  text_t label;
     76};
     77
    6278typedef map<text_t, collectioninfo_t, lttext_t> colinfo_tmap;
     79typedef map<text_t, languageinfo_t, lttext_t> languageinfo_tmap;
     80typedef map<text_t, encodinginfo_t, lttext_t> encodinginfo_tmap;
    6381
    6482enum events_t {Disabled, CollectorEvents, AllEvents};
     
    91109  text_t macroprecedence;
    92110 
     111  languageinfo_tmap languages;
     112  encodinginfo_tmap encodings;
     113
    93114  void clear ();
    94115  recptconf () {clear();}
     
    118139  bool get_cookie (text_t &cookie, text_tmap &fcgienv);
    119140  bool get_cookie (text_tmap &fcgienv);
     141
     142  // get the default encoding for the given language - if it fails for any
     143  // reason, return ""
     144  text_t get_default_encoding (const text_t &language);
    120145
    121146  virtual void define_general_macros (cgiargsclass &args, outconvertclass &outconvert,
Note: See TracChangeset for help on using the changeset viewer.