summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorАлексей Шилин <rootlexx@mail.ru>2019-11-25 09:59:38 +0000
committerJulian Andres Klode <jak@debian.org>2019-11-25 09:59:38 +0000
commit19033186919b9c6d31ca3aabaacfb069a4b64f88 (patch)
tree13cc2899b6497f463d401091a9a6b8a603d9d3f3 /apt-pkg
parent4afb07258fad5f9026ad25f579a871093a312ac5 (diff)
Search in all available description translations
When multiple translations of package descriptions are available, perform search in all of them. It allows using search patterns in any of the configured languages. Previously, only the first available translation was searched. As the result, patterns in e.g. English never matched packages which had their descriptions translated into local language. Closes: #490000
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cacheiterators.h1
-rw-r--r--apt-pkg/pkgcache.cc48
2 files changed, 26 insertions, 23 deletions
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index fbd4bcb8d..5c3ad9bbb 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -220,6 +220,7 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);}
inline DescIterator DescriptionList() const;
+ DescIterator TranslatedDescriptionForLanguage(APT::StringView lang) const;
DescIterator TranslatedDescription() const;
inline DepIterator DependsList() const;
inline PrvIterator ProvidesList() const;
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index ba9a39f13..160c58273 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -992,6 +992,23 @@ string pkgCache::PkgFileIterator::RelStr() /*{{{*/
return Res;
}
/*}}}*/
+// VerIterator::TranslatedDescriptionForLanguage - Return a DescIter for language/*{{{*/
+// ---------------------------------------------------------------------
+/* return a DescIter for the specified language
+ */
+pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescriptionForLanguage(StringView lang) const
+{
+ for (pkgCache::DescIterator Desc = DescriptionList(); Desc.end() == false; ++Desc)
+ if (lang == Desc.LanguageCode())
+ return Desc;
+
+ if (lang == "en")
+ return TranslatedDescriptionForLanguage("");
+
+ return DescIterator();
+}
+
+ /*}}}*/
// VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
// ---------------------------------------------------------------------
/* return a DescIter for the current locale or the default if none is
@@ -1003,30 +1020,15 @@ pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const
for (std::vector<string>::const_iterator l = lang.begin();
l != lang.end(); ++l)
{
- pkgCache::DescIterator Desc = DescriptionList();
- for (; Desc.end() == false; ++Desc)
- if (*l == Desc.LanguageCode())
- break;
- if (Desc.end() == true)
- {
- if (*l == "en")
- {
- Desc = DescriptionList();
- for (; Desc.end() == false; ++Desc)
- if (strcmp(Desc.LanguageCode(), "") == 0)
- break;
- if (Desc.end() == true)
- continue;
- }
- else
- continue;
- }
- return Desc;
+ pkgCache::DescIterator Desc = TranslatedDescriptionForLanguage(*l);
+ if (Desc.IsGood())
+ return Desc;
}
- for (pkgCache::DescIterator Desc = DescriptionList();
- Desc.end() == false; ++Desc)
- if (strcmp(Desc.LanguageCode(), "") == 0)
- return Desc;
+
+ pkgCache::DescIterator Desc = TranslatedDescriptionForLanguage("");
+ if (Desc.IsGood())
+ return Desc;
+
return DescriptionList();
}