Esempio n. 1
0
std::string
Dictionary::translate_plural(const Entries& dict, const std::string& msgid, const std::string& msgid_plural, int count)
{
  Entries::const_iterator i = dict.find(msgid);

  if (i != dict.end())
  {
    const std::vector<std::string>& msgstrs = i->second;
    unsigned int n = 0;
    n = plural_forms.get_plural(count);
    assert(/*n >= 0 &&*/ n < msgstrs.size());

    if (!msgstrs[n].empty())
      return msgstrs[n];
    else
      if (count == 1) // default to english rules
        return msgid;
      else
        return msgid_plural;
  }
  else
  {
    log_info << "Couldn't translate: " << msgid << std::endl;
    log_info << "Candidates: " << std::endl;
    for (i = dict.begin(); i != dict.end(); ++i)
      log_info << "'" << i->first << "'" << std::endl;

    if (count == 1) // default to english rules
      return msgid;
    else
      return msgid_plural;
  }
}
Esempio n. 2
0
std::string
Dictionary::translate(const Entries& dict, const std::string& msgid)
{
  Entries::const_iterator i = dict.find(msgid);
  if (i != dict.end() && !i->second.empty())
  {
    return i->second[0];
  }
  else
  {
    log_info << "Couldn't translate: " << msgid << std::endl;
    return msgid;
  } 
}
Esempio n. 3
0
std::string
Dictionary::translate_plural(const Entries& dict, const std::string& msgid, const std::string& msgid_plural, int count) const
{
	Entries::const_iterator it = dict.find(msgid);
	if (it != dict.end())
	{
		unsigned int                  n         = plural_forms.get_plural(count);
		const std::vector<std::string>& msgstrs = it->second;
		if (n >= msgstrs.size())
		{
			log_error << "Plural translation not available (and not set to empty): '" << msgid << "'" << std::endl;
			log_error << "Missing plural form: " << n << std::endl;
			return msgid;
		}

		if (!msgstrs[n].empty())
		{
			return msgstrs[n];
		}
		else
		if (count == 1) // default to english rules
		{
			return msgid;
		}
		else
		{
			return msgid_plural;
		}
	}
	else
	{
		log_info << "Couldn't translate: " << msgid << std::endl;
		log_info << "Candidates: " << std::endl;
		for (it = dict.begin(); it != dict.end(); ++it)
			log_info << "'" << it->first << "'" << std::endl;

		if (count == 1) // default to english rules
		{
			return msgid;
		}
		else
		{
			return msgid_plural;
		}
	}
}