Ticket #1645 (closed enhancement: fixed)

Opened 14 years ago

Last modified 13 years ago

alt attribute of icons img tags is not translated.

Reported by: joseluis.rosa@… Owned by: tracguest
Priority: P2 Milestone: CPS 3.4.3
Component: CPSPortlets Version: TRUNK
Severity: normal Keywords:
Cc:

Description

In PortletsTool?.py the methods renderIcon and renderActionIcon, return an img tag. The value of the alt attribute is not translated with Localizer which in case of actions icons can be very useful (in my use case I render actions without title).

I propose to replace this line:

img_tag = IMG_TAG % (base_url + icon_path,
                     getattr(img, 'width', 0),
                     getattr(img, 'height', 0),
                     alt)

with these:

language = self.translation_service.getSelectedLanguage()
alt_text = self.Localizer.default.gettext(alt, language) 
img_tag = IMG_TAG % (base_url + icon_path,
                     getattr(img, 'width', 0),
                     getattr(img, 'height', 0),
                     alt_text)

Please, let me know if there's a better solution for this.

Thank you.

Change History

comment:1 Changed 14 years ago by sfermigier

  • Milestone changed from CPS 3.4.1 to CPS 3.4.3

comment:2 Changed 13 years ago by joseluis.rosa@…

Even, the title attribute of the img tag could be set too.

IMG_TAG = '<img src="%s" width="%s" height="%s" alt="%s" title="%s"/>'
language = self.translation_service.getSelectedLanguage()
alt_text = self.Localizer.default.gettext(alt, language) 
img_tag = IMG_TAG % (base_url + icon_path,
                     getattr(img, 'width', 0),
                     getattr(img, 'height', 0),
                     alt_text, alt_text)

comment:3 Changed 13 years ago by joseluis.rosa@…

  • Owner changed from jmorliaguet to tracguest
  • Status changed from new to assigned

There's a little bug here:

alt_text = self.Localizer.default.gettext(alt, language) 

should be

alt_text = self.Localizer.default.gettext(str(alt), language) 

as alt sometimes is not a string, which is required so that it can be translated by message catalog.

comment:4 Changed 13 years ago by madarche

  • Status changed from assigned to closed
  • Version changed from 3.4.0 to TRUNK
  • Resolution set to fixed

Fixed by changeset [50095].

There is still a little cache problem : the alt and title don't get changed when the user change the portal language. This is strange since the Actions Portlet cache parameters include "current_lang".

If you have an idea and can contribute code you are welcome.

Note: See TracTickets for help on using tickets.