summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2009-11-26 22:23:08 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2009-11-26 22:23:08 +0100
commit45df0ad2aab7d019cec855ba2cfe7ecdd0f8c7c8 (patch)
treef18787e135dcd7ea9444f93abc51c2a6516e2f7e /apt-pkg/deb
parent32e994d9c891ba379af7b292eeb81b4402d3f2af (diff)
[BREAK] add possibility to download and use multiply
Translation files, configurable with Acquire::Languages accessable with APT::Configuration::getLanguages() and as always with documentation in apt.conf. The commit also includes a very very simple testapp.
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/debindexfile.cc29
-rw-r--r--apt-pkg/deb/debindexfile.h5
-rw-r--r--apt-pkg/deb/deblistparser.cc17
-rw-r--r--apt-pkg/deb/debmetaindex.cc17
-rw-r--r--apt-pkg/deb/debrecords.cc12
5 files changed, 55 insertions, 25 deletions
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index ed7633803..5beb83665 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -319,10 +319,11 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
// TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section) :
- pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section)
-{
-}
+debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section,
+ char const * const Translation) :
+ pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section),
+ Language(Translation)
+{}
/*}}}*/
// TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/
// ---------------------------------------------------------------------
@@ -355,8 +356,8 @@ string debTranslationsIndex::IndexURI(const char *Type) const
bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const
{
if (TranslationsAvailable()) {
- string TranslationFile = "Translation-" + LanguageCode();
- new pkgAcqIndexTrans(Owner, IndexURI(LanguageCode().c_str()),
+ string const TranslationFile = string("Translation-").append(Language);
+ new pkgAcqIndexTrans(Owner, IndexURI(Language),
Info(TranslationFile.c_str()),
TranslationFile);
}
@@ -375,7 +376,7 @@ string debTranslationsIndex::Describe(bool Short) const
snprintf(S,sizeof(S),"%s",Info(TranslationFile().c_str()).c_str());
else
snprintf(S,sizeof(S),"%s (%s)",Info(TranslationFile().c_str()).c_str(),
- IndexFile(LanguageCode().c_str()).c_str());
+ IndexFile(Language).c_str());
return S;
}
/*}}}*/
@@ -397,20 +398,20 @@ string debTranslationsIndex::Info(const char *Type) const
return Info;
}
/*}}}*/
-bool debTranslationsIndex::HasPackages() const
+bool debTranslationsIndex::HasPackages() const /*{{{*/
{
if(!TranslationsAvailable())
return false;
- return FileExists(IndexFile(LanguageCode().c_str()));
+ return FileExists(IndexFile(Language));
}
-
+ /*}}}*/
// TranslationsIndex::Exists - Check if the index is available /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debTranslationsIndex::Exists() const
{
- return FileExists(IndexFile(LanguageCode().c_str()));
+ return FileExists(IndexFile(Language));
}
/*}}}*/
// TranslationsIndex::Size - Return the size of the index /*{{{*/
@@ -419,7 +420,7 @@ bool debTranslationsIndex::Exists() const
unsigned long debTranslationsIndex::Size() const
{
struct stat S;
- if (stat(IndexFile(LanguageCode().c_str()).c_str(),&S) != 0)
+ if (stat(IndexFile(Language).c_str(),&S) != 0)
return 0;
return S.st_size;
}
@@ -430,7 +431,7 @@ unsigned long debTranslationsIndex::Size() const
bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
{
// Check the translation file, if in use
- string TranslationFile = IndexFile(LanguageCode().c_str());
+ string TranslationFile = IndexFile(Language);
if (TranslationsAvailable() && FileExists(TranslationFile))
{
FileFd Trans(TranslationFile,FileFd::ReadOnly);
@@ -462,7 +463,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
/* */
pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const
{
- string FileName = IndexFile(LanguageCode().c_str());
+ string FileName = IndexFile(Language);
pkgCache::PkgFileIterator File = Cache.FileBegin();
for (; File.end() == false; File++)
diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h
index b0012c96b..c0e8d7d8e 100644
--- a/apt-pkg/deb/debindexfile.h
+++ b/apt-pkg/deb/debindexfile.h
@@ -77,12 +77,13 @@ class debTranslationsIndex : public pkgIndexFile
string URI;
string Dist;
string Section;
+ const char * const Language;
string Info(const char *Type) const;
string IndexFile(const char *Type) const;
string IndexURI(const char *Type) const;
- inline string TranslationFile() const {return "Translation-" + LanguageCode();};
+ inline string TranslationFile() const {return string("Translation-").append(Language);};
public:
@@ -99,7 +100,7 @@ class debTranslationsIndex : public pkgIndexFile
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
- debTranslationsIndex(string URI,string Dist,string Section);
+ debTranslationsIndex(string URI,string Dist,string Section, char const * const Language);
};
class debSourcesIndex : public pkgIndexFile
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 517b771a5..16e6ee332 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -13,6 +13,7 @@
#include <apt-pkg/deblistparser.h>
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/crc-16.h>
#include <apt-pkg/md5.h>
@@ -129,10 +130,11 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver)
only describe package properties */
string debListParser::Description()
{
- if (DescriptionLanguage().empty())
+ string const lang = DescriptionLanguage();
+ if (lang.empty())
return Section.FindS("Description");
else
- return Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str());
+ return Section.FindS(string("Description-").append(lang).c_str());
}
/*}}}*/
// ListParser::DescriptionLanguage - Return the description lang string /*{{{*/
@@ -142,7 +144,16 @@ string debListParser::Description()
assumed to describe original description. */
string debListParser::DescriptionLanguage()
{
- return Section.FindS("Description").empty() ? pkgIndexFile::LanguageCode() : "";
+ if (Section.FindS("Description").empty() == false)
+ return "";
+
+ std::vector<string> const lang = APT::Configuration::getLanguages();
+ for (std::vector<string>::const_iterator l = lang.begin();
+ l != lang.end(); l++)
+ if (Section.FindS(string("Description-").append(*l).c_str()).empty() == false)
+ return *l;
+
+ return "";
}
/*}}}*/
// ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index f3ab6960c..8f28f053b 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -5,6 +5,7 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/error.h>
using namespace std;
@@ -170,13 +171,19 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool GetAll) const
new indexRecords (Dist));
// Queue the translations
+ std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
I != SectionEntries.end(); I++) {
if((*I)->IsSrc)
continue;
- debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section);
- i.GetIndexes(Owner);
+
+ for (vector<string>::const_iterator l = lang.begin();
+ l != lang.end(); l++)
+ {
+ debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section,(*l).c_str());
+ i.GetIndexes(Owner);
+ }
}
return true;
@@ -202,6 +209,7 @@ vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
return Indexes;
Indexes = new vector <pkgIndexFile*>;
+ std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
I != SectionEntries.end(); I++) {
if ((*I)->IsSrc)
@@ -209,7 +217,10 @@ vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
else
{
Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
- Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section));
+
+ for (vector<string>::const_iterator l = lang.begin();
+ l != lang.end(); l++)
+ Indexes->push_back(new debTranslationsIndex(URI,Dist,(*I)->Section,(*l).c_str()));
}
}
diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc
index 8ed0bb7eb..5b8538a46 100644
--- a/apt-pkg/deb/debrecords.cc
+++ b/apt-pkg/deb/debrecords.cc
@@ -11,6 +11,7 @@
#include <apt-pkg/debrecords.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/aptconfiguration.h>
#include <langinfo.h>
/*}}}*/
@@ -109,13 +110,18 @@ string debRecordParser::ShortDesc()
string debRecordParser::LongDesc()
{
string orig, dest;
- char *codeset = nl_langinfo(CODESET);
if (!Section.FindS("Description").empty())
orig = Section.FindS("Description").c_str();
- else
- orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
+ else
+ {
+ vector<string> const lang = APT::Configuration::getLanguages();
+ for (vector<string>::const_iterator l = lang.begin();
+ orig.empty() && l != lang.end(); l++)
+ orig = Section.FindS(string("Description-").append(*l).c_str());
+ }
+ char const * const codeset = nl_langinfo(CODESET);
if (strcmp(codeset,"UTF-8") != 0) {
UTF8ToCodeset(codeset, orig, &dest);
orig = dest;