Reusing WordPress components: L10n

Personally, I'm a big fan of WordPress. Although it can be bloated sometimes, it uses smart programming techniques and high quality libraries. (Unlike some of the plugins.)

Today, I sorted out how to use the Localization (l10n) libraries of WordPress in another project. And it was a lot simpler than I could have hoped for.

Step 1: Copy some files

From the WordPress distribution, we're gonna need /wp-includes/l10n.php and the directory /wp-includes/pomo/*.php. Copy l10n and the whole directory pomo to your own includes directory.

Step 2: Compatibility

WordPress extensively uses apply_filters and do_action for filtering data and triggering events. We're not gonna use those now, but unless we want to rewrite half of l10n.php, we better make something for compatibility. I entered these simple statements in a new file named wordpress-compat.php:

function apply_filters($tag,$in){
        return $in;
function do_action(){

Step 3: Combining and using it

require( 'includes/l10n/compat.php' );
require( 'includes/l10n/pomo/mo.php' );
require( 'includes/l10n/l10n.php' );
echo __("text to be translated");

That's all. For creating .po/.mo files, you may want to read my topic on creating .po/.mo files or see what else I wrote on the subject.

© GeekLabInfo Reusing WordPress components: L10n is a post from You are free to copy materials from, but you are required to link back to

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Leave a Reply