Opened 15 years ago
Closed 10 years ago
#12905 closed defect (bug) (wontfix)
the_title_attribute() is hard to internationalize
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (6)
Note: See
TracTickets for help on using
tickets.
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
$args
is argument string or text template by checking if it starts byarg=
wherearg
is one of the valid arguments (we have them all in$default
).