[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Do not use gettextize and i18n round 2 Re: I18n: The gettext proposal

From: Justin Erenkrantz <justin_at_erenkrantz.com>
Date: 2004-03-30 20:28:42 CEST

--On Tuesday, March 30, 2004 11:57 AM -0600 Ben Collins-Sussman
<sussman@collab.net> wrote:

> I've always assumed that localizing Subversion means we're going to add
> a new runtime library dependency, as well a number of compile-time
> dependencies on specific tools. Is this a problem? Is it not worth the
> pain? It certainly doesn't bother me. Is there disagreement among
> developers on this point?

My only desire in this whole i18n effort is not to introduce a build or
runtime dependency on GNU gettext. The patch that I submitted last night
works with Solaris's gettext, which is integrated into Solaris's libc and
doesn't suffer from being LGPLed.

So, as far as I'm concerned, I'm mostly happy...for now. ;-)

>> I think my biggest concern for i18n adoption is that we will no longer be
>> able to use constant char *'s for our error strings (the big help
>> structs). A lot of our help code and error strings rely upon that, so I
>> don't know how we're going to refactor that.
>
> I don't understand... can you elaborate? In Nicolas' email, he
> explained how a number of code changes would be required to work with
> the xgettext scanner. Is this another one to add to that list?

Okay, so the problem is that we have a very common paradigm like:

in subversion/clients/cmdline/help-cmd.c:

const char svn_cl__help_header[] =
    "usage: svn <subcommand> [options] [args]\n"
    "Type \"svn help <subcommand>\" for help on a specific subcommand.\n"
    "\n"
    "Most subcommands take file and/or directory arguments, recursing\n"
    "on the directories. If no arguments are supplied to such a\n"
    "command, it will recurse on the current directory (inclusive) by\n"
    "default.\n"
    "\n"
    "Available subcommands:\n";

These are compiled-in constant strings. However, with the i18n requirement
and the way gettext operates, these can't be compiled-in constants anymore as
the translation needs to occur at run-time to the 'correct' translation.

We'll have to rethink somewhat how we treat such constants.

> Also, while I'm here, let me suggest a strategy for moving forward:
>
> 0. Start a completely new mail thread about what we do/don't have to do
> regarding linking to LGPL libraries like libneon or libintl. We've had
...
> 1. Get gettexty tools fully integrated into our build-system, and make
> sure they work exactly the way we want on all our different platforms.
> This can be done in a series of trunk commits; I don't think we need a
> branch.
>
> 2. After all the build-system work is complete, *then* we start
> refactoring our stringy code for the scanner.
>
> 3. When steps 1 and 2 are finished, we'll finally have a complete .pot
> template, and we can let volunteers start producing .po files.

+1. Sounds sane.

> Justin's build-system patch, though. I might ask Justin, however, if
> he'd be willing to trim down his patch to *just* build-system changes,
> and not _() changes. I beg for smaller patches, easier for newbies like
> me to understand. No power plants. :-)

Heh. Just drop most of the .c file changes. I've attached a trimmed-down
version here that also includes the fixup for main.c. It also includes the
_() for the default error in opt.c - that's a quick way to test if everything
is working.

I'd just need to test this against a GNU gettext install. If it works, would
there be any reason not to commit the build infrastructure to the trunk? I
can probably get to this tonight, I guess. -- justin

* Makefile.in: Add localedir, MSGFMT, PACKAGE_NAME, PACKAGE_VERSION substs from
  configure; add in build-i18n and install-i18n targets
  [installs to right location for Solaris; no clue about GNU gettext]
* configure.in: Remove old placeholder for GNU gettext and move down to a
  more sensible location; add in i18n config section which enables NLS iff
  msgfmt is found; export SVN_LOCALE_DIR properly escaped so main.c can use;
  if i18n enabled, add in build-i18n and install-i18n targets
  [the double eval is funny, but there isn't a clean way to fully expand here.
   There are some M4 macros in apr or httpd for this though.]
* subversion/clients/cmdline/main.c: Include svn_private_config.h, _()-escape
  some strings
  (main): call setlocale, bindtextdomain, and textdomain to initialize gettext
* subversion/libsvn_subr/opt.c (svn_opt_print_help): Add _() to the 'default'
  case when there are no arguments.

Index: Makefile.in
===================================================================
--- Makefile.in (revision 9230)
+++ Makefile.in (working copy)
@@ -57,6 +57,7 @@
 infodir = @infodir@
 datadir = @datadir@
 docdir = @docdir@
+localedir = @localedir@

 # where to install libsvn_swig_*
 swig_py_libdir = @libdir@
@@ -78,7 +79,10 @@
 TEXI2DVI = texi2dvi
 DVIPS = dvips
 DVIPDF = dvipdf
+MSGFMT = @MSGFMT@

+PACKAGE_NAME=@PACKAGE_NAME@
+PACKAGE_VERSION=@PACKAGE_VERSION@

 CC = @CC@
 CXX = @CXX@
@@ -511,3 +515,17 @@
           echo "$(INSTALL_DATA) $$file $(DESTDIR)$(infodir)/$$inst"; \
           $(INSTALL_DATA) $$file $(DESTDIR)$(infodir)/$$inst; \
         done
+
+ALL_LINGUAS=@ALL_LINGUAS@
+build-i18n:
+ @list='$(ALL_LINGUAS)'; \
+ for i in $$list; do \
+ $(MSGFMT) -o po/$$i.mo $(srcdir)/po/$$i.po; \
+ done
+
+install-i18n:
+ $(MKDIR) $(DESTDIR)$(localedir)
+ @list='$(ALL_LINGUAS)'; \
+ for i in $$list; do \
+ $(INSTALL_DATA) po/$$i.mo
$(DESTDIR)$(localedir)/$$i/LC_MESSAGES/$(PACKAGE_NAME).mo; \
+ done
Index: configure.in
===================================================================
--- configure.in (revision 9230)
+++ configure.in (working copy)
@@ -73,11 +73,6 @@
 dnl (We can add custom defines by creating ./acconfig.h if we wish.)
 AC_CONFIG_HEADER(svn_private_config.h)

-dnl Todo: we're English-only now, but GNU Gettext eventually?
-dnl Set of available languages.
-dnl ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
-dnl I volunteer for this ^^ translation :-) -xbc
-
 dnl Check for programs ---------------------

 dnl Look for a C compiler (before anything can set CFLAGS)
@@ -255,7 +250,43 @@
 SVN_LIB_BERKELEY_DB($SVN_FS_WANT_DB_MAJOR, $SVN_FS_WANT_DB_MINOR,
                     $SVN_FS_WANT_DB_PATCH, [db4 db])

+dnl I18n -------------------

+localedir='${datadir}/locale'
+localedir="${localedir}/subversion-${svn_version}"
+AC_SUBST(localedir)
+
+dnl Set of available languages.
+dnl ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
+dnl I volunteer for this ^^ translation :-) -xbc
+ALL_LINGUAS="es"
+AC_SUBST(ALL_LINGUAS)
+
+USE_NLS="no"
+AC_PATH_PROG(MSGFMT, msgfmt, none)
+if test "$MSGFMT" != "none"; then
+ AC_DEFINE(ENABLE_NLS, 1,
+ [Define to 1 if translation of program messages to the user's
+ native language is requested.])
+ dnl Must expand twice at least to get prefix expanded!
+ svn_localedir="`eval echo ${localedir}`"
+ svn_localedir="`eval echo ${svn_localedir}`"
+ AC_DEFINE_UNQUOTED(SVN_LOCALE_DIR, "${svn_localedir}",
+ [Defined to be the path to the installed locale dirs])
+ USE_NLS="yes"
+fi
+
+AH_BOTTOM(
+#define N_(x) (x)
+#ifdef ENABLE_NLS
+#include <locale.h>
+#include <libintl.h>
+#define _(x) dgettext(PACKAGE_NAME, x)
+#else
+#define _(x) (x)
+#endif
+)
+
 # Only add *_APACHE_RULE if we also have db, since mod_dav_svn depends on it.
 INSTALL_STATIC_RULES="install-bin install-docs"
 INSTALL_RULES="install-base-lib install-lib install-include install-static"
@@ -274,6 +305,11 @@
   INSTALL_RULES="`echo $INSTALL_RULES | sed 's/install-lib/install-dav-lib
install-lib/'`"
 fi

+if test "$USE_NLS" = "yes"; then
+ BUILD_RULES="$BUILD_RULES build-i18n"
+ INSTALL_RULES="$INSTALL_RULES install-i18n"
+fi
+
 AC_SUBST(BUILD_RULES)
 AC_SUBST(INSTALL_STATIC_RULES)
 AC_SUBST(INSTALL_RULES)
Index: subversion/libsvn_subr/opt.c
===================================================================
--- subversion/libsvn_subr/opt.c (revision 9230)
+++ subversion/libsvn_subr/opt.c (working copy)
@@ -36,6 +36,8 @@
 #include "svn_utf.h"
 #include "svn_time.h"

+#include "svn_private_config.h"
+
 
 /*** Code. ***/

@@ -735,7 +737,7 @@
                                 pool,
                                 stdout);
   else /* unknown option or cmd */
- fprintf (stderr, "Type '%s help' for usage.\n", pgm_name);
+ fprintf (stderr, _("Type '%s help' for usage.\n"), pgm_name);

   return SVN_NO_ERROR;
 }
Index: subversion/clients/cmdline/main.c
===================================================================
--- subversion/clients/cmdline/main.c (revision 9230)
+++ subversion/clients/cmdline/main.c (working copy)
@@ -47,6 +47,8 @@
 #include "svn_auth.h"
 #include "cl.h"

+#include "svn_private_config.h"
+
 
 /*** Option Processing ***/

@@ -656,6 +658,12 @@
   svn_cl__cmd_baton_t command_baton;
   svn_auth_baton_t *ab;
   svn_config_t *cfg;
+
+#ifdef ENABLE_NLS
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE_NAME, SVN_LOCALE_DIR);
+ textdomain (PACKAGE_NAME);
+#endif

   /* Initialize the app. */
   if (svn_cmdline_init ("svn", stderr) != EXIT_SUCCESS)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Mar 30 20:29:01 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.