[wp-trac] [WordPress Trac] #9673: sprintf() shortcuts

WordPress Trac wp-trac at lists.automattic.com
Tue Apr 28 21:49:29 GMT 2009


#9673: sprintf() shortcuts
-------------------------+--------------------------------------------------
 Reporter:  wnorris      |       Owner:  nbachiyski
     Type:  enhancement  |      Status:  new       
 Priority:  normal       |   Milestone:  Unassigned
Component:  i18n         |     Version:  2.8       
 Severity:  normal       |    Keywords:  i18n      
-------------------------+--------------------------------------------------
 After seeing #9650, I figured it would equally make sense to add shortcut
 methods for the very often used case of formatted, localized strings:

   `sprintf( __('Author is %s'), $author )`

 I propose two new l10n functions: `_f()` and `_ef()` which accept a
 formatted string and a variable number of arguments, which are passed
 through `__()` and `sprintf()` as in the example above.

 I've not yet attached a patch for this, because I'm not sure what to do
 about the domain.  One possibility is to require that the domain be passed
 in, so the above example would be called as:

   `_f( 'Author is %s', 'default', $author)`

 I'm certainly not crazy about that approach, since it makes all the calls
 in WP core unnecessarily verbose.  Alternately, you could take the
 variable arguments as an array, changing the function signature to be:

   `function _f( $string, $args, $domain = 'default')`

 This would result in the above example being called as:

   `_f( 'Author is %s', array($author) )`

 or if you want to specify the domain:

   `_f( 'Author is %s', array($author), 'my-domain' )`

 Would love to hear others thoughts on this.  Perhaps this has even been
 discussed before?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9673>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list