From fddf1ee0be8d02f24460dd33fc58226e69a4e1a5 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Mon, 15 Jun 2009 10:54:09 -0400
Subject: [PATCH] Create gettext framework for SSSD daemon

---
 .gitignore                  |    1 +
 server/Makefile.am          |    7 ++++++-
 server/configure.ac         |    4 +++-
 server/po/LINGUAS           |    1 +
 server/po/Makevars          |   41 +++++++++++++++++++++++++++++++++++++++++
 server/po/POTFILES.in       |    9 +++++++++
 server/po/es.po             |   22 ++++++++++++++++++++++
 server/po/sss_daemon.pot    |   22 ++++++++++++++++++++++
 server/tools/sss_groupadd.c |    4 ++--
 server/tools/sss_groupdel.c |    4 ++--
 server/tools/sss_groupmod.c |    4 ++--
 server/tools/sss_useradd.c  |    7 ++++---
 server/tools/sss_userdel.c  |    4 ++--
 server/tools/sss_usermod.c  |    4 ++--
 server/tools/tools_util.c   |   20 ++++++++++++++++++++
 server/tools/tools_util.h   |    4 ++++
 server/util/server.c        |    6 ++++++
 server/util/sssd-i18n.h     |    8 ++++++++
 sssd.spec.in                |    1 +
 19 files changed, 158 insertions(+), 15 deletions(-)
 create mode 100644 server/po/LINGUAS
 create mode 100644 server/po/Makevars
 create mode 100644 server/po/POTFILES.in
 create mode 100644 server/po/es.po
 create mode 100644 server/po/sss_daemon.pot
 create mode 100644 server/util/sssd-i18n.h

diff --git a/.gitignore b/.gitignore
index d0daf65..c6cb77b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,3 +37,4 @@ stamp-po
 ABOUT-NLS
 build
 *.patch
+*.swp
diff --git a/server/Makefile.am b/server/Makefile.am
index 7fdce6c..2dee393 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -1,3 +1,4 @@
+SUBDIRS = po
 topdir=.
 sssdlibexecdir = $(libexecdir)/sssd
 sssdlibdir = $(libdir)/sssd
@@ -117,7 +118,10 @@ AM_CPPFLAGS = -Wall \
     -DSHADOW_UTILS_PATH=\"$(shadow_utils_path)\" \
     -DSSSD_INTROSPECT_PATH=\"$(dbusinstropectdir)\" \
     -DSSSD_CONF_DIR=\"$(sssdconfdir)\" \
-    -DUSE_MMAP=1
+    -DUSE_MMAP=1 \
+    -DLOCALEDIR=\"\$(localedir)\"
+
+EXTRA_DIST = build/config.rpath
 
 SSSD_DEBUG_OBJ = \
     util/debug.c
@@ -170,6 +174,7 @@ dist_noinst_HEADERS = \
     util/btreemap.h \
     util/nss_sha512crypt.h \
     util/dlinklist.h \
+    util/sssd-i18n.h \
     util/util.h \
     config.h \
     monitor/monitor.h \
diff --git a/server/configure.ac b/server/configure.ac
index a1060c1..77f7ec7 100644
--- a/server/configure.ac
+++ b/server/configure.ac
@@ -20,6 +20,8 @@ AM_PROG_CC_C_O
 AC_DISABLE_STATIC
 AC_PROG_LIBTOOL
 AC_CONFIG_MACRO_DIR([m4])
+AM_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_VERSION([0.17])
 
 m4_pattern_allow([AM_SILENT_RULES])
 AM_SILENT_RULES
@@ -84,6 +86,6 @@ AC_SUBST(EXTRA_OBJ)
 
 AC_CHECK_HEADERS([sys/inotify.h])
 
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile po/Makefile.in])
 
 AC_OUTPUT
diff --git a/server/po/LINGUAS b/server/po/LINGUAS
new file mode 100644
index 0000000..8357fca
--- /dev/null
+++ b/server/po/LINGUAS
@@ -0,0 +1 @@
+es
diff --git a/server/po/Makevars b/server/po/Makevars
new file mode 100644
index 0000000..5dda691
--- /dev/null
+++ b/server/po/Makevars
@@ -0,0 +1,41 @@
+# Makefile variables for PO directory in any package using GNU gettext.
+
+# Usually the message domain is the same as the package name.
+DOMAIN = $(PACKAGE)
+
+# These two variables depend on the location of this directory.
+subdir = po
+top_builddir = ..
+
+# These options get passed to xgettext.
+XGETTEXT_OPTIONS = --keyword=_ --keyword=N_
+
+# This is the copyright holder that gets inserted into the header of the
+# $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
+# package.  (Note that the msgstr strings, extracted from the package's
+# sources, belong to the copyright holder of the package.)  Translators are
+# expected to transfer the copyright for their translations to this person
+# or entity, or to disclaim their copyright.  The empty string stands for
+# the public domain; in this case the translators are expected to disclaim
+# their copyright.
+COPYRIGHT_HOLDER = Red Hat, Inc.
+
+# This is the email address or URL to which the translators shall report
+# bugs in the untranslated strings:
+# - Strings which are not entire sentences, see the maintainer guidelines
+#   in the GNU gettext documentation, section 'Preparing Strings'.
+# - Strings which use unclear terms or require additional context to be
+#   understood.
+# - Strings which make invalid assumptions about notation of date, time or
+#   money.
+# - Pluralisation problems.
+# - Incorrect English spelling.
+# - Incorrect formatting.
+# It can be your email address, or a mailing list address where translators
+# can write to without being subscribed, or the URL of a web page through
+# which the translators can contact you.
+MSGID_BUGS_ADDRESS = freeipa-devel@redhat.com
+
+# This is the list of locale categories, beyond LC_MESSAGES, for which the
+# message catalogs shall be used.  It is usually empty.
+EXTRA_LOCALE_CATEGORIES =
diff --git a/server/po/POTFILES.in b/server/po/POTFILES.in
new file mode 100644
index 0000000..8de37f6
--- /dev/null
+++ b/server/po/POTFILES.in
@@ -0,0 +1,9 @@
+# List of source files which contain translatable strings.
+confdb/confdb_setup.c
+tools/sss_groupdel.c
+tools/sss_groupmod.c
+tools/sss_userdel.c
+tools/tools_util.c
+tools/sss_useradd.c
+tools/sss_groupadd.c
+tools/sss_usermod.c
diff --git a/server/po/es.po b/server/po/es.po
new file mode 100644
index 0000000..5332039
--- /dev/null
+++ b/server/po/es.po
@@ -0,0 +1,22 @@
+# English translations for sss_daemon package.
+# Copyright (C) 2009 Red Hat, Inc.
+# This file is distributed under the same license as the sss_daemon package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: sss_daemon 0.4.0\n"
+"Report-Msgid-Bugs-To: freeipa-devel@redhat.com\n"
+"POT-Creation-Date: 2009-06-15 10:21-0400\n"
+"PO-Revision-Date: 2009-06-15 10:21-0400\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: tools/sss_useradd.c:484
+#, c-format
+msgid "The user %s already exists\n"
+msgstr "The user %s already exists\n"
diff --git a/server/po/sss_daemon.pot b/server/po/sss_daemon.pot
new file mode 100644
index 0000000..73457d0
--- /dev/null
+++ b/server/po/sss_daemon.pot
@@ -0,0 +1,22 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Red Hat, Inc.
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: sss_daemon 0.4.0\n"
+"Report-Msgid-Bugs-To: freeipa-devel@redhat.com\n"
+"POT-Creation-Date: 2009-06-15 10:21-0400\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: tools/sss_useradd.c:484
+#, c-format
+msgid "The user %s already exists\n"
+msgstr ""
diff --git a/server/tools/sss_groupadd.c b/server/tools/sss_groupadd.c
index 5e1aeb9..eb7b3d8 100644
--- a/server/tools/sss_groupadd.c
+++ b/server/tools/sss_groupadd.c
@@ -134,9 +134,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
-    ret = setup_db(&ctx);
+    ret = init_sss_tools(&ctx);
     if(ret != EOK) {
-        DEBUG(0, ("Could not set up database\n"));
+        DEBUG(0, ("Could not set up tools\n"));
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_groupdel.c b/server/tools/sss_groupdel.c
index 8e07feb..3158710 100644
--- a/server/tools/sss_groupdel.c
+++ b/server/tools/sss_groupdel.c
@@ -127,9 +127,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
-    ret = setup_db(&ctx);
+    ret = init_sss_tools(&ctx);
     if(ret != EOK) {
-        DEBUG(0, ("Could not set up database\n"));
+        DEBUG(0, ("Could not set up tools\n"));
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_groupmod.c b/server/tools/sss_groupmod.c
index e2c59cb..d6c1915 100644
--- a/server/tools/sss_groupmod.c
+++ b/server/tools/sss_groupmod.c
@@ -254,9 +254,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
-    ret = setup_db(&ctx);
+    ret = init_sss_tools(&ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Could not set up database\n"));
+        DEBUG(0, ("Could not set up tools\n"));
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_useradd.c b/server/tools/sss_useradd.c
index a01cd7f..84f38fa 100644
--- a/server/tools/sss_useradd.c
+++ b/server/tools/sss_useradd.c
@@ -31,6 +31,7 @@
 #include "util/util.h"
 #include "db/sysdb.h"
 #include "tools/tools_util.h"
+#include "util/sssd-i18n.h"
 
 /* Define default command strings if not redefined by user */
 #ifndef USERADD
@@ -335,9 +336,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
-    ret = setup_db(&ctx);
+    ret = init_sss_tools(&ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Could not set up database\n"));
+        DEBUG(0, ("Could not set up tools\n"));
         ret = EXIT_FAILURE;
         goto fini;
     }
@@ -480,7 +481,7 @@ int main(int argc, const char **argv)
         ret = user_ctx->error;
         switch (ret) {
             case EEXIST:
-                DEBUG(0, ("The user %s already exists\n", user_ctx->username));
+                DEBUG(0, (_("The user %s already exists\n"), user_ctx->username));
                 break;
 
             default:
diff --git a/server/tools/sss_userdel.c b/server/tools/sss_userdel.c
index 713c938..e374b14 100644
--- a/server/tools/sss_userdel.c
+++ b/server/tools/sss_userdel.c
@@ -126,9 +126,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
-    ret = setup_db(&ctx);
+    ret = init_sss_tools(&ctx);
     if(ret != EOK) {
-        DEBUG(0, ("Could not set up database\n"));
+        DEBUG(0, ("Could not set up tools\n"));
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_usermod.c b/server/tools/sss_usermod.c
index d19fe9d..a5eadce 100644
--- a/server/tools/sss_usermod.c
+++ b/server/tools/sss_usermod.c
@@ -322,9 +322,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
-    ret = setup_db(&ctx);
+    ret = init_sss_tools(&ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Could not set up database\n"));
+        DEBUG(0, ("Could not set up tools\n"));
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c
index 0f093cb..15665d3 100644
--- a/server/tools/tools_util.c
+++ b/server/tools/tools_util.c
@@ -228,3 +228,23 @@ int parse_groups(TALLOC_CTX *mem_ctx, const char *optstr, char ***_out)
     return EOK;
 }
 
+int init_sss_tools(struct tools_ctx **ctx)
+{
+    int ret;
+    /* Set up LOCALE */
+    setlocale (LC_ALL, "");
+    bindtextdomain (PACKAGE, LOCALEDIR);
+    textdomain (PACKAGE);
+
+    /* Connect to the database */
+    ret = setup_db(ctx);
+    if (ret != EOK) {
+        DEBUG(0, ("Could not set up database\n"));
+        ret = EXIT_FAILURE;
+        goto fini;
+    }
+
+    ret = EOK;
+fini:
+    return ret;
+}
diff --git a/server/tools/tools_util.h b/server/tools/tools_util.h
index e055fe2..7c66c11 100644
--- a/server/tools/tools_util.h
+++ b/server/tools/tools_util.h
@@ -1,6 +1,8 @@
 #ifndef __TOOLS_UTIL_H__
 #define __TOOLS_UTIL_H__
 
+#include "util/sssd-i18n.h"
+
 #define UID_NOT_SET 0
 #define GID_NOT_SET 0
 
@@ -36,6 +38,8 @@ struct tools_ctx {
     struct sss_domain_info *domains;
 };
 
+int init_sss_tools(struct tools_ctx **ctx);
+
 int setup_db(struct tools_ctx **ctx);
 
 void usage(poptContext pc, const char *error);
diff --git a/server/util/server.c b/server/util/server.c
index 7c1c927..4dfd18e 100644
--- a/server/util/server.c
+++ b/server/util/server.c
@@ -29,6 +29,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include "util/util.h"
+#include "util/sssd-i18n.h"
 #include "ldb.h"
 #include "confdb/confdb.h"
 
@@ -280,6 +281,11 @@ int server_setup(const char *name, int flags,
         }
     }
 
+    /* Set up locale */
+    setlocale (LC_ALL, "");
+    bindtextdomain (PACKAGE, LOCALEDIR);
+    textdomain (PACKAGE);
+
     /* the event context is the top level structure.
      * Everything else should hang off that */
     event_ctx = tevent_context_init(talloc_autofree_context());
diff --git a/server/util/sssd-i18n.h b/server/util/sssd-i18n.h
new file mode 100644
index 0000000..74f9bec
--- /dev/null
+++ b/server/util/sssd-i18n.h
@@ -0,0 +1,8 @@
+#ifndef _SSSD_I18N_H
+#define _SSSD_I18N_H
+
+#include <libintl.h>
+#define _(STRING) gettext (STRING)
+#include "config.h"
+
+#endif
diff --git a/sssd.spec.in b/sssd.spec.in
index 165cd8a..b6ceb5f 100644
--- a/sssd.spec.in
+++ b/sssd.spec.in
@@ -108,6 +108,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man5/*
 %{_mandir}/man8/*
 %{_datadir}/locale/*/LC_MESSAGES/sss_client.mo
+%{_datadir}/locale/*/LC_MESSAGES/sss_daemon.mo
 
 %post
 /sbin/ldconfig
-- 
1.6.2.2

