def translate_kml_document(request, document): # collective.geo.kml doesn't correctly translate strings in KML, so we # do it here to work around this issue. translate = tools.translator(request, 'seantis.placemap') translation = translate(_(u"See the original resource")) return document.replace(u"See the original resource", translation)
def get_sources_description(request): translate = tools.translator(request, 'seantis.reservation') items = [ u'<dt>{}</dt><dd>{}</dd>'.format( *map(translate, (s.title, s.description)) ) for s in sources ] return u'<dl>{}</dl>'.format(''.join(items))
def get_record(request, person, fields): record = [] translate = tools.translator(request, 'seantis.people') for field in (get_field(request, person, f[0]) for f in fields): if isinstance(field, Message): record.append(translate(field)) else: record.append(field) return record
def get_attribute_map(request, headers, portal_type): if not headers: raise ContentImportError(_(u'No column headers were found')) schema = tools.get_schema_from_portal_type(portal_type) attribute_map = {} fields = getFields(schema) known_titles = dict((field.title, field) for field in fields.values()) known_fields = dict((key, field) for key, field in fields.items()) translate = tools.translator(request) known_translated_titles = dict( (translate(field.title), field) for field in fields.values() ) for header in headers: if header in known_translated_titles: field = known_translated_titles[header] elif header in known_fields: field = known_fields[header] elif header in known_titles: field = known_titles[header] else: log.warn(u"The header '{}' was ignored.".format(header)) continue if field in attribute_map.values(): raise ContentImportError( _( u'The ${name} column is specified more than once', mapping=dict(name=header) ) ) if field in ('title', 'id'): raise ContentImportError( _( u'The ${name} column is invalid. "title" and "id" are ' u'reserved fieldnames which may not be used.', mapping=dict(name=header) ) ) attribute_map[header] = field return attribute_map
def export_people(request, container, portal_type, fields, review_state=None, include_inactive=True): people = get_people(container, portal_type, review_state, include_inactive) if not people: raise ContentExportError(_(u"No people to export")) records = (get_record(request, person, fields) for person in people) translate = tools.translator(request, 'seantis.people') dataset = tablib.Dataset(headers=[translate(f[1]) for f in fields]) map(dataset.append, records) return dataset
def translate_position(self, request): particles = [] if self.rownumber: particles.append(_(u'Row ${row}', mapping=dict( row=self.rownumber ))) if self.colname: particles.append(_(u'Column ${column}', mapping=dict( column=self.colname ))) translate = tools.translator(request) return u', '.join(map(translate, particles))
def get_value(request, person, field): value = getattr(person, field) schema = tools.get_schema_from_portal_type(person.portal_type) try: name = schema.get(field).vocabularyName except AttributeError: return getattr(person, field) vocabulary = zope.component.getUtility(IVocabularyFactory, name)(person) try: translate = tools.translator(request, 'seantis.people') return translate(vocabulary.getTerm(value).title) except LookupError: return value
def get_vocabularies(request, attribute_map): """ Returns a dictionary containing all (translated) vocabularies used by the given attribute map. """ vocabularies = {} translate = tools.translator(request) for header, field in attribute_map.items(): if IChoice.providedBy(field): vocabulary = zope.component.getUtility(IVocabularyFactory, field.vocabularyName) vocabulary = vocabulary(None) vocabularies[header] = dict([ (translate(term.title).lower(), term.value) for term in vocabulary._terms ]) return vocabularies
def filename(self): parts = [] parts.append(self.context.title) source = self.get_source_by_id(self.request.get('source')) translate = tools.translator(self.request, 'seantis.reservation') parts.append(translate(source.title)) if self.year not in ('any', 'all'): parts.append(self.year) if self.month not in ('any', 'all'): if len(self.month) == 1: parts.append('0{}'.format(self.month)) else: parts.append(self.month) parts.append(self.file_extension) return '.'.join(parts)
def create_and_save_pdf(data, filename, context, request, toc): """ Create a PDF of the current/all organization(s) and sub-organizations with portrait, memberships, and possibly table of contents and save it in the organization. """ translator = tools.translator(request, 'seantis.agencies') report = OrganizationsReport(data, context.title, translator, toc=toc) filehandle = report.build(context, request) with unrestricted.run_as('Manager'): request.set('_authenticator', createToken()) if filename in context: context.manage_delObjects([filename]) context.invokeFactory(type_name='File', id=filename) file = context.get(filename) file.setContentType('application/pdf') file.setExcludeFromNav(True) file.setFilename(filename) file.setFile(filehandle.getvalue()) file.reindexObject()
def translate(self, text): return tools.translator(self.request, 'seantis.cover.people')(text)
def test_translator(self): _ = MessageFactory('plone') self.assertEqual( tools.translator(self.request, domain='plone')(_(u'Comment')), i18n.translate(_(u'Comment'), target_language='en', domain='plone') )
def translate(self, text): return tools.translator(self.request, 'seantis.reservation')(text)
def translate(self, text, domain=None): return tools.translator(self.request, domain or self.domain)(text)
def translate(self, request): return tools.translator(request)(self.message)
def translate(self, text): return tools.translator(self.request, 'seantis.kantonsrat')(text)