Exemplo n.º 1
0
 def json(self):
     result = {
         'state': self.state, #XXX should i18n these?
         'filename': self.filename,
         'progress': translate(self.progress_descr),
         }
     return json.dumps(result)
Exemplo n.º 2
0
    def store(self, mem_id, category, msg):
        """
        This takes an OBJECT and stores it on a per-user basis.
        If we receive a string, we're going to see if it's a message id
        and attempt to translate it.  If not, WE WILL LEAVE IT ALONE!!!
        """
        cat = self._category_annot(mem_id, category)
        try:
            new_id = cat.maxKey() + 1
        except ValueError:
            new_id = 0

        # Try to turn a str into a Message.
        if isinstance(msg, basestring) and not isinstance(msg, Message):
            # The reason for that comparison is: if it's already a
            # Message, then -- very confusingly -- Message is a
            # subclass of basestring ... but calling _() on a Message
            # returns an instance that compares equal to the original
            # but translates differently! No kidding. WTF.
            msg = _(msg)
        if isinstance(msg, Message):
            msg = translate(msg, context=self.site_root)
            
        if isinstance(msg, Message) or isinstance(msg, basestring):
            cleaner = Cleaner()
            msg = cleaner.clean_html(msg)

            # clean_html wraps plain text messages in a paragraph tag.  If
            # that has happened, we'll remove it to restore the original message.
            if msg.startswith('<p>'):
                msg = msg[3:-4]

        cat[new_id] = msg
Exemplo n.º 3
0
 def translate(self, msgid, domain=i18n_domain, mapping=None,
               target_language=None, default=None):
     """
     Wrapper around translate machinery which defaults to our i18n
     domain and the current context object.  Returns instance of
     unicode type.
     """
     context = aq_inner(self.context)
     kw = dict(domain=domain, mapping=mapping, context=context,
               target_language=target_language, default=default)
     return translate(msgid, **kw)
Exemplo n.º 4
0
 def confirmDeleteList(self):
     form = self.request.form
     psm = _(u'psm_mailing_list_deletion_cancelled', u"Mailing list deletion cancelled.")
     list_id = form.get('list_id', '')
     confirm = form.get('%s_confirm_delete' % list_id, 'false')
     if confirm == 'true':
         self.context.manage_delObjects(ids=[list_id])
         psm = _(u'psm_mailing_list_deleted', u"Mailing list deleted.")
     psm = translate(psm)
     url = "%s?portal_status_message=%s" % (self.context.absolute_url(),
                                            psm)
     self.request.RESPONSE.redirect(url)
Exemplo n.º 5
0
def project_noun():
    default = _base_project_noun()   # i'm too scared to touch that function! -egj

    # see http://www.openplans.org/projects/opencore/lists/opencore-dev/archive/2009/02/1235074968070/forum_view#1240025304798
    # ..we need the site as a context to pass in to `translate` so that 
    # we can get the user's preferred languages
    site = getSite()
    if site is None:
        # Ugh. This happens during import time, it's used by a couple
        # of archetypes schema labels.  Lookup fails because we
        # haven't yet loaded the zcml that creates an implementation
        # of IProvideSiteConfig.  We have no choice but to return the
        # default; I'm hoping this is OK because we don't actually
        # care about archetypes labels.  - PMW
        return default
    i18nified = _(u'project_noun', default)
    return translate(i18nified, context=site)
Exemplo n.º 6
0
    def _translate(self, msgid, domain=i18n_domain, mapping=None,
                   target_language=None, default=None):
        # Ensure that our mapping gets used...
        if isinstance(msgid, Message):
            if msgid.mapping:
                tmp = msgid.mapping.copy()
                tmp.update(mapping or {})
                mapping = tmp
            # Messages have a read-only mapping; we can make a copy to stuff
            # our mapping in there.
            msgid = Message(msgid, mapping=mapping)
        # ... and does not contain binary encoded strings.
        mapping.update(self._unicode_values(mapping))

        kw = dict(domain=domain, mapping=mapping,
                  context=self.context,
                  target_language=target_language, default=default)
        return translate(msgid, **kw)