- display localized resolvable kind
authorJan Kupec <jkupec@suse.cz>
Wed, 12 Sep 2007 12:17:19 +0000 (12:17 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 12 Sep 2007 12:17:19 +0000 (12:17 +0000)
src/zypper-info.cc
src/zypper-misc.cc
src/zypper-search.h
src/zypper-source-callbacks.h
src/zypper-utils.cc
src/zypper-utils.h

index 0ff8a1a..3ae1c74 100644 (file)
@@ -9,6 +9,7 @@
 #include <zypp/Patch.h>
 
 #include "zypper.h"
+#include "zypper-utils.h"
 #include "zypper-misc.h"
 
 using namespace std;
@@ -49,13 +50,15 @@ void printInfo(const ZypperCommand & command, const vector<string> & arguments)
 
     if (!installer.item) {
       // TranslatorExplanation E.g. "package zypper not found."
-      cout << "\n" << format(_("%s %s not found.")) % kind.asString() % *nameit
+      cout << "\n" << format(_("%s %s not found."))
+          % kind_to_string_localized(kind, 1) % *nameit
           << endl;
     }
     else {
       // print info
       // TranslatorExplanation E.g. "Information for package zypper:"
-      cout << endl << format(_("Information for %s %s:")) % kind.asString() % *nameit;
+      cout << endl << format(_("Information for %s %s:"))
+          % kind_to_string_localized(kind, 1) % *nameit;
 
       cout << endl << endl;
 
index 0586d26..d264cbb 100644 (file)
@@ -20,6 +20,7 @@
 #include <zypp/target/store/xml_escape_parser.hpp>
 
 #include "zypper.h"
+#include "zypper-utils.h"
 #include "zypper-getopt.h"
 #include "zypper-misc.h"
 #include "zypper-callbacks.h"
@@ -77,35 +78,6 @@ ResObject::Kind string_to_kind (const string &skind)
   return empty;
 }
 
-string kind_to_string_localized(const KindOf<Resolvable> & kind, unsigned long count)
-{
-  if (kind == ResTraits<Package>::kind.asString())
-    return _PL("package", "packages", count);
-  if (kind == ResTraits<Selection>::kind.asString())
-    return _PL("selection", "selections", count);
-  if (kind == ResTraits<Pattern>::kind.asString())
-    return _PL("pattern", "patterns", count);
-  if (kind == ResTraits<Product>::kind.asString())
-    return _PL("product", "product", count);
-  if (kind == ResTraits<Patch>::kind.asString())
-    return _PL("patch", "patches", count);
-  if (kind == ResTraits<Script>::kind.asString())
-    return _PL("script", "scripts", count);
-  if (kind == ResTraits<Message>::kind.asString())
-    return _PL("message", "messages", count);
-  if (kind == ResTraits<Language>::kind.asString())
-    return _PL("language", "languages", count);
-  if (kind == ResTraits<Atom>::kind.asString())
-    return _PL("atom", "atoms", count);
-  if (kind == ResTraits<SystemResObject>::kind.asString())
-    return _PL("system", "systems", count);
-  if (kind == ResTraits<SrcPackage>::kind.asString())
-    return _PL("srcpackage", "srcpackages", count);
-  // default
-  return _PL("resolvable", "resolvables", count);
-}
-
-
 // copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
 bool ProvideProcess::operator()( const PoolItem& provider )
 {
@@ -292,7 +264,7 @@ void mark_for_install( const ResObject::Kind &kind,
   cout_vv << "... done" << endl;
   if (!installer.item) {
     // TranslatorExplanation e.g. "package 'pornview' not found"
-    cerr << format(_("%s '%s' not found")) % kind % name << endl;
+    cerr << format(_("%s '%s' not found")) % kind_to_string_localized(kind,1) % name << endl;
     WAR << format("%s '%s' not found") % kind % name << endl;
 
     return;
@@ -301,7 +273,7 @@ void mark_for_install( const ResObject::Kind &kind,
   if (installer.installed_item &&
       installer.installed_item.resolvable()->edition() == installer.item.resolvable()->edition() &&
       installer.installed_item.resolvable()->arch() == installer.item.resolvable()->arch()) {
-    cout_n << format(_("skipping %s '%s' (already installed)")) % kind.asString() % name << endl;
+    cout_n << format(_("skipping %s '%s' (already installed)")) % kind_to_string_localized(kind,1) % name << endl;
   }
   else {
     // TODO don't use setToBeInstalled for this purpose but higher level solver API
@@ -353,7 +325,8 @@ void mark_for_uninstall( const ResObject::Kind &kind,
                );
   cerr_vv << "... done" << endl;
   if (!deleter.found) {
-    cerr << _("Not found") << endl;
+    // TranslatorExplanation e.g. "package 'pornview' not found"
+    cerr << format(_("%s '%s' not found")) % kind_to_string_localized(kind,1) % name << endl;
     return; //error?
   }
 }
@@ -1489,7 +1462,8 @@ bool confirm_licenses()
         // TranslatorExplanation The first %s is name of the resolvable, the second is its kind (e.g. 'zypper package')
                          if (!gSettings.machine_readable)
                cout << format(_("Automatically agreeing with %s %s license."))
-                   % it->resolvable()->name() % it->resolvable()->kind().asString()
+                   % it->resolvable()->name()
+                   % kind_to_string_localized(it->resolvable()->kind(),1)
                    << endl;
 
         MIL << format("Automatically agreeing with %s %s license.")
@@ -1499,8 +1473,8 @@ bool confirm_licenses()
         continue;
       }
 
-      cout << format(_("%s %s license:"))
-          % it->resolvable()->name() % it->resolvable()->kind().asString()
+      cout << format(_("%s %s license:")) % it->resolvable()->name()
+                % kind_to_string_localized(it->resolvable()->kind(), 1)
         << it->resolvable()->licenseToConfirm() << endl;
 
       string question = _("In order to install this package, you must agree"
@@ -1530,7 +1504,8 @@ bool confirm_licenses()
             // TranslatorExplanation e.g. "... with flash package license."
           cout << format(
               _("Aborting installation due to user disagreement with %s %s license."))
-                % it->resolvable()->name() % it->resolvable()->kind().asString()
+                % it->resolvable()->name()
+                % kind_to_string_localized(it->resolvable()->kind(), 1)
               << endl;
             MIL << "License(s) NOT confirmed (interactive)" << endl;
         }
index 0bcb9f9..79edecb 100644 (file)
@@ -21,6 +21,7 @@
 #include <zypp/RepoManager.h>
 
 #include "zypper.h"
+#include "zypper-utils.h"
 #include "zypper-getopt.h"
 #include "zypper-tabulator.h"
 
@@ -316,7 +317,8 @@ struct FillTable
         row << "i"
            << pool_item.resolvable()->repository().info().name()
             // TODO what about rug's Bundle?
-            << (gSettings.is_rug_compatible ? "" : pool_item.resolvable()->kind().asString()) 
+            << (gSettings.is_rug_compatible ?
+                "" : kind_to_string_localized(pool_item.resolvable()->kind(), 1))
             << pool_item.resolvable()->name()
             << pool_item.resolvable()->edition().asString()
             << pool_item.resolvable()->arch().asString();
@@ -357,7 +359,8 @@ struct FillTable
     // add other fields to the result table
     row << alias
         // TODO what about rug's Bundle?
-        << (gSettings.is_rug_compatible ? "" : res->kind.asString())
+        << (gSettings.is_rug_compatible ?
+            "" : kind_to_string_localized(res->kind, 1))
         << res->name
         << res->edition.asString()
         << res->arch.asString();
index 0ff7d42..98c7e26 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "zypper.h"
 #include "zypper-callbacks.h"
-
+#include "zypper-utils.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace ZmartRecipients
@@ -177,7 +177,8 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
     _url = url;
 
     cout_n << boost::format(_("Downloading %s %s-%s.%s"))
-        % _resolvable_ptr->kind() % _resolvable_ptr->name()
+        % kind_to_string_localized(_resolvable_ptr->kind(), 1)
+        % _resolvable_ptr->name()
         % _resolvable_ptr->edition() % _resolvable_ptr->arch();
 
 // grr, bad class??
index c22a5bf..b351cf5 100644 (file)
@@ -57,3 +57,33 @@ bool is_changeable_media(const zypp::Url & url)
   mm.close(id);
   return is_cd;
 }
+
+// ----------------------------------------------------------------------------
+
+string kind_to_string_localized(const KindOf<Resolvable> & kind, unsigned long count)
+{
+  if (kind == ResTraits<Package>::kind.asString())
+    return _PL("package", "packages", count);
+  if (kind == ResTraits<Selection>::kind.asString())
+    return _PL("selection", "selections", count);
+  if (kind == ResTraits<Pattern>::kind.asString())
+    return _PL("pattern", "patterns", count);
+  if (kind == ResTraits<Product>::kind.asString())
+    return _PL("product", "product", count);
+  if (kind == ResTraits<Patch>::kind.asString())
+    return _PL("patch", "patches", count);
+  if (kind == ResTraits<Script>::kind.asString())
+    return _PL("script", "scripts", count);
+  if (kind == ResTraits<Message>::kind.asString())
+    return _PL("message", "messages", count);
+  if (kind == ResTraits<Language>::kind.asString())
+    return _PL("language", "languages", count);
+  if (kind == ResTraits<Atom>::kind.asString())
+    return _PL("atom", "atoms", count);
+  if (kind == ResTraits<SystemResObject>::kind.asString())
+    return _PL("system", "systems", count);
+  if (kind == ResTraits<SrcPackage>::kind.asString())
+    return _PL("srcpackage", "srcpackages", count);
+  // default
+  return _PL("resolvable", "resolvables", count);
+}
index 5a3f964..611ab5a 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <zypp/Pathname.h>
 #include <zypp/Url.h>
+#include <zypp/Resolvable.h>
 
 std::string read_line_from_file( const zypp::Pathname &file );
 void write_line_to_file( const zypp::Pathname &file, const std::string &line );
@@ -17,4 +18,7 @@ std::ostream & report_a_bug (std::ostream& stm);
 
 bool is_changeable_media(const zypp::Url & url);
 
+std::string kind_to_string_localized(
+    const zypp::KindOf<zypp::Resolvable> & kind, unsigned long count);
+
 #endif /*ZYPPER_UTILS_H*/