Make WordPress Core

Opened 15 years ago

Closed 10 years ago

#12905 closed defect (bug) (wontfix)

the_title_attribute() is hard to internationalize

Reported by: mdawaffe's profile mdawaffe Owned by: nbachiyski's profile nbachiyski
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: I18N Keywords: dev-feedback needs-refresh close
Focuses: Cc:

Description

To internationalize the output of the_title_attribute, you have to go through some hoops.

printf( esc_attr__( 'Permanent link to %s' ), the_title_attribute( 'echo=0' ) );

Adding a 'formatted' argument to the args array would clean it up a little.

the_title_attribute( array( 'formatted' => __( 'Permanent link to %s' ) ) );

Even better would be if we could auto detect what the first parameter was.

the_title_attribute( __( 'Permanent link to %s' ) );

It'd require the function to try and detect if it's first argument were a sprintf format. Maybe: look for %, if found, does sprintf return a string, if so, go for it.

Attached is one way to implement.

Attachments (2)

12905.diff (965 bytes) - added by mdawaffe 15 years ago.
tmpl-argument-for-the-title-attribute.diff (927 bytes) - added by nbachiyski 15 years ago.

Download all attachments as: .zip

Change History (6)

@mdawaffe
15 years ago

#1 @nbachiyski
15 years ago

We should try an move all before/after arguments to similar template approach. It improves code readability a lot. Compare 'before' => '<li>', 'after' => '</li>' with '<li>%s</li>'.

That's why the name formatted seems a little niche. I propose to call the argument just text. Its default value will be %s. This way we can skip the % checks and just say sprintf( $text, $title );. If text doesn't contain any %s sprintf won't complain, just the title won't appear anywhere in the result. I am perfectly ok with that.

We can differentiate if $args is argument string or text template by checking if it starts by arg= where arg is one of the valid arguments (we have them all in $default).

#2 @hakre
15 years ago

Related: #14972

#3 @chriscct7
11 years ago

  • Keywords dev-feedback needs-refresh close added

This patch seems like a super roundabout way of solving it. You could just as easily get the title, localize it, then run it through strip_tags. In any event, the patch needs to be refreshed

#4 @wonderboymusic
10 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

No one has been willing to look at this in 5 years

Note: See TracTickets for help on using tickets.