Opened 16 years ago
Closed 11 years ago
#12905 closed defect (bug) (wontfix)
the_title_attribute() is hard to internationalize
| Reported by: | mdawaffe | Owned by: | nbachiyski |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | I18N | Version: | 3.0 |
| Severity: | normal | Keywords: | dev-feedback needs-refresh close |
| Cc: | Focuses: |
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)
Change History (6)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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 saysprintf( $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
$argsis argument string or text template by checking if it starts byarg=whereargis one of the valid arguments (we have them all in$default).