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

[PATCH] gettext on Win32

From: D.J. Heap <dj_at_shadyvale.net>
Date: 2004-04-09 03:34:17 CEST

This is not a complete patch, but I thought I'd put it out here for
interested parties to look at and comment on. It does not yet calculate
the path to the locale directory, and it does not update the dsp
generator -- just the vcproj one. The changes are simple, though, and I
can probably refactor some of it, once I update the dsp generator.

The locale project support is modelled after the existing neon.

I can compile and link and pass all tests with this, but I don't believe
there is much really exercising the gettext stuff yet...once it goes in
there may be more to be done, but shouldn't be much.

Any objections/recommendations on the approach?

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.

Index: build.conf
===================================================================
--- build.conf (revision 9303)
+++ build.conf (working copy)
@@ -248,6 +248,7 @@
 type = i18n
 path = subversion/po
 install = locale
+external-project = build/win32\svn_locale
 
 # ----------------------------------------------------------------------------
 #
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 9303)
+++ 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 9303)
+++ 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 9303)
+++ 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 9303)
+++ svn_private_config.hw (working copy)
@@ -48,8 +48,16 @@
 /* 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"
+#define SVN_LOCALE_DIR "C:\\Stuff\\gettext\\share\\locale"
+#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 9303)
+++ 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 Fri Apr 9 03:32:31 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.