[Solved] Translation for custom Columns in folder_contents View

I have add two Indexes to Catalog and the Metadata Columns. It' called "firstname" and "lastname"
Then i have override the Pattern Options for "structure" in the registry and Rebuild my Catalog.

<record name="plone.patternoptions">
    <field type="plone.registry.field.Dict">
      <description>Base pattern configuration options</description>
      <key_type type="plone.registry.field.ASCIILine" />
      <title>Patterns configuration</title>
      <value_type type="plone.registry.field.Text" />
    </field>
    <value>
      <element key="structure">{"momentFormat": "DD.MM. YYYY","_default_activeColumns": ["lastname","firstname","review_state",]}</element>
    </value>
  </record>

My Question: how can i translate/customize the column header, I don't want the plain metadata label as column label? Is there an Option for the Structure Pattern that can override via registry.xml, like the _default_activeColumns?

My Solution is subclassing of FolderContensView:

class MyFolderContentsView(FolderContentsView):
  
  def get_options(self):
    options = super(MyFolderContentsView, self).get_options()
    if 'firstname' in options['availableColumns']:
      options['availableColumns']['firstname'] = self.context.translate(_('Firstname'))
    
    if 'lastname' in options['availableColumns']:
      options['availableColumns']['lastname'] = self.context.translate(_('Lastname'))
    
    if 'firstname' in options['rearrange']['properties']:
      options['rearrange']['properties']['firstname'] = self.context.translate(_('Firstname'))
    
    if 'lastname' in options['rearrange']['properties']:
      options['rearrange']['properties']['lastname'] = self.context.translate(_('Lastname'))
    return options

Update: Only for a specific Folderish Contenttype, e.g. StuffContainer (the solution above has global effect to all folder_content views

  • remove the custom plone.patternoptions from registry, which i described above
  • register and override the patterns view for your specific Folderish Contenttype
<!-- configure.zcml -->

<!-- Override Patterns Settings View -->
<browser:page
    for="my.addon.interfaces.IStuffContainer"
    layer="my.addon.interfaces.IMyAddonLayer"
    class=".views.PatternsSettingsView"
    name="plone_patterns_settings"
    permission="zope.Public" />
# views.py

from Products.CMFPlone.patterns.view import PatternsSettingsView as BasePatternsSettingsView,

class PatternsSettingsView(BasePatternsSettingsView):
    def __call__(self):
        result = super(PatternsSettingsView, self).__call__()
        result.update({'data-pat-structure':'{"momentFormat": "DD.MM. ' \
                       'YYYY","_default_activeColumns": ' \
                       '["review_state","lastname", "firstname"]}'})

        return result

Thinking naively: if your term "firstname" exists as a messagestring in the .po template, shouldn't your translations then be picked up automatically (as is e.g. the case for Actions)?

Yes, this was my first Idea. But it has no effect.