Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.i18n.Translation Class Reference

List of all members.

Public Member Functions

def __init__
def load_po
def load_mo
def formatMarkup
def loadLanguage

Public Attributes

 language
 domain
 translation
 info
 name
 ename
 direction
 maintainer
 has_wikimarkup
 formatted
 raw

Detailed Description

This class represents a translation. Usually this is a translation
    from English original texts to a single language, like e.g. "de" (german).

    The domain value defaults to 'MoinMoin' and this is reserved for
    translation of the MoinMoin distribution. If you do a translation for
    a third-party plugin, you have to use a different and unique value.

Definition at line 143 of file __init__.py.


Constructor & Destructor Documentation

def MoinMoin.i18n.Translation.__init__ (   self,
  language,
  domain = 'MoinMoin' 
)

Definition at line 151 of file __init__.py.

00151 
00152     def __init__(self, language, domain='MoinMoin'):
00153         self.language = language
00154         self.domain = domain


Member Function Documentation

def MoinMoin.i18n.Translation.formatMarkup (   self,
  request,
  text,
  percent 
)
Formats the text using the wiki parser/formatter.

This raises an exception if a text needs itself to be translated,
this could possibly happen with macros.

@param request: the request object
@param text: the text to format
@param percent: True if result is used as left-side of a % operator and
        thus any GENERATED % needs to be escaped as %%.

Definition at line 182 of file __init__.py.

00182 
00183     def formatMarkup(self, request, text, percent):
00184         """ Formats the text using the wiki parser/formatter.
00185 
00186         This raises an exception if a text needs itself to be translated,
00187         this could possibly happen with macros.
00188 
00189         @param request: the request object
00190         @param text: the text to format
00191         @param percent: True if result is used as left-side of a % operator and
00192                         thus any GENERATED % needs to be escaped as %%.
00193         """
00194         logging.debug("formatting: %r" % text)
00195 
00196         from MoinMoin.Page import Page
00197         from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
00198         if percent:
00199             from MoinMoin.formatter.text_html_percent import Formatter
00200         else:
00201             from MoinMoin.formatter.text_html import Formatter
00202 
00203         out = StringIO()
00204         request.redirect(out)
00205         parser = WikiParser(text, request, line_anchors=False)
00206         formatter = Formatter(request, terse=True)
00207         reqformatter = None
00208         if hasattr(request, 'formatter'):
00209             reqformatter = request.formatter
00210         request.formatter = formatter
00211         p = Page(request, "$$$$i18n$$$$")
00212         formatter.setPage(p)
00213         parser.format(formatter)
00214         text = out.getvalue()
00215         if reqformatter is None:
00216             del request.formatter
00217         else:
00218             request.formatter = reqformatter
00219         request.redirect()
00220         text = text.strip()
00221         return text

def MoinMoin.i18n.Translation.load_mo (   self,
  f 
)
load the mo file, setup some attributes from metadata 

Definition at line 165 of file __init__.py.

00165 
00166     def load_mo(self, f):
00167         """ load the mo file, setup some attributes from metadata """
00168         # binary files have to be opened in the binary file mode!
00169         self.translation = gettext.GNUTranslations(f)
00170         self.info = info = self.translation.info()
00171         try:
00172             self.name = info['x-language']
00173             self.ename = info['x-language-in-english']
00174             self.direction = info['x-direction']
00175             self.maintainer = info['last-translator']
00176         except KeyError, err:
00177             logging.warning("metadata problem in %r: %s" % (self.language, str(err)))
00178         try:
00179             assert self.direction in ('ltr', 'rtl', )
00180         except (AttributeError, AssertionError), err:
00181             logging.warning("direction problem in %r: %s" % (self.language, str(err)))

Here is the caller graph for this function:

def MoinMoin.i18n.Translation.load_po (   self,
  f 
)
load the po file 

Definition at line 155 of file __init__.py.

00155 
00156     def load_po(self, f):
00157         """ load the po file """
00158         from MoinMoin.i18n.msgfmt import MsgFmt
00159         mf = MsgFmt()
00160         mf.read_po(f.readlines())
00161         mo_data = mf.generate_mo()
00162         f = StringIO(mo_data)
00163         self.load_mo(f)
00164         f.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.i18n.Translation.loadLanguage (   self,
  request,
  trans_dir = "i18n" 
)

Definition at line 222 of file __init__.py.

00222 
00223     def loadLanguage(self, request, trans_dir="i18n"):
00224         request.clock.start('loadLanguage')
00225         # see comment about per-wiki scope above
00226         cache = caching.CacheEntry(request, arena='i18n', key=self.language, scope='wiki', use_pickle=True)
00227         langfilename = po_filename(request, self.language, self.domain, i18n_dir=trans_dir)
00228         needsupdate = cache.needsUpdate(langfilename)
00229         if not needsupdate:
00230             try:
00231                 unformatted = cache.content()
00232                 logging.debug("pickle %s load success" % self.language)
00233             except caching.CacheError:
00234                 logging.debug("pickle %s load failed" % self.language)
00235                 needsupdate = 1
00236 
00237         if needsupdate:
00238             logging.debug("langfilename %s needs update" % langfilename)
00239             f = file(langfilename)
00240             self.load_po(f)
00241             f.close()
00242             trans = self.translation
00243             unformatted = trans._catalog
00244             self.has_wikimarkup = self.info.get('x-haswikimarkup', 'False') == 'True'
00245             logging.debug("dumping lang %s" % self.language)
00246             try:
00247                 cache.update(unformatted)
00248             except caching.CacheError:
00249                 pass
00250 
00251         self.formatted = {}
00252         self.raw = unformatted
00253         request.clock.stop('loadLanguage')
00254 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 173 of file __init__.py.

Definition at line 153 of file __init__.py.

Definition at line 172 of file __init__.py.

Definition at line 250 of file __init__.py.

Definition at line 243 of file __init__.py.

Definition at line 169 of file __init__.py.

Definition at line 152 of file __init__.py.

Definition at line 174 of file __init__.py.

Definition at line 171 of file __init__.py.

Definition at line 251 of file __init__.py.

Definition at line 168 of file __init__.py.


The documentation for this class was generated from the following file: