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

Re: [PATCH] gettext on Win32

From: D.J. Heap <dj_at_shadyvale.net>
Date: 2004-04-17 01:24:15 CEST

Here's a new version of the build system patch -- it builds and passes
ra_local tests with and without gettext support. It sounds like it'll
need a slight tweak (for the direct gettext calls) and I need to change
the dsp generator slightly, but I will do that and commit it tomorrow if
there are no objections. I have not actually tested trying to use an
alternate language...if it's not very involved I will do it if told how
(is it just a matter of temporarily changing Control Panel -> Regional
and Language settings or do I need to install/change more stuff?).

I used the following gettext binaries from http://mirrors.kernel.org/gnu
(I had c-runtime headaches trying to use the latest version and other
implementations):

gettext-runtime-0.12.1.bin.woe32.zip
gettext-tools-0.12.1.bin.woe32.zip
libiconv-1.9.1.bin.woe32.zip

I will try to update the INSTALL doc sometime this weekend after this is
committed.

Log:
Update the Win32 project generators to handle gettext and localization
requirements.

* build.conf
   Add external-project path to locale target for Win32.

* build/win32/svn_locale.vcproj
   New project file for locale build target.

* build/generator/build_locale.ezt
   New batch file template for creating localization files.

* build/generator/gen_vcnet_vcproj.py
   Add support for the new TargetI18N target type.

* build/generator/gen_base.py
   (TargetI18N.__init__): Read in the external-project option.

* build/generator/gen_win.py
   Add --enable-nls option. If it's on then populate the
   build_locale.bat file with the .po file targets and setup the
   appropriate defines and link settings.

* svn_private_config.hw
   Define N_, _, PACKAGE_NAME appropriately and stub in a
   SVN_LOCALE_DIR for now.

* gen-make.py
   Add Windows-specific --enable-nls option.

* subversion/libsvn_subr/cmdline.c
   (svn_cmdline_init): Setup gettext support for Win32 which involved
   moving the gettext initialization to after apr initialization so
   it's functionality could be used.

Index: build.conf
===================================================================
--- build.conf (revision 9388)
+++ build.conf (working copy)
@@ -248,6 +248,7 @@
 type = i18n
 path = subversion/po
 install = locale
+external-project = build/win32\svn_locale
 
 # ----------------------------------------------------------------------------
 #
Index: subversion/libsvn_subr/cmdline.c
===================================================================
--- subversion/libsvn_subr/cmdline.c (revision 9388)
+++ subversion/libsvn_subr/cmdline.c (working copy)
@@ -93,10 +93,6 @@
         }
       return EXIT_FAILURE;
     }
-#ifdef ENABLE_NLS
- bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);
- textdomain(PACKAGE_NAME);
-#endif
 
   /* Initialize the APR subsystem, and register an atexit() function
      to Uninitialize that subsystem at program exit. */
@@ -123,6 +119,31 @@
       return EXIT_FAILURE;
     }
 
+#ifdef ENABLE_NLS
+#ifdef WIN32
+ {
+ char native_file_name[_MAX_PATH];
+ const char* internal_path;
+ apr_pool_t* pool;
+
+ apr_pool_create (&pool, 0);
+ /* get exe name - our locale info will be in '../share/locale' */
+ GetModuleFileName (0, native_file_name, sizeof(native_file_name));
+ internal_path = svn_path_internal_style (native_file_name, pool);
+ /* get base path name */
+ internal_path = svn_path_dirname (internal_path, pool);
+ /* back up one dir and append 'share/locale' */
+ internal_path = svn_path_dirname (internal_path, pool);
+ internal_path = svn_path_join (internal_path, "share/locale", pool);
+ bindtextdomain (PACKAGE_NAME, internal_path);
+ apr_pool_destroy (pool);
+ }
+#else
+ bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);
+#endif
+ textdomain(PACKAGE_NAME);
+#endif
+
   return EXIT_SUCCESS;
 }
 
Index: build/win32/svn_locale.vcproj
===================================================================
--- build/win32/svn_locale.vcproj (revision 0)
+++ build/win32/svn_locale.vcproj (revision 0)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="locale"
+ SccProjectName=""
+ SccLocalPath=""
+ Keyword="MakeFileProj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ ConfigurationType="0"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE">
+ <Tool
+ Name="VCNMakeTool"
+ BuildCommandLine="cmd /c build_locale.bat"
+ ReBuildCommandLine="cmd /c build_locale.bat"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ ConfigurationType="0"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="FALSE">
+ <Tool
+ Name="VCNMakeTool"
+ BuildCommandLine="cmd /c build_locale.bat"
+ ReBuildCommandLine="cmd /c build_locale.bat"
+ />
+ </Configuration>
+ </Configurations>
+ <Files>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Index: build/generator/build_locale.ezt
===================================================================
--- build/generator/build_locale.ezt (revision 0)
+++ build/generator/build_locale.ezt (revision 0)
@@ -0,0 +1,13 @@
+@echo off
+@rem **************************************************************************
+cd ..\..\subversion\po
+[for pofiles]echo Running msgfmt on [pofiles.po]...
+msgfmt.exe -o [pofiles.mo] [pofiles.po]
+if not errorlevel 0 goto err
+[end]
+goto end
+@rem **************************************************************************
+:err
+set exitcode=1
+:end
+exit %exitcode%
Index: build/generator/gen_vcnet_vcproj.py
===================================================================
--- build/generator/gen_vcnet_vcproj.py (revision 9388)
+++ build/generator/gen_vcnet_vcproj.py (working copy)
@@ -38,6 +38,9 @@
     elif isinstance(target, gen_base.TargetProject):
       config_type=1
       target.output_name = target.name + '.exe'
+ elif isinstance(target, gen_base.TargetI18N):
+ config_type=4
+ target.output_name = target.name
     else:
       raise gen_base.GenError("Cannot create project for %s" % target.name)
 
@@ -60,7 +63,8 @@
       'default_platform' : self.platforms[0],
       'default_config' : configs[0].name,
       'is_exe' : ezt.boolean(isinstance(target, gen_base.TargetExe)),
- 'is_external' : ezt.boolean(isinstance(target, gen_base.TargetProject)
+ 'is_external' : ezt.boolean((isinstance(target, gen_base.TargetProject)
+ or isinstance(target, gen_base.TargetI18N))
                                   and target.cmd),
       'is_utility' : ezt.boolean(isinstance(target,
                                             gen_base.TargetProject)),
@@ -124,8 +128,6 @@
       # These aren't working yet
       if isinstance(target, gen_base.TargetProject) and target.cmd:
         continue
- if isinstance(target, gen_base.TargetI18N):
- continue
       guids[target.name] = self.makeguid(target.name)
 
     self.gen_proj_names(install_targets)
@@ -136,10 +138,10 @@
       # These aren't working yet
       if isinstance(target, gen_base.TargetProject) and target.cmd:
         continue
- if isinstance(target, gen_base.TargetI18N):
- continue
 
- if isinstance(target, gen_base.TargetLinked) and target.external_project:
+ if ((isinstance(target, gen_base.TargetLinked)
+ or isinstance(target, gen_base.TargetI18N))
+ and target.external_project):
         # Figure out where the external .vcproj is located.
         fname = target.external_project + '.vcproj'
       else:
@@ -151,7 +153,9 @@
       if '-' in fname:
         fname = '"%s"' % fname
 
- depends = self.adjust_win_depends(target, name)
+ depends = [ ]
+ if not isinstance(target, gen_base.TargetI18N):
+ depends = self.adjust_win_depends(target, name)
 
       deplist = [ ]
       for i in range(len(depends)):
Index: build/generator/gen_base.py
===================================================================
--- build/generator/gen_base.py (revision 9388)
+++ build/generator/gen_base.py (working copy)
@@ -505,6 +505,7 @@
     # Let the Makefile determine this via .SUFFIXES
     self.compile_cmd = None
     self.objext = '.mo'
+ self.external_project = options.get('external-project')
 
   def add_dependencies(self, graph, cfg, extmap):
     graph.add(DT_INSTALL, self.install, self)
Index: build/generator/gen_win.py
===================================================================
--- build/generator/gen_win.py (revision 9388)
+++ build/generator/gen_win.py (working copy)
@@ -5,6 +5,7 @@
 import os
 import sys
 import string
+import fnmatch
 
 try:
   from cStringIO import StringIO
@@ -53,6 +54,9 @@
     # Instrumentation options
     self.instrument_apr_pools = None
     self.instrument_purify_quantify = None
+
+ # NLS options
+ self.enable_nls = None
 
     for opt, val in options:
       if opt == '--with-berkeley-db':
@@ -78,6 +82,8 @@
         self.instrument_purify_quantify = 1
       elif opt == '--enable-pool-debug':
         self.instrument_apr_pools = 1
+ elif opt == '--enable-nls':
+ self.enable_nls = 1
 
   def __init__(self, fname, verfname, options, subdir):
     """
@@ -166,6 +172,17 @@
             'openssl_path': self.openssl_path}
     self.write_with_template(os.path.join('build', 'win32', 'build_neon.bat'),
                              'build_neon.ezt', data)
+
+ # Generate the build_locale.bat file
+ pofiles = []
+ if self.enable_nls:
+ for po in os.listdir(os.path.join('subversion', 'po')):
+ if fnmatch.fnmatch(po, '*.po'):
+ pofiles.append(POFile(po, po[:-2] + 'mo'))
+
+ data = {'pofiles': pofiles}
+ self.write_with_template(os.path.join('build', 'win32', 'build_locale.bat'),
+ 'build_locale.ezt', data)
 
     #Initialize parent
     gen_base.GeneratorBase.__init__(self, fname, verfname)
@@ -453,6 +470,10 @@
     if self.dblibname:
       fakedefines.append("APU_HAVE_DB=1")
 
+ # check if they wanted nls
+ if self.enable_nls:
+ fakedefines.append("ENABLE_NLS")
+
     return fakedefines
 
   def get_win_includes(self, target, rootpath):
@@ -519,6 +540,8 @@
       return []
 
     nondeplibs = target.msvc_libs[:]
+ if self.enable_nls:
+ nondeplibs.extend(['intl.lib'])
 
     if isinstance(target, gen_base.TargetExe):
       nondeplibs.append('setargv.obj')
@@ -603,3 +626,8 @@
 FILTER_LIBS = 1
 FILTER_PROJECTS = 2
 
+class POFile:
+ "Item class for holding po file info"
+ def __init__(self, po, mo):
+ self.po = po
+ self.mo = mo
Index: svn_private_config.hw
===================================================================
--- svn_private_config.hw (revision 9388)
+++ svn_private_config.hw (working copy)
@@ -48,8 +48,15 @@
 /* Defined to be the path to the installed binaries */
 #define SVN_BINARY_DIR "/usr/local/bin"
 
-/* Until Win32 gets gettext functionality, leave these disabled. */
+/* Setup gettext macros */
 #define N_(x) (x)
+#ifdef ENABLE_NLS
+#define PACKAGE_NAME "subversion"
+#include <locale.h>
+#include <libintl.h>
+#define _(x) dgettext(PACKAGE_NAME, x)
+#else
 #define _(x) (x)
+#endif
 
 #endif /* CONFIG_HW */
Index: gen-make.py
===================================================================
--- gen-make.py (revision 9388)
+++ gen-make.py (working copy)
@@ -100,6 +100,9 @@
   print
   print " --enable-quantify"
   print " add support for Quantify instrumentation"
+ print
+ print " --enable-nls"
+ print " add support for gettext localization"
   sys.exit(0)
 
 
@@ -128,6 +131,7 @@
                                 'enable-pool-debug',
                                 'enable-purify',
                                 'enable-quantify',
+ 'enable-nls',
                                 ])
     if len(args) > 1:
       _usage_exit()

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Apr 17 01:22:54 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.