[glom] Command-line utilities: Initialize gettext and the locale.



commit 271ba617a689508faf198d58707210c74be524ab
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Jan 9 11:23:12 2012 +0100

    Command-line utilities: Initialize gettext and the locale.
    
    	* glom/glom_create_from_example.cc:
    	* glom/glom_export_po.cc:
    	* glom/glom_export_po_all.cc:
    	* glom/glom_test_connection.cc: This should make the translations be used.

 ChangeLog                        |    9 +++++++++
 glom/glom_create_from_example.cc |   23 +++++++++++++++++++++++
 glom/glom_export_po.cc           |   33 ++++++++++++++++++++++++++++-----
 glom/glom_export_po_all.cc       |   31 +++++++++++++++++++++++++++----
 glom/glom_test_connection.cc     |   23 +++++++++++++++++++++++
 5 files changed, 110 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index acce2de..df82c73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2012-01-09  Murray Cumming  <murrayc murrayc com>
 
+	Command-line utilities: Initialize gettext and the locale.
+
+	* glom/glom_create_from_example.cc:
+	* glom/glom_export_po.cc:
+	* glom/glom_export_po_all.cc:
+	* glom/glom_test_connection.cc: This should make the translations be used.
+
+2012-01-09  Murray Cumming  <murrayc murrayc com>
+
 	glom_export_po_all: Actually export the translations.
 
 	* glom/glom_export_po_all.cc: Use the available locale_id,
diff --git a/glom/glom_create_from_example.cc b/glom/glom_create_from_example.cc
index b74af81..cc69008 100644
--- a/glom/glom_create_from_example.cc
+++ b/glom/glom_create_from_example.cc
@@ -36,6 +36,7 @@
 #include <glibmm/convert.h>
 #include <glibmm/miscutils.h>
 #include <iostream>
+#include <stdexcept>
 
 #include <glibmm/i18n.h>
 
@@ -200,6 +201,28 @@ static void cleanup()
 
 int main(int argc, char* argv[])
 {
+  bindtextdomain(GETTEXT_PACKAGE, GLOM_LOCALEDIR);
+  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+  textdomain(GETTEXT_PACKAGE);
+
+  // Set the locale for any streams to the user's current locale,
+  // We should not rely on the default locale of
+  // any streams (we should always do an explicit imbue()),
+  // but this is maybe a good default in case we forget.
+  try
+  {
+    std::locale::global(std::locale(""));
+  }
+  catch(const std::runtime_error& ex)
+  {
+    //This has been known to throw an exception at least once:
+    //https://bugzilla.gnome.org/show_bug.cgi?id=619445
+    //This should tell us what the problem is:
+    std::cerr << G_STRFUNC << ": exception from std::locale::global(std::locale(\"\")): " << ex.what() << std::endl;
+    std::cerr << "  This can happen if the locale is not properly installed or configured." << std::endl;
+  }
+
+  
   Glom::libglom_init();
   
   Glib::OptionContext context;
diff --git a/glom/glom_export_po.cc b/glom/glom_export_po.cc
index 804267b..b25b375 100644
--- a/glom/glom_export_po.cc
+++ b/glom/glom_export_po.cc
@@ -30,6 +30,7 @@
 #include <glibmm/convert.h>
 #include <glibmm/miscutils.h>
 #include <iostream>
+#include <stdexcept>
 
 #include <glibmm/i18n.h>
 
@@ -68,6 +69,28 @@ GlomCreateOptionGroup::GlomCreateOptionGroup()
 
 int main(int argc, char* argv[])
 {
+  bindtextdomain(GETTEXT_PACKAGE, GLOM_LOCALEDIR);
+  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+  textdomain(GETTEXT_PACKAGE);
+
+  // Set the locale for any streams to the user's current locale,
+  // We should not rely on the default locale of
+  // any streams (we should always do an explicit imbue()),
+  // but this is maybe a good default in case we forget.
+  try
+  {
+    std::locale::global(std::locale(""));
+  }
+  catch(const std::runtime_error& ex)
+  {
+    //This has been known to throw an exception at least once:
+    //https://bugzilla.gnome.org/show_bug.cgi?id=619445
+    //This should tell us what the problem is:
+    std::cerr << G_STRFUNC << ": exception from std::locale::global(std::locale(\"\")): " << ex.what() << std::endl;
+    std::cerr << "  This can happen if the locale is not properly installed or configured." << std::endl;
+  }
+  
+
   Glom::libglom_init();
   
   Glib::OptionContext context;
@@ -110,14 +133,14 @@ int main(int argc, char* argv[])
 
   if(input_uri.empty())
   {
-    std::cerr << "Please specify a glom file." << std::endl;
+    std::cerr << _("Please specify a glom file.") << std::endl;
     std::cerr << std::endl << context.get_help() << std::endl;
     return EXIT_FAILURE;
   }
 
   if(group.m_arg_locale_id.empty())
   {
-    std::cerr << "Please specify a locale ID." << std::endl;
+    std::cerr << _("Please specify a locale ID.") << std::endl;
     std::cerr << std::endl << context.get_help() << std::endl;
     return EXIT_FAILURE;
   }
@@ -148,7 +171,7 @@ int main(int argc, char* argv[])
   //Check the output path: 
   if(group.m_arg_filepath_output.empty())
   {
-    std::cerr << "Please specify an output path." << std::endl;
+    std::cerr << _("Please specify an output path.") << std::endl;
     std::cerr << std::endl << context.get_help() << std::endl;
     return EXIT_FAILURE;
   }
@@ -184,11 +207,11 @@ int main(int argc, char* argv[])
     Glom::write_translations_to_po_file(&document, ouput_uri, group.m_arg_locale_id);
   if(!succeeded)
   {
-    std::cerr << "Po file creation failed." << std::endl;
+    std::cerr << _("Po file creation failed.") << std::endl;
     return EXIT_FAILURE;
   }
 
-  std::cout << "Po file created at: " << ouput_uri << std::endl;
+  std::cout << Glib::ustring::compose(_("Po file created at: %1"), ouput_uri) << std::endl;
 
   Glom::libglom_deinit();
 
diff --git a/glom/glom_export_po_all.cc b/glom/glom_export_po_all.cc
index 373798b..a27cc08 100644
--- a/glom/glom_export_po_all.cc
+++ b/glom/glom_export_po_all.cc
@@ -30,6 +30,7 @@
 #include <glibmm/convert.h>
 #include <glibmm/miscutils.h>
 #include <iostream>
+#include <stdexcept>
 
 #include <glibmm/i18n.h>
 
@@ -62,6 +63,28 @@ GlomCreateOptionGroup::GlomCreateOptionGroup()
 
 int main(int argc, char* argv[])
 {
+  bindtextdomain(GETTEXT_PACKAGE, GLOM_LOCALEDIR);
+  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+  textdomain(GETTEXT_PACKAGE);
+
+  // Set the locale for any streams to the user's current locale,
+  // We should not rely on the default locale of
+  // any streams (we should always do an explicit imbue()),
+  // but this is maybe a good default in case we forget.
+  try
+  {
+    std::locale::global(std::locale(""));
+  }
+  catch(const std::runtime_error& ex)
+  {
+    //This has been known to throw an exception at least once:
+    //https://bugzilla.gnome.org/show_bug.cgi?id=619445
+    //This should tell us what the problem is:
+    std::cerr << G_STRFUNC << ": exception from std::locale::global(std::locale(\"\")): " << ex.what() << std::endl;
+    std::cerr << "  This can happen if the locale is not properly installed or configured." << std::endl;
+  }
+
+  
   Glom::libglom_init();
   
   Glib::OptionContext context;
@@ -104,7 +127,7 @@ int main(int argc, char* argv[])
 
   if(input_uri.empty())
   {
-    std::cerr << "Please specify a glom file." << std::endl;
+    std::cerr << _("Please specify a glom file.") << std::endl;
     std::cerr << std::endl << context.get_help() << std::endl;
     return EXIT_FAILURE;
   }
@@ -178,7 +201,7 @@ int main(int argc, char* argv[])
   const std::vector<Glib::ustring> locales = document.get_translation_available_locales();
   if(locales.empty())
   {
-    std::cerr << "The Glom document has no translations." << std::endl;
+    std::cerr << _("The Glom document has no translations.") << std::endl;
     return EXIT_FAILURE;
   }
 
@@ -197,11 +220,11 @@ int main(int argc, char* argv[])
       Glom::write_translations_to_po_file(&document, output_uri, locale_id);
     if(!succeeded)
     {
-      std::cerr << "Po file creation failed." << std::endl;
+      std::cerr << _("Po file creation failed.") << std::endl;
       return EXIT_FAILURE;
     }
 
-    std::cout << "Po file created at: " << output_uri << std::endl;
+    std::cout << Glib::ustring::compose(_("Po file created at: %1"), output_uri) << std::endl;
   }
 
   Glom::libglom_deinit();
diff --git a/glom/glom_test_connection.cc b/glom/glom_test_connection.cc
index 1603427..dadd725 100644
--- a/glom/glom_test_connection.cc
+++ b/glom/glom_test_connection.cc
@@ -32,6 +32,7 @@
 #include <glibmm/optioncontext.h>
 #include <glibmm/convert.h>
 #include <iostream>
+#include <stdexcept>
 
 #include <glibmm/i18n.h>
 
@@ -93,6 +94,28 @@ static void print_options_hint()
 
 int main(int argc, char* argv[])
 {
+  bindtextdomain(GETTEXT_PACKAGE, GLOM_LOCALEDIR);
+  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+  textdomain(GETTEXT_PACKAGE);
+
+  // Set the locale for any streams to the user's current locale,
+  // We should not rely on the default locale of
+  // any streams (we should always do an explicit imbue()),
+  // but this is maybe a good default in case we forget.
+  try
+  {
+    std::locale::global(std::locale(""));
+  }
+  catch(const std::runtime_error& ex)
+  {
+    //This has been known to throw an exception at least once:
+    //https://bugzilla.gnome.org/show_bug.cgi?id=619445
+    //This should tell us what the problem is:
+    std::cerr << G_STRFUNC << ": exception from std::locale::global(std::locale(\"\")): " << ex.what() << std::endl;
+    std::cerr << "  This can happen if the locale is not properly installed or configured." << std::endl;
+  }
+
+
   Glom::libglom_init();
   
   Glib::OptionContext context;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]