From 19033186919b9c6d31ca3aabaacfb069a4b64f88 Mon Sep 17 00:00:00 2001 From: Алексей Шилин Date: Mon, 25 Nov 2019 09:59:38 +0000 Subject: 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 --- apt-pkg/cacheiterators.h | 1 + apt-pkg/pkgcache.cc | 48 +++++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'apt-pkg') 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 { 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 @@ -991,6 +991,23 @@ string pkgCache::PkgFileIterator::RelStr() /*{{{*/ Res = Res + (Res.empty() == true?"b=":",b=") + Architecture(); 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/*{{{*/ // --------------------------------------------------------------------- @@ -1003,30 +1020,15 @@ pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const for (std::vector::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(); } -- cgit v1.2.3-70-g09d2