gettext markup of library sources

Phil Edwards phil@jaj.com
Mon Apr 28 21:04:00 GMT 2003


On Mon, Apr 28, 2003 at 03:13:56PM -0500, Benjamin Kosnik wrote:
> 
> Once you put this in, I can go through and standardize all the strings.

Go for it.  Final patch below, put the __N hook in a few more headers.


2003-04-28  Phil Edwards  <pme@gcc.gnu.org>

	* configure.in:  Test for libintl.h.
	* include/bits/c++config:  Define __N for everybody.
	* include/bits/basic_string.h, include/bits/stl_bvector.h,
	include/bits/stl_deque.h, include/bits/stl_vector.h,
	include/std/std_bitset.h:  Wrap all __throw* text with __N.
	* po/Makefile.am (pot):  New rule, mostly working.
	* src/functexcept.cc:  Call gettext on all __throw* arguments when
	-fexceptions is in effect.
	* po/Makefile.in, config.h.in, configure:  Regenerate.


Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/configure.in,v
retrieving revision 1.122
diff -u -3 -p -r1.122 configure.in
--- configure.in	23 Apr 2003 22:31:44 -0000	1.122
+++ configure.in	28 Apr 2003 20:59:47 -0000
@@ -401,7 +401,7 @@ else
   # Check for available headers.
   AC_CHECK_HEADERS([nan.h ieeefp.h endian.h sys/isa_defs.h machine/endian.h \
   machine/param.h sys/machine.h fp.h locale.h float.h inttypes.h gconv.h \
-  sys/types.h])
+  sys/types.h libintl.h])
 
   GLIBCPP_CHECK_COMPILER_FEATURES
   GLIBCPP_CHECK_LINKER_FEATURES
Index: include/bits/basic_string.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_string.h,v
retrieving revision 1.28
diff -u -3 -p -r1.28 basic_string.h
--- include/bits/basic_string.h	27 Apr 2003 17:20:42 -0000	1.28
+++ include/bits/basic_string.h	28 Apr 2003 20:59:48 -0000
@@ -275,7 +275,7 @@ namespace std
       _M_check(size_type __pos) const
       {
 	if (__pos > this->size())
-	  __throw_out_of_range("basic_string::_M_check");
+	  __throw_out_of_range(__N("basic_string::_M_check"));
 	return _M_ibegin() + __pos;
       }
 
@@ -447,7 +447,7 @@ namespace std
       at(size_type __n) const
       {
 	if (__n >= this->size())
-	  __throw_out_of_range("basic_string::at");
+	  __throw_out_of_range(__N("basic_string::at"));
 	return _M_data()[__n];
       }
 
@@ -455,7 +455,7 @@ namespace std
       at(size_type __n)
       {
 	if (__n >= size())
-	  __throw_out_of_range("basic_string::at");
+	  __throw_out_of_range(__N("basic_string::at"));
 	_M_leak();
 	return _M_data()[__n];
       }
@@ -818,7 +818,7 @@ namespace std
       substr(size_type __pos = 0, size_type __n = npos) const
       {
 	if (__pos > this->size())
-	  __throw_out_of_range("basic_string::substr");
+	  __throw_out_of_range(__N("basic_string::substr"));
 	return basic_string(*this, __pos, __n);
       }
 
Index: include/bits/c++config
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/c++config,v
retrieving revision 1.712
diff -u -3 -p -r1.712 c++config
--- include/bits/c++config	28 Apr 2003 00:17:06 -0000	1.712
+++ include/bits/c++config	28 Apr 2003 20:59:48 -0000
@@ -97,4 +97,10 @@
 # define _GLIBCPP_FAST_MATH 0
 #endif
 
+// This marks string literals in header files to be extracted for eventual
+// translation.  It is primarily used for messages in thrown exceptions; see
+// src/functexcept.cc.  We use __N because the more traditional _N is used
+// for something else under certain OSes (see BADNAMES).
+#define __N(msgid)     (msgid)
+
 // End of prewritten config; the discovered settings follow.
Index: include/bits/stl_bvector.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_bvector.h,v
retrieving revision 1.20
diff -u -3 -p -r1.20 stl_bvector.h
--- include/bits/stl_bvector.h	16 Jan 2003 20:30:23 -0000	1.20
+++ include/bits/stl_bvector.h	28 Apr 2003 20:59:48 -0000
@@ -480,7 +480,7 @@ template <typename _Alloc> 
   
     void _M_range_check(size_type __n) const {
       if (__n >= this->size())
-        __throw_out_of_range("vector<bool>");
+        __throw_out_of_range(__N("vector<bool>"));
     }
   
     reference at(size_type __n)
@@ -607,7 +607,7 @@ template <typename _Alloc> 
   
     void reserve(size_type __n) {
       if (__n > this->max_size())
-	__throw_length_error("vector::reserve");
+	__throw_length_error(__N("vector::reserve"));
       if (this->capacity() < __n) {
         _Bit_type * __q = _M_bit_alloc(__n);
         this->_M_finish = copy(begin(), end(), iterator(__q, 0));
Index: include/bits/stl_deque.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_deque.h,v
retrieving revision 1.35
diff -u -3 -p -r1.35 stl_deque.h
--- include/bits/stl_deque.h	16 Jan 2003 20:30:23 -0000	1.35
+++ include/bits/stl_deque.h	28 Apr 2003 20:59:48 -0000
@@ -940,7 +940,7 @@ namespace std
     _M_range_check(size_type __n) const
     {
       if (__n >= this->size())
-        __throw_out_of_range("deque [] access out of range");
+        __throw_out_of_range(__N("std::deque [] access out of range"));
     }
   
   public:
Index: include/bits/stl_vector.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_vector.h,v
retrieving revision 1.34
diff -u -3 -p -r1.34 stl_vector.h
--- include/bits/stl_vector.h	16 Jan 2003 20:30:25 -0000	1.34
+++ include/bits/stl_vector.h	28 Apr 2003 20:59:48 -0000
@@ -524,7 +524,7 @@ namespace std
       _M_range_check(size_type __n) const
       {
 	if (__n >= this->size())
-	  __throw_out_of_range("vector [] access out of range");
+	  __throw_out_of_range(__N("std::vector [] access out of range"));
       }
       
     public:
Index: include/std/std_bitset.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_bitset.h,v
retrieving revision 1.13
diff -u -3 -p -r1.13 std_bitset.h
--- include/std/std_bitset.h	15 Apr 2003 06:11:10 -0000	1.13
+++ include/std/std_bitset.h	28 Apr 2003 20:59:49 -0000
@@ -264,7 +264,7 @@ namespace std
     {
       for (size_t __i = 1; __i < _Nw; ++__i)
 	if (_M_w[__i])
-	  __throw_overflow_error("bitset -- too large to fit in unsigned long");
+	  __throw_overflow_error(__N("bitset value is too large to fit in unsigned long"));
       return _M_w[0];
     }
 
@@ -466,7 +466,7 @@ namespace std
       // localized to this single should-never-get-this-far function.
       _WordT&
       _M_getword(size_t) const
-      { __throw_out_of_range("bitset -- zero-length"); return *new _WordT; }
+      { __throw_out_of_range(__N("bitset is zero-length")); return *new _WordT; }
 
       _WordT
       _M_hiword() const { return 0; }
@@ -862,7 +862,7 @@ namespace std
     set(size_t __pos, bool __val = true)
     {
       if (__pos >= _Nb)
-	__throw_out_of_range("bitset -- set() argument too large");
+	__throw_out_of_range(__N("bitset::set() argument too large"));
       return _Unchecked_set(__pos, __val);
     }
 
@@ -887,7 +887,7 @@ namespace std
     reset(size_t __pos)
     {
       if (__pos >= _Nb)
-	__throw_out_of_range("bitset -- reset() argument too large");
+	__throw_out_of_range(__N("bitset::reset() argument too large"));
       return _Unchecked_reset(__pos);
     }
 
@@ -911,7 +911,7 @@ namespace std
     flip(size_t __pos)
     {
       if (__pos >= _Nb)
-	__throw_out_of_range("bitset -- flip() argument too large");
+	__throw_out_of_range(__N("bitset::flip() argument too large"));
       return _Unchecked_flip(__pos);
     }
 
@@ -1014,7 +1014,7 @@ namespace std
     test(size_t __pos) const
     {
       if (__pos >= _Nb)
-	__throw_out_of_range("bitset -- test() argument too large");
+	__throw_out_of_range(__N("bitset::test() argument too large"));
       return _Unchecked_test(__pos);
     }
 
Index: po/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/po/Makefile.am,v
retrieving revision 1.6
diff -u -3 -p -r1.6 Makefile.am
--- po/Makefile.am	7 Jan 2002 18:57:06 -0000	1.6
+++ po/Makefile.am	28 Apr 2003 20:59:49 -0000
@@ -22,6 +22,7 @@
 ## USA.
 
 PACKAGE = @PACKAGE@
+glibcpp_srcdir = @glibcpp_srcdir@
 
 # Location of installation directories.
 mkinstalldirs = $(SHELL) $(toplevel_srcdir)/mkinstalldirs
@@ -76,6 +77,14 @@ install-data-local-yes: all-local-yes
 	  $(mkinstalldirs) $$install_dir; \
 	  $(INSTALL_DATA) $$cat $$install_dir/$(PACKAGE).mo; \
 	done
+
+# Maintainence of the .po template file.  This rule is never run automatically,
+# and updates the source directory.
+pot:
+	cd $(glibcpp_srcdir); \
+	xgettext --default-domain=$(PACKAGE) --add-comments --c++ --debug \
+	  --join-existing -o po/$(PACKAGE).pot --keyword=__N \
+	  `grep -r -l '__N(".*")' .`
 
 # Specify what gets cleaned up on a 'make clean'
 CLEANFILES = $(LOCALE_OUT) 
Index: src/functexcept.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/functexcept.cc,v
retrieving revision 1.3
diff -u -3 -p -r1.3 functexcept.cc
--- src/functexcept.cc	13 Feb 2002 18:29:11 -0000	1.3
+++ src/functexcept.cc	28 Apr 2003 20:59:49 -0000
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -32,6 +32,12 @@
 #include <new>
 #include <typeinfo>
 #include <ios>
+#ifdef _GLIBCPP_HAVE_LIBINTL_H
+# include <libintl.h>
+# define _(msgid)   gettext (msgid)
+#else
+# define _(msgid)   (msgid)
+#endif
 
 namespace std 
 {
@@ -54,43 +60,43 @@ namespace std 
 
   void
   __throw_logic_error(const char* __s)
-  { throw logic_error(__s); }
+  { throw logic_error(_(__s)); }
 
   void
   __throw_domain_error(const char* __s)
-  { throw domain_error(__s); }
+  { throw domain_error(_(__s)); }
 
   void
   __throw_invalid_argument(const char* __s)
-  { throw invalid_argument(__s); }
+  { throw invalid_argument(_(__s)); }
 
   void
   __throw_length_error(const char* __s)
-  { throw length_error(__s); }
+  { throw length_error(_(__s)); }
 
   void
   __throw_out_of_range(const char* __s)
-  { throw out_of_range(__s); }
+  { throw out_of_range(_(__s)); }
 
   void
   __throw_runtime_error(const char* __s)
-  { throw runtime_error(__s); }
+  { throw runtime_error(_(__s)); }
 
   void
   __throw_range_error(const char* __s)
-  { throw range_error(__s); }
+  { throw range_error(_(__s)); }
 
   void
   __throw_overflow_error(const char* __s)
-  { throw overflow_error(__s); }
+  { throw overflow_error(_(__s)); }
 
   void
   __throw_underflow_error(const char* __s)
-  { throw underflow_error(__s); }
+  { throw underflow_error(_(__s)); }
 
   void
   __throw_ios_failure(const char* __s)
-  { throw ios_base::failure(__s); }
+  { throw ios_base::failure(_(__s)); }
 #else
   void
   __throw_bad_exception(void)



More information about the Gcc-patches mailing list