Opened 3 years ago
Last modified 3 years ago
#12905 new defect (bug)
the_title_attribute() is hard to internationalize
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | I18N | Version: | 3.0 |
| Severity: | normal | Keywords: | |
| 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 (4)
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 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).