[Python-checkins] CVS: python/dist/src/Lib gettext.py,1.2,1.3

Barry Warsaw python-dev@python.org
Fri, 25 Aug 2000 13:26:45 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv25063

Modified Files:
	gettext.py 
Log Message:
_expand_lang(), _find(): Added support for unaliasing and expanded the
language found in the environment variable, contributed by James
Henstridge.


Index: gettext.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/gettext.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** gettext.py	2000/08/25 19:53:17	1.2
--- gettext.py	2000/08/25 20:26:43	1.3
***************
*** 87,91 ****
  """
  
! # This module represents the integration of work from the following authors:
  #
  # Martin von Loewis, who wrote the initial implementation of the underlying
--- 87,92 ----
  """
  
! # This module represents the integration of work, contributions, feedback, and
! # suggestions from the following people:
  #
  # Martin von Loewis, who wrote the initial implementation of the underlying
***************
*** 122,125 ****
--- 123,169 ----
  
  
+ def _expand_lang(locale):
+     from locale import normalize
+     locale = normalize(locale)
+     COMPONENT_CODESET   = 1 << 0
+     COMPONENT_TERRITORY = 1 << 1
+     COMPONENT_MODIFIER  = 1 << 2
+     # split up the locale into its base components
+     mask = 0
+     pos = locale.find('@')
+     if pos >= 0:
+         modifier = locale[pos:]
+         locale = locale[:pos]
+         mask |= COMPONENT_MODIFIER
+     else:
+         modifier = ''
+     pos = locale.find('.')
+     if pos >= 0:
+         codeset = locale[pos:]
+         locale = locale[:pos]
+         mask |= COMPONENT_CODESET
+     else:
+         codeset = ''
+     pos = locale.find('_')
+     if pos >= 0:
+         territory = locale[pos:]
+         locale = locale[:pos]
+         mask |= COMPONENT_TERRITORY
+     else:
+         territory = ''
+     language = locale
+     ret = []
+     for i in range(mask+1):
+         if not (i & ~mask):  # if all components for this combo exist ...
+             val = language
+             if i & COMPONENT_TERRITORY: val += territory
+             if i & COMPONENT_CODESET:   val += codeset
+             if i & COMPONENT_MODIFIER:  val += modifier
+             ret.append(val)
+     ret.reverse()
+     return ret
+ 
+ 
+ 
  class GNUTranslations(UserDict):
      # Magic number of .mo files
***************
*** 159,164 ****
              #
              # advance to next entry in the seek tables
!             masteridx = masteridx + 8
!             transidx = transidx + 8
          return catalog
  
--- 203,208 ----
              #
              # advance to next entry in the seek tables
!             masteridx += 8
!             transidx += 8
          return catalog
  
***************
*** 172,176 ****
      global _current_domain
      global _localedirs
- 
      # Get some reasonable defaults for arguments that were not supplied
      if domain is None:
--- 216,219 ----
***************
*** 194,197 ****
--- 237,246 ----
          if 'C' not in languages:
              languages.append('C')
+     # now normalize and expand the languages
+     langdict = {}
+     for lang in languages:
+         for nelang in _expand_lang(lang):
+             langdict[nelang] = nelang
+     languages = langdict.keys()
      # select a language
      for lang in languages: