What does l10n.js do in WordPress 3.1? And how do I remove it?

I just installed WP 3.1 Beta 2 on my test server. I noticed that it ships with a new l10n.js file that gets automatically inserted into the header.

I did a bit of digging and it has something to do with localization. I’m guessing that many people don’t use this, so I’m wondering how I could remove it?

Read More

If it’s important not to remove it, please let me know as well.

Related posts

Leave a Reply

8 comments

  1. It contains the convertEntities() function that (as the name says) converts HTML entities to their actual value. It is mostly used for scripts that send over localization data from PHP to the JS side using wp_localize_script(). Just search for l10n_print_after in the code base and you see it a lot.

    The data you add in wp_localize_script() is added before the script it translates (it must be, because it is referenced there). However, if you use a script concatenator (so you only have one request that returns all used JS files), this one file would also be called after all localized data – but now convertEntities() is not defined when we need it. For this reason this function is split off the general utils.js file and added with a high priority at the top.

    For this reason you should not remove it: all scripts that use translatable strings use it (even if they are still in English), and you might break places that still have entities.

  2. if ( !is_admin() ) {
    function my_init_method() {
    wp_deregister_script( 'l10n' );
    }
    add_action('init', 'my_init_method'); 
    }
    

    use the code above to deregister l10n.js in function.php

  3. Looks like it is included when you enqueue the ‘comment-reply’ scrip. Note that you probably want to make sure ‘comment-reply’ is loaded only on pages could have comments enabled (e.g. check is_singular() before enqueueing the script).

  4. I found on my installation that this script was loaded alongside the new admin bar, getting rid of the admin bar got rid of the l10n.js for me(but i think Jan’s answer is more inline with answering the “why”).

    Removing the bar was easy..

    remove_action( 'init', 'wp_admin_bar_init' );
    

    This doesn’t actually address the question(as evidenced by the other answers), but incase anyone wants to remove that awful bar, the above is how you do it..

  5. How to remove it:

    function kill_l10n() {
        if ( !is_admin() )
            wp_deregister_script( 'l10n' );
    }
    add_action( 'wp_print_scripts', 'kill_l10n' );
    

    Drop in functions.php or whatever (plugin, etc.)

    Works for me.

  6. Developers source for the file has following description:

    //Used to ensure that Entities used in L10N strings are correct

    and commit note says:

    Move the l10n helper function into a seperate js file so we can always output it first.

    I hadn’t played with 3.1 yet so not sure what can make it load in every page.

  7. Yep it’s thrown inside the theme by wp_head automatically…
    I remove it by placing the code below in the theme’s functions.php


    remove_action( 'wp_head', 'l10n' );