Beispiel #1
0
void WriteComments(int comm_id, bool bInterLine)
{
  itComments = mapComments.find(comm_id);
  if (itComments == mapComments.end()) // check if we have at least one comment for the xml id
    return;

  itRangeComments = mapComments.equal_range(comm_id);
  for (itComments = itRangeComments.first; itComments != itRangeComments.second;++itComments)
  {
    if (bInterLine == itComments->second.bInterLineComment)
    {
      WriteLF(pPOTFile);
      fprintf(pPOTFile,bInterLine ? "#%s\n": "#. %s\n", itComments->second.text.c_str());
    }
  }

  return;
};
void VFSHandle_ZIP::Write(unsigned char *data, unsigned int length)
{
	LocalFileHeader	*lfh	=	m_lfh[m_fileid];
	FileHeader			*fh		=	m_fh[m_fileid];

	//	compress data
	unsigned char *dest = new unsigned char[length];

	memset(&m_zipstream,0,sizeof(z_stream));

	m_zipstream.avail_in	= length;
	m_zipstream.next_in		=	data;

	m_zipstream.avail_out	= length;
	m_zipstream.next_out	=	dest;

	deflateInit2(&m_zipstream,9,Z_DEFLATED,-15,9,Z_DEFAULT_STRATEGY);
	deflate(&m_zipstream,Z_FINISH);
	deflateEnd(&m_zipstream);

	int crc = crc32(0L, Z_NULL, 0);
	lfh->crc32			=	crc32(crc,data,length);
	lfh->uncomp_size		=	length;
	lfh->comp_size		=	m_zipstream.total_out;
	fh->comp_size		=	m_zipstream.total_out;
	fh->uncomp_size		=	lfh->uncomp_size;
	fh->crc32				=	lfh->crc32;
	fh->relative_offset_lfh	=	m_stream.tellg();

	WriteLF(lfh);

	//	write data to archive
	m_stream.clear();
	m_stream.seekg(lfh->file_data_offset,std::ios::beg);
	m_stream.write((char *)dest,lfh->comp_size);

	delete[] dest;
}
Beispiel #3
0
bool ConvertXML2PO(std::string LangDir, std::string LCode, int nPlurals,
                    std::string PluralForm, bool bIsForeignLang)
{
  int stringCount = 0;
  std::string  OutputPOFilename;

  OutputPOFilename = LangDir + "strings.po";

  // Initalize the output po document
  pPOTFile = fopen (OutputPOFilename.c_str(),"wb");
  if (pPOTFile == NULL)
  {
    printf("Error opening output file: %s\n", OutputPOFilename.c_str());
    return false;
  }
  printf("%s\t\t", LCode.c_str()); 

  fprintf(pPOTFile,
    "# XBMC Media Center language file\n"
    "%s"
    "%s%s%s%s%s%s%s%s%s"
    "msgid \"\"\n"
    "msgstr \"\"\n"
    "\"Project-Id-Version: %s\\n\"\n"
    "\"Report-Msgid-Bugs-To: [email protected]\\n\"\n"
    "\"POT-Creation-Date: %s\\n\"\n"
    "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n"
    "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n"
    "\"Language-Team: LANGUAGE\\n\"\n"
    "\"MIME-Version: 1.0\\n\"\n"
    "\"Content-Type: text/plain; charset=UTF-8\\n\"\n"
    "\"Content-Transfer-Encoding: 8bit\\n\"\n"
    "\"Language: %s\\n\"\n"
    "\"Plural-Forms: nplurals=%i; plural=%s\\n\"\n",
    (projType == CORE) ? ("XBMC " + ProjVersion + "\n").c_str() : "",
    (projType == CORE || projType == UNKNOWN) ? "" : "# Addon Name: ",
    (projType == CORE || projType == UNKNOWN) ? "" : ProjTextName.c_str(),
    (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon id: ",
    (projType == CORE || projType == UNKNOWN) ? "" : ProjName.c_str(),
    (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon version: ",
    (projType == CORE || projType == UNKNOWN) ? "" : ProjVersion.c_str(),
    (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon Provider: ",
    (projType == CORE || projType == UNKNOWN) ? "" : ProjProvider.c_str(),
    (projType == CORE || projType == UNKNOWN) ? "" : "\n",
    (projType == CORE) ? "XBMC-Main" : "XBMC-Addons",
    GetCurrTime().c_str(),
    (!LCode.empty()) ? LCode.c_str() : "LANGUAGE",
    nPlurals, PluralForm.c_str());
    bhasLFWritten =false;

  if (!mapAddonXMLData["en"].strSummary.empty())
  {
    WriteLF(pPOTFile);
    WriteStrLine("msgctxt ", "Addon Summary", addonXMLEncoding);
    WriteStrLine("msgid ", mapAddonXMLData["en"].strSummary.c_str(), addonXMLEncoding);
    WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strSummary.c_str(), addonXMLEncoding);
    bhasLFWritten =false;
    stringCount++;
  }

  if (!mapAddonXMLData["en"].strDescription.empty())
  {
    WriteLF(pPOTFile);
    WriteStrLine("msgctxt ", "Addon Description", addonXMLEncoding);
    WriteStrLine("msgid ", mapAddonXMLData["en"].strDescription.c_str(), addonXMLEncoding);
    WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strDescription.c_str(), addonXMLEncoding);
    bhasLFWritten =false;
    stringCount++;
  }

  if (!mapAddonXMLData["en"].strDisclaimer.empty())
  {
    WriteLF(pPOTFile);
    WriteStrLine("msgctxt ", "Addon Disclaimer", addonXMLEncoding);
    WriteStrLine("msgid ", mapAddonXMLData["en"].strDisclaimer.c_str(), addonXMLEncoding);
    WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strDisclaimer.c_str(), addonXMLEncoding);
    bhasLFWritten =false;
    stringCount++;
  }

//  if (projType == ADDON_NOSTRINGS)
//    return true;

  int previd = -1;

  for (itSourceXmlId = mapSourceXmlId.begin(); itSourceXmlId != mapSourceXmlId.end(); itSourceXmlId++)
  {
    int id = itSourceXmlId->first;
    std::string value = itSourceXmlId->second;
    bhasLFWritten = false;

    //create comment lines, if empty string id or ids found and
    //re-create original xml comments between entries. Only for the source language
    if (!bIsForeignLang)
      WriteComments(previd, true);

    if ((id-previd >= 2) && !bIsForeignLang && previd > -1)
    {
      WriteLF(pPOTFile);
      if (id-previd == 2)
        fprintf(pPOTFile,"#empty string with id %i\n", id-1);
      if (id-previd > 2)
        fprintf(pPOTFile,"#empty strings from id %i to %i\n", previd+1, id-1);
    }
    bhasLFWritten = false;

    //write comment originally placed next to the string entry
    //convert it into #. style gettext comment
    if (!bIsForeignLang)
      WriteComments(id, false);

    //create msgctxt, including the string id
    WriteLF(pPOTFile);
    fprintf(pPOTFile,"msgctxt \"#%i\"\n", id);

    //create msgid and msgstr lines
    WriteLF(pPOTFile);
    WriteStrLine("msgid ", value.c_str(), sourceXMLEncoding);
    if (bIsForeignLang)
    {
      itForeignXmlId = mapForeignXmlId.find(id);
      if (itForeignXmlId != mapForeignXmlId.end())
      {
        stringCount++;
        WriteStrLine("msgstr ", itForeignXmlId->second.c_str(), foreignXMLEncoding);
      }
      else fprintf(pPOTFile,"msgstr \"\"\n");
    }
    else fprintf(pPOTFile,"msgstr \"\"\n");

    if (!bIsForeignLang)
      stringCount++;
    previd =id;
  }

  fclose(pPOTFile);

  printf("%i\t\t", stringCount);
  printf("%s\n", OutputPOFilename.erase(0,WorkingDir.length()).c_str());

  mapForeignXmlId.clear();
  return true;
}