Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
gettext Namespace Reference

Data Structures

class  NullTranslations
 
class  GNUTranslations
 

Functions

def find
 
def translation
 
def install
 
def textdomain
 
def bindtextdomain
 
def dgettext
 
def gettext
 

Variables

list __all__
 
tuple _default_localedir = os.path.join(sys.prefix, 'share', 'locale')
 
dictionary _translations = {}
 
dictionary _localedirs = {}
 
string _current_domain = 'messages'
 
 Catalog = translation
 

Detailed Description

Internationalization and localization support.

This module provides internationalization (I18N) and localization (L10N)
support for your Python programs by providing an interface to the GNU gettext
message catalog library.

I18N refers to the operation by which a program is made aware of multiple
languages.  L10N refers to the adaptation of your program, once
internationalized, to the local language and cultural habits.

Function Documentation

def gettext.bindtextdomain (   domain,
  localedir = None 
)

Definition at line 271 of file gettext.py.

272 def bindtextdomain(domain, localedir=None):
273  global _localedirs
274  if localedir is not None:
275  _localedirs[domain] = localedir
276  return _localedirs.get(domain, _default_localedir)
277 
def gettext.dgettext (   domain,
  message 
)

Definition at line 278 of file gettext.py.

References translation().

279 def dgettext(domain, message):
280  try:
281  t = translation(domain, _localedirs.get(domain, None))
282  except IOError:
283  return message
284  return t.gettext(message)
285 
def gettext.find (   domain,
  localedir = None,
  languages = None 
)

Definition at line 200 of file gettext.py.

201 def find(domain, localedir=None, languages=None):
202  # Get some reasonable defaults for arguments that were not supplied
203  if localedir is None:
204  localedir = _default_localedir
205  if languages is None:
206  languages = []
207  for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
208  val = os.environ.get(envar)
209  if val:
210  languages = val.split(':')
211  break
212  if 'C' not in languages:
213  languages.append('C')
214  # now normalize and expand the languages
215  nelangs = []
216  for lang in languages:
217  for nelang in _expand_lang(lang):
218  if nelang not in nelangs:
219  nelangs.append(nelang)
220  # select a language
221  for lang in nelangs:
222  if lang == 'C':
223  break
224  mofile = os.path.join(localedir, lang, 'LC_MESSAGES', '%s.mo' % domain)
225  if os.path.exists(mofile):
226  return mofile
227  return None
228 
229 
230 
# a mapping between absolute .mo file path and Translation object
def gettext.gettext (   message)

Definition at line 286 of file gettext.py.

References dgettext().

287 def gettext(message):
288  return dgettext(_current_domain, message)
289 
290 
291 # dcgettext() has been deemed unnecessary and is not implemented.
292 
293 # James Henstridge's Catalog constructor from GNOME gettext. Documented usage
294 # was:
295 #
296 # import gettext
297 # cat = gettext.Catalog(PACKAGE, localedir=LOCALEDIR)
298 # _ = cat.gettext
299 # print _('Hello World')
300 
301 # The resulting catalog object currently don't support access through a
302 # dictionary API, which was supported (but apparently unused) in GNOME
303 # gettext.
def gettext.install (   domain,
  localedir = None,
  unicode = 0 
)

Definition at line 253 of file gettext.py.

References translation().

254 def install(domain, localedir=None, unicode=0):
255  translation(domain, localedir, fallback=1).install(unicode)
256 
257 
258 
# a mapping b/w domains and locale directories
def gettext.textdomain (   domain = None)

Definition at line 264 of file gettext.py.

265 def textdomain(domain=None):
266  global _current_domain
267  if domain is not None:
268  _current_domain = domain
269  return _current_domain
270 
def gettext.translation (   domain,
  localedir = None,
  languages = None,
  class_ = None,
  fallback = 0 
)

Definition at line 234 of file gettext.py.

References smtpd.class_, find(), and aifc.open().

235  class_=None, fallback=0):
236  if class_ is None:
237  class_ = GNUTranslations
238  mofile = find(domain, localedir, languages)
239  if mofile is None:
240  if fallback:
241  return NullTranslations()
242  raise IOError(ENOENT, 'No translation file found for domain', domain)
243  key = os.path.abspath(mofile)
244  # TBD: do we need to worry about the file pointer getting collected?
245  # Avoid opening, reading, and parsing the .mo file after it's been done
246  # once.
247  t = _translations.get(key)
248  if t is None:
249  t = _translations.setdefault(key, class_(open(mofile, 'rb')))
250  return t
251 
252 

Variable Documentation

list __all__
Initial value:
1 = ["bindtextdomain","textdomain","gettext","dgettext",
2  "find","translation","install","Catalog"]

Definition at line 51 of file gettext.py.

string _current_domain = 'messages'

Definition at line 261 of file gettext.py.

tuple _default_localedir = os.path.join(sys.prefix, 'share', 'locale')

Definition at line 54 of file gettext.py.

dictionary _localedirs = {}

Definition at line 259 of file gettext.py.

dictionary _translations = {}

Definition at line 231 of file gettext.py.

Catalog = translation

Definition at line 304 of file gettext.py.