changeset 2330:9c7a80c87ae9

"Locale" configuration option
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Jul 2017 16:34:16 +0200
parents 55c900a5b0e4
children a47d07b5b39f
files Core/Toolbox.cpp Core/Toolbox.h NEWS OrthancServer/OrthancInitialization.cpp Resources/Configuration.json
diffstat 5 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Fri Jul 14 16:17:02 2017 +0200
+++ b/Core/Toolbox.cpp	Fri Jul 14 16:34:16 2017 +0200
@@ -1256,7 +1256,7 @@
 
   static std::auto_ptr<std::locale>  globalLocale_;
   
-  void Toolbox::InitializeGlobalLocale()
+  void Toolbox::InitializeGlobalLocale(const char* locale)
   {
     // Make Orthanc use English, United States locale
 
@@ -1270,18 +1270,25 @@
 
     try
     {
-      if (DEFAULT_LOCALE == NULL)
+      if (locale != NULL)
       {
+        LOG(WARNING) << "Using user-specified locale: \"" << locale << "\"";
+        globalLocale_.reset(new std::locale(locale));
+      }
+      else if (DEFAULT_LOCALE == NULL)
+      {
+        LOG(WARNING) << "Using system-wide default locale";
         globalLocale_.reset(new std::locale());
       }
       else
       {
+        LOG(WARNING) << "Using default locale: \"" << DEFAULT_LOCALE << "\"";
         globalLocale_.reset(new std::locale(DEFAULT_LOCALE));
       }
     }
-    catch (std::runtime_error& e)
+    catch (std::runtime_error&)
     {
-      LOG(ERROR) << "Cannot initialize global locale as \"" << DEFAULT_LOCALE << "\"";
+      LOG(ERROR) << "Cannot initialize global locale";
       throw OrthancException(ErrorCode_InternalError);
     }
   }
--- a/Core/Toolbox.h	Fri Jul 14 16:17:02 2017 +0200
+++ b/Core/Toolbox.h	Fri Jul 14 16:34:16 2017 +0200
@@ -207,7 +207,7 @@
 
     bool StartsWithUuid(const std::string& str);
 
-    void InitializeGlobalLocale();
+    void InitializeGlobalLocale(const char* locale);
 
     void FinalizeGlobalLocale();
 
--- a/NEWS	Fri Jul 14 16:17:02 2017 +0200
+++ b/NEWS	Fri Jul 14 16:34:16 2017 +0200
@@ -12,6 +12,7 @@
   - Obsolete manufacturers are still accepted but might disappear in the future
   - Added new manufacturer: GenericNoWidlcards to replace all '*' by '' in
     outgoing C-Find requests
+* "Locale" configuration option
 
 REST API
 --------
--- a/OrthancServer/OrthancInitialization.cpp	Fri Jul 14 16:17:02 2017 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Fri Jul 14 16:34:16 2017 +0200
@@ -464,7 +464,6 @@
   {
     boost::recursive_mutex::scoped_lock lock(globalMutex_);
 
-    Toolbox::InitializeGlobalLocale();
     HttpClient::InitializeOpenSsl();
 
     InitializeServerEnumerations();
@@ -473,6 +472,16 @@
     ReadGlobalConfiguration(configurationFile);
     ValidateGlobalConfiguration();
 
+    if (configuration_.isMember("Locale"))
+    {
+      std::string locale = GetGlobalStringParameterInternal("Locale", "");
+      Toolbox::InitializeGlobalLocale(configuration_["Locale"].asCString());
+    }
+    else
+    {
+      Toolbox::InitializeGlobalLocale(NULL);
+    }
+
     if (configuration_.isMember("Pkcs11"))
     {
       ConfigurePkcs11(configuration_["Pkcs11"]);
--- a/Resources/Configuration.json	Fri Jul 14 16:17:02 2017 +0200
+++ b/Resources/Configuration.json	Fri Jul 14 16:34:16 2017 +0200
@@ -334,6 +334,10 @@
   // interest in the "Dictionary" configuration option below.
   "LoadPrivateDictionary" : true,
 
+  // Locale to be used by Orthanc. Notably used if comparing strings
+  // in a case-insensitive way.
+  // "Locale" : "en_US.UTF-8",
+
   // Register a new tag in the dictionary of DICOM tags that are known
   // to Orthanc. Each line must contain the tag (formatted as 2
   // hexadecimal numbers), the value representation (2 upcase