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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.