[wp-trac] Re: [WordPress Trac] #3911: Javascript should not be localized by via PHP

WordPress Trac wp-trac at lists.automattic.com
Mon Mar 5 23:49:50 GMT 2007


#3911: Javascript should not be localized by via PHP
-----------------------------------+----------------------------------------
 Reporter:  mdawaffe               |        Owner:  mdawaffe
     Type:  defect                 |       Status:  assigned
 Priority:  high                   |    Milestone:  2.2     
Component:  Optimization           |      Version:  2.1.2   
 Severity:  normal                 |   Resolution:          
 Keywords:  has-patch 2nd-opinion  |  
-----------------------------------+----------------------------------------
Comment (by mdawaffe):

 majelbstoat,

 The variables get put into an object you specify.  The patch on this
 ticket tells the script loader to add them to an object called
 "listManL10n":
 {{{
 wp_localize_script( 'listman', 'listManL10n', array(
    'jumpText' => __('Jump to new item'),
    'delText' => __('Are you sure you want to delete this %s?')
 ) );
 }}}

 (in the patch the above is actually accomplished by a line that looks like
 {{{$this->localize( ... );}}})

 Script loader then generates the following output in the page's HEAD.

 {{{
 <script type='text/javascript'>
 /* <![CDATA[ */
         listManL10n = {
                 jumpText: "Jump to new item",
                 delText: "Are you sure you want to delete this %s?"
         }
 /* ]]> */
 </script>
 }}}

 It's the responsibility of the JavaScript to then go find it.  listMan was
 tweaked to do just that with the following lines (included in the patch).
 {{{
 if ( 'undefined' != typeof listManL10n )
    Object.extend(listMan.prototype, listManL10n);
 }}}

 As to your other question:

 Oops, forgot about the offset stuff.  I think it fixes a coloring bug that
 sometimes shows up when AJAX adding new items to a list with alternating
 colors, but that's been sitting around locally on my machine for a
 while....

-- 
Ticket URL: <http://trac.wordpress.org/ticket/3911#comment:4>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list