Based on the code provided it looks like you are misunderstanding how
wp_localize_script works. The signature of the function looks like this:
wp_localize_script( $handle, $name, $data );
wp_localize_script. Take a look at the example in the codex (I've added line numbers below):
3: // Register the script
4: wp_register_script( 'some_handle', 'path/to/myscript.js' );
6: // Localize the script with new data
7: $translation_array = array(
8: 'some_string' => __( 'Some string to translate', 'plugin-domain' ),
9: 'a_value' => '10'
11: wp_localize_script( 'some_handle', 'object_name', $translation_array );
13: // Enqueued script with localized data.
14: wp_enqueue_script( 'some_handle' );
Next, on line 11,
wp_localize_script() is used to register the localization data for the script handle
'some_handle' registered on line 4.
wp_localize_script() was passed the same
$handle registered on line 4, WordPress automatically includes the localized data on every page that
wp_enqueue_script( 'some_handle' ); is called.
In other words, you need to use
This quote from the notes section says more or less the same thing:
IMPORTANT! wp_localize_script() MUST be called after the script has been registered using wp_register_script() or wp_enqueue_script().
Also, I don't think you need to
$data. WordPress should do that for you.