From 7c2708ea9cebf14327c002b0d6fdd8bdc3319165 Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Thu, 10 Sep 2009 10:33:27 +0800
Subject: [PATCH] ENH: internationalization working with macro

---
 CMakeLists.txt        |  1 +
 Code/Common/otbI18n.h | 52 +++++++++++++++++++++++++++++++++++++++++++
 OTBConfig.cmake.in    |  2 ++
 otbConfigure.h.in     |  4 +++-
 4 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 Code/Common/otbI18n.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0f44d3841..74bfc80517 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -556,6 +556,7 @@ FIND_PACKAGE(Gettext)
 IF(GETTEXT_FOUND)
   SET(OTB_I18N 1)
   SET(OTB_LANG "en" CACHE STRING "OTB internationalization (Experimental)")#might want to get the Locale from the system here
+  SET(OTB_LANG_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/Locale)
   #TODO compile the po into mo
 ELSE(GETTEXT_FOUND)
   SET(OTB_I18N 0)
diff --git a/Code/Common/otbI18n.h b/Code/Common/otbI18n.h
new file mode 100644
index 0000000000..dc4fc7897f
--- /dev/null
+++ b/Code/Common/otbI18n.h
@@ -0,0 +1,52 @@
+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#ifndef __otbI18n_h
+#define __otbI18n_h
+
+#include "otbConfigure.h"
+
+#if defined(OTB_I18N)
+#include <libintl.h>
+#endif
+
+//To enable stringization after macro replacement
+#define _QUOTEME(x) #x
+#define QUOTEME(x) _QUOTEME(x)
+
+
+#if defined(OTB_I18N)
+#define otbI18nMacro() \
+  setlocale( LC_ALL, QUOTEME(OTB_LANG) );\
+  bindtextdomain( "otb", QUOTEME(OTB_LANG_LOCATION) );\
+  textdomain( "otb" );\
+  std::cout << "Language: " << QUOTEME(OTB_LANG) << std::endl;\
+  std::cout << "Language location: " << QUOTEME(OTB_LANG_LOCATION) << std::endl;
+#else
+#define otbI18nMacro()\
+std::cout << "No internationalization" << std::endl;
+#endif
+
+#if defined(OTB_I18N)
+#define otbGetTextMacro(msgString)\
+gettext(msgString)
+#else
+#define otbGetTextMacro(msgString)\
+msgString
+#endif
+
+#endif
\ No newline at end of file
diff --git a/OTBConfig.cmake.in b/OTBConfig.cmake.in
index 67b59c4ed9..220529478a 100644
--- a/OTBConfig.cmake.in
+++ b/OTBConfig.cmake.in
@@ -135,3 +135,5 @@ SET(OTB_USE_EXTERNAL_BOOST "@OTB_USE_EXTERNAL_BOOST@")
 
 # Internationalization
 SET(OTB_I18N "@OTB_I18N@")
+SET(OTB_LANG "@OTB_LANG@")
+SET(OTB_LANG_LOCATION "@OTB_LANG_LOCATION@")
diff --git a/otbConfigure.h.in b/otbConfigure.h.in
index 3bbe3c7cbd..dd3846e99d 100644
--- a/otbConfigure.h.in
+++ b/otbConfigure.h.in
@@ -66,4 +66,6 @@
 /* Use Visu/Gui configurations */
 #cmakedefine OTB_USE_VISU_GUI
 
-#cmakedefine OTB_I18N
\ No newline at end of file
+#cmakedefine OTB_I18N
+#define OTB_LANG @OTB_LANG@
+#define OTB_LANG_LOCATION @OTB_LANG_LOCATION@
-- 
GitLab